Skip to main content

matter_kit/clusters/generated/
oven_mode.rs

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