Skip to main content

matter_kit/clusters/generated/
laundry_washer_mode.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Laundry Washer Mode — cluster 0x0051.
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//! Laundry Washer Mode (cluster `0x0051`, 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 = 0x0051;
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 = "LWM";
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    /// `Delicate`.
106    Delicate = 16385,
107    /// `Heavy`.
108    Heavy = 16386,
109    /// `Whites`.
110    Whites = 16387,
111}
112
113impl ModeTag {
114    /// Reads a wire value, or `None` for one this revision does not define.
115    #[must_use]
116    pub const fn from_value(value: u16) -> Option<Self> {
117        match value {
118            0 => Some(Self::Auto),
119            1 => Some(Self::Quick),
120            2 => Some(Self::Quiet),
121            3 => Some(Self::LowNoise),
122            4 => Some(Self::LowEnergy),
123            5 => Some(Self::Vacation),
124            6 => Some(Self::Min),
125            7 => Some(Self::Max),
126            8 => Some(Self::Night),
127            9 => Some(Self::Day),
128            16384 => Some(Self::Normal),
129            16385 => Some(Self::Delicate),
130            16386 => Some(Self::Heavy),
131            16387 => Some(Self::Whites),
132            _ => None,
133        }
134    }
135
136    /// Its wire value.
137    #[must_use]
138    pub const fn value(self) -> u16 {
139        self as u16
140    }
141}
142
143impl ToTlv for ModeTag {
144    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
145        self.value().to_tlv(w, tag)
146    }
147}
148
149impl<'a> FromTlv<'a> for ModeTag {
150    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
151        let value = <u16 as FromTlv<'a>>::from_tlv(reader, element)?;
152        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
153    }
154}
155
156/// `ModeOptionStruct`.
157#[derive(Debug, Clone, Copy, PartialEq)]
158pub struct ModeOptionStruct<'a> {
159    /// `Label`, field 0.
160    pub label: &'a str,
161    /// `Mode`, field 1.
162    pub mode: u8,
163    /// `ModeTags`, field 2.
164    pub mode_tags: TlvList<'a, ModeTagStruct>,
165}
166
167impl<'a> ToTlv for ModeOptionStruct<'a> {
168    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
169        w.start_structure(tag)?;
170        self.label.to_tlv(w, Tag::Context(0))?;
171        self.mode.to_tlv(w, Tag::Context(1))?;
172        self.mode_tags.to_tlv(w, Tag::Context(2))?;
173        w.end_container()
174    }
175}
176
177impl<'a> FromTlv<'a> for ModeOptionStruct<'a> {
178    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
179        if element.value.container() != Some(ContainerKind::Structure) {
180            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
181        }
182        let mut label = None;
183        let mut mode = None;
184        let mut mode_tags = None;
185        loop {
186            let Some(field) = reader.next_element()? else {
187                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
188            };
189            if field.value == Value::EndOfContainer {
190                break;
191            }
192            match field.tag.context() {
193                Some(0) => label = Some(<&'a str>::from_tlv(reader, &field)?),
194                Some(1) => mode = Some(<u8>::from_tlv(reader, &field)?),
195                Some(2) => {
196                    mode_tags = Some(<TlvList<'a, ModeTagStruct>>::from_tlv(reader, &field)?)
197                }
198                // A field this revision does not define. §7.19.2: a receiver
199                // ignores what it does not know rather than refusing the whole
200                // structure, which is what lets a newer peer talk to an older one.
201                _ => reader.skip_value(&field)?,
202            }
203        }
204        Ok(Self {
205            label: label.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
206            mode: mode.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
207            mode_tags: mode_tags.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
208        })
209    }
210}
211
212/// `ModeTagStruct`.
213#[derive(Debug, Clone, Copy, PartialEq)]
214pub struct ModeTagStruct {
215    /// `MfgCode`, field 0.
216    pub mfg_code: Option<crate::msg::VendorId>,
217    /// `Value`, field 1.
218    pub value: u16,
219}
220
221impl ToTlv for ModeTagStruct {
222    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
223        w.start_structure(tag)?;
224        if let Some(value) = &self.mfg_code {
225            value.to_tlv(w, Tag::Context(0))?;
226        }
227        self.value.to_tlv(w, Tag::Context(1))?;
228        w.end_container()
229    }
230}
231
232impl<'a> FromTlv<'a> for ModeTagStruct {
233    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
234        if element.value.container() != Some(ContainerKind::Structure) {
235            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
236        }
237        let mut mfg_code = None;
238        let mut value = None;
239        loop {
240            let Some(field) = reader.next_element()? else {
241                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
242            };
243            if field.value == Value::EndOfContainer {
244                break;
245            }
246            match field.tag.context() {
247                Some(0) => mfg_code = Some(<crate::msg::VendorId>::from_tlv(reader, &field)?),
248                Some(1) => value = Some(<u16>::from_tlv(reader, &field)?),
249                // A field this revision does not define. §7.19.2: a receiver
250                // ignores what it does not know rather than refusing the whole
251                // structure, which is what lets a newer peer talk to an older one.
252                _ => reader.skip_value(&field)?,
253            }
254        }
255        Ok(Self {
256            mfg_code,
257            value: value.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
258        })
259    }
260}
261
262/// The fields of `ChangeToMode` (command `0x00`).
263#[derive(Debug, Clone, Copy, PartialEq)]
264pub struct ChangeToModeFields {
265    /// `NewMode`, field 0.
266    pub new_mode: u8,
267}
268
269impl ToTlv for ChangeToModeFields {
270    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
271        w.start_structure(tag)?;
272        self.new_mode.to_tlv(w, Tag::Context(0))?;
273        w.end_container()
274    }
275}
276
277impl<'a> FromTlv<'a> for ChangeToModeFields {
278    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
279        if element.value.container() != Some(ContainerKind::Structure) {
280            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
281        }
282        let mut new_mode = None;
283        loop {
284            let Some(field) = reader.next_element()? else {
285                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
286            };
287            if field.value == Value::EndOfContainer {
288                break;
289            }
290            match field.tag.context() {
291                Some(0) => new_mode = Some(<u8>::from_tlv(reader, &field)?),
292                // A field this revision does not define. §7.19.2: a receiver
293                // ignores what it does not know rather than refusing the whole
294                // structure, which is what lets a newer peer talk to an older one.
295                _ => reader.skip_value(&field)?,
296            }
297        }
298        Ok(Self {
299            new_mode: new_mode.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
300        })
301    }
302}
303
304/// The fields of `ChangeToModeResponse` (command `0x01`).
305#[derive(Debug, Clone, Copy, PartialEq)]
306pub struct ChangeToModeResponseFields<'a> {
307    /// `Status`, field 0.
308    pub status: u8,
309    /// `StatusText`, field 1.
310    pub status_text: &'a str,
311}
312
313impl<'a> ToTlv for ChangeToModeResponseFields<'a> {
314    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
315        w.start_structure(tag)?;
316        self.status.to_tlv(w, Tag::Context(0))?;
317        self.status_text.to_tlv(w, Tag::Context(1))?;
318        w.end_container()
319    }
320}
321
322impl<'a> FromTlv<'a> for ChangeToModeResponseFields<'a> {
323    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
324        if element.value.container() != Some(ContainerKind::Structure) {
325            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
326        }
327        let mut status = None;
328        let mut status_text = None;
329        loop {
330            let Some(field) = reader.next_element()? else {
331                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
332            };
333            if field.value == Value::EndOfContainer {
334                break;
335            }
336            match field.tag.context() {
337                Some(0) => status = Some(<u8>::from_tlv(reader, &field)?),
338                Some(1) => status_text = Some(<&'a str>::from_tlv(reader, &field)?),
339                // A field this revision does not define. §7.19.2: a receiver
340                // ignores what it does not know rather than refusing the whole
341                // structure, which is what lets a newer peer talk to an older one.
342                _ => reader.skip_value(&field)?,
343            }
344        }
345        Ok(Self {
346            status: status.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
347            status_text: status_text.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
348        })
349    }
350}
351
352/// Every attribute the specification defines, with its conformance.
353pub const ATTRIBUTES: &[Attribute] = &[
354    Attribute {
355        id: 0x0000,
356        name: "SupportedModes",
357        kind: "list[ModeOptionStruct]",
358        access: Access::read_only(Privilege::View),
359        qualities: AttributeQualities::empty(),
360        reporting: Reporting::OnChange,
361        conform: Conform::MANDATORY,
362    },
363    Attribute {
364        id: 0x0001,
365        name: "CurrentMode",
366        kind: "uint8",
367        access: Access::read_only(Privilege::View),
368        qualities: AttributeQualities::empty(),
369        reporting: Reporting::OnChange,
370        conform: Conform::MANDATORY,
371    },
372    Attribute {
373        id: 0x0002,
374        name: "StartUpMode",
375        kind: "uint8",
376        access: Access::read_only(Privilege::View),
377        qualities: AttributeQualities::empty(),
378        reporting: Reporting::OnChange,
379        conform: Conform::DISALLOWED,
380    },
381    Attribute {
382        id: 0x0003,
383        name: "OnMode",
384        kind: "uint8",
385        access: Access::read_only(Privilege::View),
386        qualities: AttributeQualities::empty(),
387        reporting: Reporting::OnChange,
388        conform: Conform::DISALLOWED,
389    },
390];
391
392/// Every command, with its conformance.
393pub const COMMANDS: &[Command] = &[
394    Command {
395        id: 0x00,
396        name: "ChangeToMode",
397        to_server: true,
398        response: Some(0x01),
399        access: Access::invoke(Privilege::Operate),
400        conform: Conform::MANDATORY,
401    },
402    Command {
403        id: 0x01,
404        name: "ChangeToModeResponse",
405        to_server: false,
406        response: None,
407        access: Access::invoke(Privilege::Operate),
408        conform: Conform::MANDATORY,
409    },
410];
411
412/// Every event, with its conformance.
413pub const EVENTS: &[Event] = &[];
414
415/// The whole cluster, as the specification defines it.
416pub const CLUSTER: Cluster = Cluster {
417    id: ID,
418    name: "Laundry Washer Mode",
419    revision: REVISION,
420    pics: "LWM",
421    derived_from: Some("Mode Base"),
422    features: FEATURES,
423    attributes: ATTRIBUTES,
424    commands: COMMANDS,
425    events: EVENTS,
426};