Skip to main content

matter_kit/clusters/generated/
dishwasher_mode.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Dishwasher Mode — cluster 0x0059.
4//
5// Regenerate with `cargo xtask clusters --dm <checkout>/data_model/1.6`; `cargo xtask check`
6// is the CI gate that keeps this file honest. The XML itself is not vendored here — it
7// carries the CSA's own copyright notice and is not redistributable.
8
9//! Dishwasher Mode (cluster `0x0059`, revision 3).
10//!
11//! 6 identifiers, 1 feature bits, and the specification's own conformance for
12//! every element. `CLUSTER` is the whole table.
13
14#![allow(unused_imports)]
15
16use crate::dm::conformance::{Clause, Condition, Conform, Conformance};
17use crate::dm::meta::{EventPriority, Reporting};
18use crate::dm::spec::{Attribute, Cluster, Command, Event, Feature};
19use crate::dm::{Access, AccessQualities, AttributeQualities, Privilege};
20use crate::error::Result;
21use crate::im::{AttributeId, ClusterId, CommandId, EventId};
22use crate::tlv::{
23    ContainerKind, Element, FromTlv, Nullable, Tag, TlvList, TlvReader, TlvWriter, ToTlv, Value,
24};
25
26/// The cluster id.
27pub const ID: ClusterId = 0x0059;
28
29/// The highest revision the specification's history defines — what `ClusterRevision`
30/// must report (Core §7.13.1).
31pub const REVISION: u16 = 3;
32
33/// The PICS code, which a certification declaration names the cluster by.
34pub const PICS: &str = "DISHM";
35
36/// The `FeatureMap` bits (Core §7.13.2).
37///
38/// A feature has conformance of its own: a device may not claim one the
39/// specification forbids it alongside another.
40pub mod feature {
41    /// Dependency with the OnOff cluster
42    ///
43    /// Code `DEPONOFF`, bit 0.
44    pub const ON_OFF: u32 = 1 << 0;
45}
46
47/// Every feature bit, with its conformance.
48pub const FEATURES: &[Feature] = &[Feature {
49    bit: 0,
50    code: "DEPONOFF",
51    name: "OnOff",
52    conform: Conform::DISALLOWED,
53}];
54
55/// The attribute ids.
56pub mod attribute {
57    use crate::im::AttributeId;
58
59    /// `SupportedModes`.
60    pub const SUPPORTED_MODES: AttributeId = 0x00;
61    /// `CurrentMode`.
62    pub const CURRENT_MODE: AttributeId = 0x01;
63    /// `StartUpMode`.
64    pub const START_UP_MODE: AttributeId = 0x02;
65    /// `OnMode`.
66    pub const ON_MODE: AttributeId = 0x03;
67}
68
69/// The command ids.
70pub mod command {
71    use crate::im::CommandId;
72
73    /// `ChangeToMode`.
74    pub const CHANGE_TO_MODE: CommandId = 0x00;
75    /// `ChangeToModeResponse`.
76    pub const CHANGE_TO_MODE_RESPONSE: CommandId = 0x01;
77}
78
79/// `ModeTag`.
80#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
81#[repr(u16)]
82pub enum ModeTag {
83    /// `Auto`.
84    Auto = 0,
85    /// `Quick`.
86    Quick = 1,
87    /// `Quiet`.
88    Quiet = 2,
89    /// `LowNoise`.
90    LowNoise = 3,
91    /// `LowEnergy`.
92    LowEnergy = 4,
93    /// `Vacation`.
94    Vacation = 5,
95    /// `Min`.
96    Min = 6,
97    /// `Max`.
98    Max = 7,
99    /// `Night`.
100    Night = 8,
101    /// `Day`.
102    Day = 9,
103    /// `Normal`.
104    Normal = 16384,
105    /// `Heavy`.
106    Heavy = 16385,
107    /// `Light`.
108    Light = 16386,
109}
110
111impl ModeTag {
112    /// Reads a wire value, or `None` for one this revision does not define.
113    #[must_use]
114    pub const fn from_value(value: u16) -> Option<Self> {
115        match value {
116            0 => Some(Self::Auto),
117            1 => Some(Self::Quick),
118            2 => Some(Self::Quiet),
119            3 => Some(Self::LowNoise),
120            4 => Some(Self::LowEnergy),
121            5 => Some(Self::Vacation),
122            6 => Some(Self::Min),
123            7 => Some(Self::Max),
124            8 => Some(Self::Night),
125            9 => Some(Self::Day),
126            16384 => Some(Self::Normal),
127            16385 => Some(Self::Heavy),
128            16386 => Some(Self::Light),
129            _ => None,
130        }
131    }
132
133    /// Its wire value.
134    #[must_use]
135    pub const fn value(self) -> u16 {
136        self as u16
137    }
138}
139
140impl ToTlv for ModeTag {
141    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
142        self.value().to_tlv(w, tag)
143    }
144}
145
146impl<'a> FromTlv<'a> for ModeTag {
147    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
148        let value = <u16 as FromTlv<'a>>::from_tlv(reader, element)?;
149        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
150    }
151}
152
153/// `ModeOptionStruct`.
154#[derive(Debug, Clone, Copy, PartialEq)]
155pub struct ModeOptionStruct<'a> {
156    /// `Label`, field 0.
157    pub label: &'a str,
158    /// `Mode`, field 1.
159    pub mode: u8,
160    /// `ModeTags`, field 2.
161    pub mode_tags: TlvList<'a, ModeTagStruct>,
162}
163
164impl<'a> ToTlv for ModeOptionStruct<'a> {
165    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
166        w.start_structure(tag)?;
167        self.label.to_tlv(w, Tag::Context(0))?;
168        self.mode.to_tlv(w, Tag::Context(1))?;
169        self.mode_tags.to_tlv(w, Tag::Context(2))?;
170        w.end_container()
171    }
172}
173
174impl<'a> FromTlv<'a> for ModeOptionStruct<'a> {
175    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
176        if element.value.container() != Some(ContainerKind::Structure) {
177            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
178        }
179        let mut label = None;
180        let mut mode = None;
181        let mut mode_tags = None;
182        loop {
183            let Some(field) = reader.next_element()? else {
184                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
185            };
186            if field.value == Value::EndOfContainer {
187                break;
188            }
189            match field.tag.context() {
190                Some(0) => label = Some(<&'a str>::from_tlv(reader, &field)?),
191                Some(1) => mode = Some(<u8>::from_tlv(reader, &field)?),
192                Some(2) => {
193                    mode_tags = Some(<TlvList<'a, ModeTagStruct>>::from_tlv(reader, &field)?)
194                }
195                // A field this revision does not define. §7.19.2: a receiver
196                // ignores what it does not know rather than refusing the whole
197                // structure, which is what lets a newer peer talk to an older one.
198                _ => reader.skip_value(&field)?,
199            }
200        }
201        Ok(Self {
202            label: label.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
203            mode: mode.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
204            mode_tags: mode_tags.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
205        })
206    }
207}
208
209/// `ModeTagStruct`.
210#[derive(Debug, Clone, Copy, PartialEq)]
211pub struct ModeTagStruct {
212    /// `MfgCode`, field 0.
213    pub mfg_code: Option<crate::msg::VendorId>,
214    /// `Value`, field 1.
215    pub value: u16,
216}
217
218impl ToTlv for ModeTagStruct {
219    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
220        w.start_structure(tag)?;
221        if let Some(value) = &self.mfg_code {
222            value.to_tlv(w, Tag::Context(0))?;
223        }
224        self.value.to_tlv(w, Tag::Context(1))?;
225        w.end_container()
226    }
227}
228
229impl<'a> FromTlv<'a> for ModeTagStruct {
230    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
231        if element.value.container() != Some(ContainerKind::Structure) {
232            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
233        }
234        let mut mfg_code = None;
235        let mut value = None;
236        loop {
237            let Some(field) = reader.next_element()? else {
238                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
239            };
240            if field.value == Value::EndOfContainer {
241                break;
242            }
243            match field.tag.context() {
244                Some(0) => mfg_code = Some(<crate::msg::VendorId>::from_tlv(reader, &field)?),
245                Some(1) => value = Some(<u16>::from_tlv(reader, &field)?),
246                // A field this revision does not define. §7.19.2: a receiver
247                // ignores what it does not know rather than refusing the whole
248                // structure, which is what lets a newer peer talk to an older one.
249                _ => reader.skip_value(&field)?,
250            }
251        }
252        Ok(Self {
253            mfg_code,
254            value: value.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
255        })
256    }
257}
258
259/// The fields of `ChangeToMode` (command `0x00`).
260#[derive(Debug, Clone, Copy, PartialEq)]
261pub struct ChangeToModeFields {
262    /// `NewMode`, field 0.
263    pub new_mode: u8,
264}
265
266impl ToTlv for ChangeToModeFields {
267    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
268        w.start_structure(tag)?;
269        self.new_mode.to_tlv(w, Tag::Context(0))?;
270        w.end_container()
271    }
272}
273
274impl<'a> FromTlv<'a> for ChangeToModeFields {
275    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
276        if element.value.container() != Some(ContainerKind::Structure) {
277            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
278        }
279        let mut new_mode = None;
280        loop {
281            let Some(field) = reader.next_element()? else {
282                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
283            };
284            if field.value == Value::EndOfContainer {
285                break;
286            }
287            match field.tag.context() {
288                Some(0) => new_mode = Some(<u8>::from_tlv(reader, &field)?),
289                // A field this revision does not define. §7.19.2: a receiver
290                // ignores what it does not know rather than refusing the whole
291                // structure, which is what lets a newer peer talk to an older one.
292                _ => reader.skip_value(&field)?,
293            }
294        }
295        Ok(Self {
296            new_mode: new_mode.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
297        })
298    }
299}
300
301/// The fields of `ChangeToModeResponse` (command `0x01`).
302#[derive(Debug, Clone, Copy, PartialEq)]
303pub struct ChangeToModeResponseFields<'a> {
304    /// `Status`, field 0.
305    pub status: u8,
306    /// `StatusText`, field 1.
307    pub status_text: &'a str,
308}
309
310impl<'a> ToTlv for ChangeToModeResponseFields<'a> {
311    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
312        w.start_structure(tag)?;
313        self.status.to_tlv(w, Tag::Context(0))?;
314        self.status_text.to_tlv(w, Tag::Context(1))?;
315        w.end_container()
316    }
317}
318
319impl<'a> FromTlv<'a> for ChangeToModeResponseFields<'a> {
320    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
321        if element.value.container() != Some(ContainerKind::Structure) {
322            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
323        }
324        let mut status = None;
325        let mut status_text = None;
326        loop {
327            let Some(field) = reader.next_element()? else {
328                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
329            };
330            if field.value == Value::EndOfContainer {
331                break;
332            }
333            match field.tag.context() {
334                Some(0) => status = Some(<u8>::from_tlv(reader, &field)?),
335                Some(1) => status_text = Some(<&'a str>::from_tlv(reader, &field)?),
336                // A field this revision does not define. §7.19.2: a receiver
337                // ignores what it does not know rather than refusing the whole
338                // structure, which is what lets a newer peer talk to an older one.
339                _ => reader.skip_value(&field)?,
340            }
341        }
342        Ok(Self {
343            status: status.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
344            status_text: status_text.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
345        })
346    }
347}
348
349/// Every attribute the specification defines, with its conformance.
350pub const ATTRIBUTES: &[Attribute] = &[
351    Attribute {
352        id: 0x0000,
353        name: "SupportedModes",
354        kind: "list[ModeOptionStruct]",
355        access: Access::read_only(Privilege::View),
356        qualities: AttributeQualities::empty(),
357        reporting: Reporting::OnChange,
358        conform: Conform::MANDATORY,
359    },
360    Attribute {
361        id: 0x0001,
362        name: "CurrentMode",
363        kind: "uint8",
364        access: Access::read_only(Privilege::View),
365        qualities: AttributeQualities::empty(),
366        reporting: Reporting::OnChange,
367        conform: Conform::MANDATORY,
368    },
369    Attribute {
370        id: 0x0002,
371        name: "StartUpMode",
372        kind: "uint8",
373        access: Access::read_only(Privilege::View),
374        qualities: AttributeQualities::empty(),
375        reporting: Reporting::OnChange,
376        conform: Conform::DISALLOWED,
377    },
378    Attribute {
379        id: 0x0003,
380        name: "OnMode",
381        kind: "uint8",
382        access: Access::read_only(Privilege::View),
383        qualities: AttributeQualities::empty(),
384        reporting: Reporting::OnChange,
385        conform: Conform::DISALLOWED,
386    },
387];
388
389/// Every command, with its conformance.
390pub const COMMANDS: &[Command] = &[
391    Command {
392        id: 0x00,
393        name: "ChangeToMode",
394        to_server: true,
395        response: Some(0x01),
396        access: Access::invoke(Privilege::Operate),
397        conform: Conform::MANDATORY,
398    },
399    Command {
400        id: 0x01,
401        name: "ChangeToModeResponse",
402        to_server: false,
403        response: None,
404        access: Access::invoke(Privilege::Operate),
405        conform: Conform::MANDATORY,
406    },
407];
408
409/// Every event, with its conformance.
410pub const EVENTS: &[Event] = &[];
411
412/// The whole cluster, as the specification defines it.
413pub const CLUSTER: Cluster = Cluster {
414    id: ID,
415    name: "Dishwasher Mode",
416    revision: REVISION,
417    pics: "DISHM",
418    derived_from: Some("Mode Base"),
419    features: FEATURES,
420    attributes: ATTRIBUTES,
421    commands: COMMANDS,
422    events: EVENTS,
423};