Skip to main content

matter_kit/clusters/generated/
mode_base.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Mode Base — cluster 0xFFFF0003.
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//! Mode Base (cluster `0xFFFF0003`, 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 = 0xFFFF0003;
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 = "MODB";
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::OPTIONAL,
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/// `ModeOptionStruct`.
80#[derive(Debug, Clone, Copy, PartialEq)]
81pub struct ModeOptionStruct<'a> {
82    /// `Label`, field 0.
83    pub label: &'a str,
84    /// `Mode`, field 1.
85    pub mode: u8,
86    /// `ModeTags`, field 2.
87    pub mode_tags: TlvList<'a, ModeTagStruct>,
88}
89
90impl<'a> ToTlv for ModeOptionStruct<'a> {
91    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
92        w.start_structure(tag)?;
93        self.label.to_tlv(w, Tag::Context(0))?;
94        self.mode.to_tlv(w, Tag::Context(1))?;
95        self.mode_tags.to_tlv(w, Tag::Context(2))?;
96        w.end_container()
97    }
98}
99
100impl<'a> FromTlv<'a> for ModeOptionStruct<'a> {
101    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
102        if element.value.container() != Some(ContainerKind::Structure) {
103            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
104        }
105        let mut label = None;
106        let mut mode = None;
107        let mut mode_tags = None;
108        loop {
109            let Some(field) = reader.next_element()? else {
110                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
111            };
112            if field.value == Value::EndOfContainer {
113                break;
114            }
115            match field.tag.context() {
116                Some(0) => label = Some(<&'a str>::from_tlv(reader, &field)?),
117                Some(1) => mode = Some(<u8>::from_tlv(reader, &field)?),
118                Some(2) => {
119                    mode_tags = Some(<TlvList<'a, ModeTagStruct>>::from_tlv(reader, &field)?)
120                }
121                // A field this revision does not define. §7.19.2: a receiver
122                // ignores what it does not know rather than refusing the whole
123                // structure, which is what lets a newer peer talk to an older one.
124                _ => reader.skip_value(&field)?,
125            }
126        }
127        Ok(Self {
128            label: label.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
129            mode: mode.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
130            mode_tags: mode_tags.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
131        })
132    }
133}
134
135/// `ModeTagStruct`.
136#[derive(Debug, Clone, Copy, PartialEq)]
137pub struct ModeTagStruct {
138    /// `MfgCode`, field 0.
139    pub mfg_code: Option<crate::msg::VendorId>,
140    /// `Value`, field 1.
141    pub value: u16,
142}
143
144impl ToTlv for ModeTagStruct {
145    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
146        w.start_structure(tag)?;
147        if let Some(value) = &self.mfg_code {
148            value.to_tlv(w, Tag::Context(0))?;
149        }
150        self.value.to_tlv(w, Tag::Context(1))?;
151        w.end_container()
152    }
153}
154
155impl<'a> FromTlv<'a> for ModeTagStruct {
156    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
157        if element.value.container() != Some(ContainerKind::Structure) {
158            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
159        }
160        let mut mfg_code = None;
161        let mut value = None;
162        loop {
163            let Some(field) = reader.next_element()? else {
164                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
165            };
166            if field.value == Value::EndOfContainer {
167                break;
168            }
169            match field.tag.context() {
170                Some(0) => mfg_code = Some(<crate::msg::VendorId>::from_tlv(reader, &field)?),
171                Some(1) => value = Some(<u16>::from_tlv(reader, &field)?),
172                // A field this revision does not define. §7.19.2: a receiver
173                // ignores what it does not know rather than refusing the whole
174                // structure, which is what lets a newer peer talk to an older one.
175                _ => reader.skip_value(&field)?,
176            }
177        }
178        Ok(Self {
179            mfg_code,
180            value: value.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
181        })
182    }
183}
184
185/// The fields of `ChangeToMode` (command `0x00`).
186#[derive(Debug, Clone, Copy, PartialEq)]
187pub struct ChangeToModeFields {
188    /// `NewMode`, field 0.
189    pub new_mode: u8,
190}
191
192impl ToTlv for ChangeToModeFields {
193    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
194        w.start_structure(tag)?;
195        self.new_mode.to_tlv(w, Tag::Context(0))?;
196        w.end_container()
197    }
198}
199
200impl<'a> FromTlv<'a> for ChangeToModeFields {
201    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
202        if element.value.container() != Some(ContainerKind::Structure) {
203            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
204        }
205        let mut new_mode = None;
206        loop {
207            let Some(field) = reader.next_element()? else {
208                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
209            };
210            if field.value == Value::EndOfContainer {
211                break;
212            }
213            match field.tag.context() {
214                Some(0) => new_mode = Some(<u8>::from_tlv(reader, &field)?),
215                // A field this revision does not define. §7.19.2: a receiver
216                // ignores what it does not know rather than refusing the whole
217                // structure, which is what lets a newer peer talk to an older one.
218                _ => reader.skip_value(&field)?,
219            }
220        }
221        Ok(Self {
222            new_mode: new_mode.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
223        })
224    }
225}
226
227/// The fields of `ChangeToModeResponse` (command `0x01`).
228#[derive(Debug, Clone, Copy, PartialEq)]
229pub struct ChangeToModeResponseFields<'a> {
230    /// `Status`, field 0.
231    pub status: u8,
232    /// `StatusText`, field 1.
233    pub status_text: &'a str,
234}
235
236impl<'a> ToTlv for ChangeToModeResponseFields<'a> {
237    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
238        w.start_structure(tag)?;
239        self.status.to_tlv(w, Tag::Context(0))?;
240        self.status_text.to_tlv(w, Tag::Context(1))?;
241        w.end_container()
242    }
243}
244
245impl<'a> FromTlv<'a> for ChangeToModeResponseFields<'a> {
246    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
247        if element.value.container() != Some(ContainerKind::Structure) {
248            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
249        }
250        let mut status = None;
251        let mut status_text = None;
252        loop {
253            let Some(field) = reader.next_element()? else {
254                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
255            };
256            if field.value == Value::EndOfContainer {
257                break;
258            }
259            match field.tag.context() {
260                Some(0) => status = Some(<u8>::from_tlv(reader, &field)?),
261                Some(1) => status_text = Some(<&'a str>::from_tlv(reader, &field)?),
262                // A field this revision does not define. §7.19.2: a receiver
263                // ignores what it does not know rather than refusing the whole
264                // structure, which is what lets a newer peer talk to an older one.
265                _ => reader.skip_value(&field)?,
266            }
267        }
268        Ok(Self {
269            status: status.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
270            status_text: status_text.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
271        })
272    }
273}