matter_kit/clusters/generated/
chime.rs1#![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
26pub const ID: ClusterId = 0x0556;
28
29pub const REVISION: u16 = 2;
32
33pub const PICS: &str = "CHIME";
35
36pub const FEATURES: &[Feature] = &[];
38
39pub mod attribute {
41 use crate::im::AttributeId;
42
43 pub const INSTALLED_CHIME_SOUNDS: AttributeId = 0x00;
45 pub const SELECTED_CHIME: AttributeId = 0x01;
47 pub const ENABLED: AttributeId = 0x02;
49}
50
51pub mod command {
53 use crate::im::CommandId;
54
55 pub const PLAY_CHIME_SOUND: CommandId = 0x00;
57}
58
59pub mod event {
61 use crate::im::EventId;
62
63 pub const CHIME_STARTED_PLAYING: EventId = 0x00;
65}
66
67#[derive(Debug, Clone, Copy, PartialEq)]
69pub struct ChimeSoundStruct<'a> {
70 pub chime_id: u8,
72 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
117pub struct PlayChimeSoundFields {
118 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 _ => reader.skip_value(&field)?,
151 }
152 }
153 Ok(Self { chime_id })
154 }
155}
156
157pub 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
188pub 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
198pub 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
212pub 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};