Skip to main content

matter_kit/clusters/generated/
rvc_clean_mode.rs

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