Skip to main content

matter_kit/clusters/generated/
chime.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Chime — cluster 0x0556.
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//! Chime (cluster `0x0556`, revision 2).
10//!
11//! 5 identifiers, 0 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 = 0x0556;
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 = "CHIME";
35
36/// This cluster defines no features, so its `FeatureMap` is always zero.
37pub const FEATURES: &[Feature] = &[];
38
39/// The attribute ids.
40pub mod attribute {
41    use crate::im::AttributeId;
42
43    /// `InstalledChimeSounds`.
44    pub const INSTALLED_CHIME_SOUNDS: AttributeId = 0x00;
45    /// `SelectedChime`.
46    pub const SELECTED_CHIME: AttributeId = 0x01;
47    /// `Enabled`.
48    pub const ENABLED: AttributeId = 0x02;
49}
50
51/// The command ids.
52pub mod command {
53    use crate::im::CommandId;
54
55    /// `PlayChimeSound`.
56    pub const PLAY_CHIME_SOUND: CommandId = 0x00;
57}
58
59/// The event ids.
60pub mod event {
61    use crate::im::EventId;
62
63    /// `ChimeStartedPlaying`.
64    pub const CHIME_STARTED_PLAYING: EventId = 0x00;
65}
66
67/// `ChimeSoundStruct`.
68#[derive(Debug, Clone, Copy, PartialEq)]
69pub struct ChimeSoundStruct<'a> {
70    /// `ChimeID`, field 0.
71    pub chime_id: u8,
72    /// `Name`, field 1.
73    pub name: &'a str,
74}
75
76impl<'a> ToTlv for ChimeSoundStruct<'a> {
77    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
78        w.start_structure(tag)?;
79        self.chime_id.to_tlv(w, Tag::Context(0))?;
80        self.name.to_tlv(w, Tag::Context(1))?;
81        w.end_container()
82    }
83}
84
85impl<'a> FromTlv<'a> for ChimeSoundStruct<'a> {
86    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
87        if element.value.container() != Some(ContainerKind::Structure) {
88            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
89        }
90        let mut chime_id = None;
91        let mut name = None;
92        loop {
93            let Some(field) = reader.next_element()? else {
94                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
95            };
96            if field.value == Value::EndOfContainer {
97                break;
98            }
99            match field.tag.context() {
100                Some(0) => chime_id = Some(<u8>::from_tlv(reader, &field)?),
101                Some(1) => name = Some(<&'a str>::from_tlv(reader, &field)?),
102                // A field this revision does not define. §7.19.2: a receiver
103                // ignores what it does not know rather than refusing the whole
104                // structure, which is what lets a newer peer talk to an older one.
105                _ => reader.skip_value(&field)?,
106            }
107        }
108        Ok(Self {
109            chime_id: chime_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
110            name: name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
111        })
112    }
113}
114
115/// The fields of `PlayChimeSound` (command `0x00`).
116#[derive(Debug, Clone, Copy, PartialEq)]
117pub struct PlayChimeSoundFields {
118    /// `ChimeID`, field 0.
119    pub chime_id: Option<u8>,
120}
121
122impl ToTlv for PlayChimeSoundFields {
123    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
124        w.start_structure(tag)?;
125        if let Some(value) = &self.chime_id {
126            value.to_tlv(w, Tag::Context(0))?;
127        }
128        w.end_container()
129    }
130}
131
132impl<'a> FromTlv<'a> for PlayChimeSoundFields {
133    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
134        if element.value.container() != Some(ContainerKind::Structure) {
135            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
136        }
137        let mut chime_id = None;
138        loop {
139            let Some(field) = reader.next_element()? else {
140                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
141            };
142            if field.value == Value::EndOfContainer {
143                break;
144            }
145            match field.tag.context() {
146                Some(0) => chime_id = Some(<u8>::from_tlv(reader, &field)?),
147                // A field this revision does not define. §7.19.2: a receiver
148                // ignores what it does not know rather than refusing the whole
149                // structure, which is what lets a newer peer talk to an older one.
150                _ => reader.skip_value(&field)?,
151            }
152        }
153        Ok(Self { chime_id })
154    }
155}
156
157/// Every attribute the specification defines, with its conformance.
158pub const ATTRIBUTES: &[Attribute] = &[
159    Attribute {
160        id: 0x0000,
161        name: "InstalledChimeSounds",
162        kind: "list[ChimeSoundStruct]",
163        access: Access::read_only(Privilege::View),
164        qualities: AttributeQualities::empty(),
165        reporting: Reporting::OnChange,
166        conform: Conform::MANDATORY,
167    },
168    Attribute {
169        id: 0x0001,
170        name: "SelectedChime",
171        kind: "uint8",
172        access: Access::read_write_with(Privilege::View, Privilege::Operate),
173        qualities: AttributeQualities::NON_VOLATILE,
174        reporting: Reporting::OnChange,
175        conform: Conform::MANDATORY,
176    },
177    Attribute {
178        id: 0x0002,
179        name: "Enabled",
180        kind: "bool",
181        access: Access::read_write_with(Privilege::View, Privilege::Operate),
182        qualities: AttributeQualities::NON_VOLATILE,
183        reporting: Reporting::OnChange,
184        conform: Conform::MANDATORY,
185    },
186];
187
188/// Every command, with its conformance.
189pub const COMMANDS: &[Command] = &[Command {
190    id: 0x00,
191    name: "PlayChimeSound",
192    to_server: true,
193    response: None,
194    access: Access::invoke(Privilege::Operate),
195    conform: Conform::MANDATORY,
196}];
197
198/// Every event, with its conformance.
199pub const EVENTS: &[Event] = &[Event {
200    id: 0x00,
201    name: "ChimeStartedPlaying",
202    priority: EventPriority::Info,
203    access: Access::read_only(Privilege::View),
204    conform: Conform {
205        clauses: &[Clause {
206            verdict: Conformance::Described,
207            when: Condition::Named("comparison"),
208        }],
209    },
210}];
211
212/// The whole cluster, as the specification defines it.
213pub const CLUSTER: Cluster = Cluster {
214    id: ID,
215    name: "Chime",
216    revision: REVISION,
217    pics: "CHIME",
218    derived_from: None,
219    features: FEATURES,
220    attributes: ATTRIBUTES,
221    commands: COMMANDS,
222    events: EVENTS,
223};