Skip to main content

matter_kit/clusters/generated/
microwave_oven_mode.rs

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