matter_kit/clusters/generated/
mode_select.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 = 0x0050;
28
29pub const REVISION: u16 = 2;
32
33pub const PICS: &str = "MOD";
35
36pub mod feature {
41 pub const ON_OFF: u32 = 1 << 0;
45}
46
47pub const FEATURES: &[Feature] = &[Feature {
49 bit: 0,
50 code: "DEPONOFF",
51 name: "OnOff",
52 conform: Conform::OPTIONAL,
53}];
54
55pub mod attribute {
57 use crate::im::AttributeId;
58
59 pub const DESCRIPTION: AttributeId = 0x00;
61 pub const STANDARD_NAMESPACE: AttributeId = 0x01;
63 pub const SUPPORTED_MODES: AttributeId = 0x02;
65 pub const CURRENT_MODE: AttributeId = 0x03;
67 pub const START_UP_MODE: AttributeId = 0x04;
69 pub const ON_MODE: AttributeId = 0x05;
71}
72
73pub mod command {
75 use crate::im::CommandId;
76
77 pub const CHANGE_TO_MODE: CommandId = 0x00;
79}
80
81#[derive(Debug, Clone, Copy, PartialEq)]
83pub struct ModeOptionStruct<'a> {
84 pub label: &'a str,
86 pub mode: u8,
88 pub semantic_tags: TlvList<'a, SemanticTagStruct>,
90}
91
92impl<'a> ToTlv for ModeOptionStruct<'a> {
93 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
94 w.start_structure(tag)?;
95 self.label.to_tlv(w, Tag::Context(0))?;
96 self.mode.to_tlv(w, Tag::Context(1))?;
97 self.semantic_tags.to_tlv(w, Tag::Context(2))?;
98 w.end_container()
99 }
100}
101
102impl<'a> FromTlv<'a> for ModeOptionStruct<'a> {
103 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
104 if element.value.container() != Some(ContainerKind::Structure) {
105 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
106 }
107 let mut label = None;
108 let mut mode = None;
109 let mut semantic_tags = None;
110 loop {
111 let Some(field) = reader.next_element()? else {
112 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
113 };
114 if field.value == Value::EndOfContainer {
115 break;
116 }
117 match field.tag.context() {
118 Some(0) => label = Some(<&'a str>::from_tlv(reader, &field)?),
119 Some(1) => mode = Some(<u8>::from_tlv(reader, &field)?),
120 Some(2) => {
121 semantic_tags =
122 Some(<TlvList<'a, SemanticTagStruct>>::from_tlv(reader, &field)?)
123 }
124 _ => reader.skip_value(&field)?,
128 }
129 }
130 Ok(Self {
131 label: label.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
132 mode: mode.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
133 semantic_tags: semantic_tags.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
134 })
135 }
136}
137
138#[derive(Debug, Clone, Copy, PartialEq)]
140pub struct SemanticTagStruct {
141 pub mfg_code: crate::msg::VendorId,
143 pub value: u16,
145}
146
147impl ToTlv for SemanticTagStruct {
148 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
149 w.start_structure(tag)?;
150 self.mfg_code.to_tlv(w, Tag::Context(0))?;
151 self.value.to_tlv(w, Tag::Context(1))?;
152 w.end_container()
153 }
154}
155
156impl<'a> FromTlv<'a> for SemanticTagStruct {
157 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
158 if element.value.container() != Some(ContainerKind::Structure) {
159 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
160 }
161 let mut mfg_code = None;
162 let mut value = None;
163 loop {
164 let Some(field) = reader.next_element()? else {
165 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
166 };
167 if field.value == Value::EndOfContainer {
168 break;
169 }
170 match field.tag.context() {
171 Some(0) => mfg_code = Some(<crate::msg::VendorId>::from_tlv(reader, &field)?),
172 Some(1) => value = Some(<u16>::from_tlv(reader, &field)?),
173 _ => reader.skip_value(&field)?,
177 }
178 }
179 Ok(Self {
180 mfg_code: mfg_code.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
181 value: value.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
182 })
183 }
184}
185
186#[derive(Debug, Clone, Copy, PartialEq)]
188pub struct ChangeToModeFields {
189 pub new_mode: u8,
191}
192
193impl ToTlv for ChangeToModeFields {
194 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
195 w.start_structure(tag)?;
196 self.new_mode.to_tlv(w, Tag::Context(0))?;
197 w.end_container()
198 }
199}
200
201impl<'a> FromTlv<'a> for ChangeToModeFields {
202 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
203 if element.value.container() != Some(ContainerKind::Structure) {
204 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
205 }
206 let mut new_mode = None;
207 loop {
208 let Some(field) = reader.next_element()? else {
209 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
210 };
211 if field.value == Value::EndOfContainer {
212 break;
213 }
214 match field.tag.context() {
215 Some(0) => new_mode = Some(<u8>::from_tlv(reader, &field)?),
216 _ => reader.skip_value(&field)?,
220 }
221 }
222 Ok(Self {
223 new_mode: new_mode.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
224 })
225 }
226}
227
228pub const ATTRIBUTES: &[Attribute] = &[
230 Attribute {
231 id: 0x0000,
232 name: "Description",
233 kind: "string",
234 access: Access::read_only(Privilege::View),
235 qualities: AttributeQualities::FIXED,
236 reporting: Reporting::OnChange,
237 conform: Conform::MANDATORY,
238 },
239 Attribute {
240 id: 0x0001,
241 name: "StandardNamespace",
242 kind: "enum16",
243 access: Access::read_only(Privilege::View),
244 qualities: AttributeQualities::NULLABLE.union(AttributeQualities::FIXED),
245 reporting: Reporting::OnChange,
246 conform: Conform::MANDATORY,
247 },
248 Attribute {
249 id: 0x0002,
250 name: "SupportedModes",
251 kind: "list[ModeOptionStruct]",
252 access: Access::read_only(Privilege::View),
253 qualities: AttributeQualities::FIXED,
254 reporting: Reporting::OnChange,
255 conform: Conform::MANDATORY,
256 },
257 Attribute {
258 id: 0x0003,
259 name: "CurrentMode",
260 kind: "uint8",
261 access: Access::read_only(Privilege::View),
262 qualities: AttributeQualities::NON_VOLATILE,
263 reporting: Reporting::OnChange,
264 conform: Conform::MANDATORY,
265 },
266 Attribute {
267 id: 0x0004,
268 name: "StartUpMode",
269 kind: "uint8",
270 access: Access::read_write_with(Privilege::View, Privilege::Operate),
271 qualities: AttributeQualities::NULLABLE.union(AttributeQualities::NON_VOLATILE),
272 reporting: Reporting::OnChange,
273 conform: Conform::OPTIONAL,
274 },
275 Attribute {
276 id: 0x0005,
277 name: "OnMode",
278 kind: "uint8",
279 access: Access::read_write_with(Privilege::View, Privilege::Operate),
280 qualities: AttributeQualities::NULLABLE.union(AttributeQualities::NON_VOLATILE),
281 reporting: Reporting::OnChange,
282 conform: Conform {
283 clauses: &[Clause {
284 verdict: Conformance::Mandatory,
285 when: Condition::Feature(0),
286 }],
287 },
288 },
289];
290
291pub const COMMANDS: &[Command] = &[Command {
293 id: 0x00,
294 name: "ChangeToMode",
295 to_server: true,
296 response: None,
297 access: Access::invoke(Privilege::Operate),
298 conform: Conform::MANDATORY,
299}];
300
301pub const EVENTS: &[Event] = &[];
303
304pub const CLUSTER: Cluster = Cluster {
306 id: ID,
307 name: "Mode Select",
308 revision: REVISION,
309 pics: "MOD",
310 derived_from: None,
311 features: FEATURES,
312 attributes: ATTRIBUTES,
313 commands: COMMANDS,
314 events: EVENTS,
315};