1#![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 = 0x0059;
28
29pub const REVISION: u16 = 3;
32
33pub const PICS: &str = "DISHM";
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::DISALLOWED,
53}];
54
55pub mod attribute {
57 use crate::im::AttributeId;
58
59 pub const SUPPORTED_MODES: AttributeId = 0x00;
61 pub const CURRENT_MODE: AttributeId = 0x01;
63 pub const START_UP_MODE: AttributeId = 0x02;
65 pub const ON_MODE: AttributeId = 0x03;
67}
68
69pub mod command {
71 use crate::im::CommandId;
72
73 pub const CHANGE_TO_MODE: CommandId = 0x00;
75 pub const CHANGE_TO_MODE_RESPONSE: CommandId = 0x01;
77}
78
79#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
81#[repr(u16)]
82pub enum ModeTag {
83 Auto = 0,
85 Quick = 1,
87 Quiet = 2,
89 LowNoise = 3,
91 LowEnergy = 4,
93 Vacation = 5,
95 Min = 6,
97 Max = 7,
99 Night = 8,
101 Day = 9,
103 Normal = 16384,
105 Heavy = 16385,
107 Light = 16386,
109}
110
111impl ModeTag {
112 #[must_use]
114 pub const fn from_value(value: u16) -> Option<Self> {
115 match value {
116 0 => Some(Self::Auto),
117 1 => Some(Self::Quick),
118 2 => Some(Self::Quiet),
119 3 => Some(Self::LowNoise),
120 4 => Some(Self::LowEnergy),
121 5 => Some(Self::Vacation),
122 6 => Some(Self::Min),
123 7 => Some(Self::Max),
124 8 => Some(Self::Night),
125 9 => Some(Self::Day),
126 16384 => Some(Self::Normal),
127 16385 => Some(Self::Heavy),
128 16386 => Some(Self::Light),
129 _ => None,
130 }
131 }
132
133 #[must_use]
135 pub const fn value(self) -> u16 {
136 self as u16
137 }
138}
139
140impl ToTlv for ModeTag {
141 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
142 self.value().to_tlv(w, tag)
143 }
144}
145
146impl<'a> FromTlv<'a> for ModeTag {
147 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
148 let value = <u16 as FromTlv<'a>>::from_tlv(reader, element)?;
149 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
150 }
151}
152
153#[derive(Debug, Clone, Copy, PartialEq)]
155pub struct ModeOptionStruct<'a> {
156 pub label: &'a str,
158 pub mode: u8,
160 pub mode_tags: TlvList<'a, ModeTagStruct>,
162}
163
164impl<'a> ToTlv for ModeOptionStruct<'a> {
165 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
166 w.start_structure(tag)?;
167 self.label.to_tlv(w, Tag::Context(0))?;
168 self.mode.to_tlv(w, Tag::Context(1))?;
169 self.mode_tags.to_tlv(w, Tag::Context(2))?;
170 w.end_container()
171 }
172}
173
174impl<'a> FromTlv<'a> for ModeOptionStruct<'a> {
175 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
176 if element.value.container() != Some(ContainerKind::Structure) {
177 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
178 }
179 let mut label = None;
180 let mut mode = None;
181 let mut mode_tags = None;
182 loop {
183 let Some(field) = reader.next_element()? else {
184 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
185 };
186 if field.value == Value::EndOfContainer {
187 break;
188 }
189 match field.tag.context() {
190 Some(0) => label = Some(<&'a str>::from_tlv(reader, &field)?),
191 Some(1) => mode = Some(<u8>::from_tlv(reader, &field)?),
192 Some(2) => {
193 mode_tags = Some(<TlvList<'a, ModeTagStruct>>::from_tlv(reader, &field)?)
194 }
195 _ => reader.skip_value(&field)?,
199 }
200 }
201 Ok(Self {
202 label: label.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
203 mode: mode.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
204 mode_tags: mode_tags.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
205 })
206 }
207}
208
209#[derive(Debug, Clone, Copy, PartialEq)]
211pub struct ModeTagStruct {
212 pub mfg_code: Option<crate::msg::VendorId>,
214 pub value: u16,
216}
217
218impl ToTlv for ModeTagStruct {
219 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
220 w.start_structure(tag)?;
221 if let Some(value) = &self.mfg_code {
222 value.to_tlv(w, Tag::Context(0))?;
223 }
224 self.value.to_tlv(w, Tag::Context(1))?;
225 w.end_container()
226 }
227}
228
229impl<'a> FromTlv<'a> for ModeTagStruct {
230 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
231 if element.value.container() != Some(ContainerKind::Structure) {
232 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
233 }
234 let mut mfg_code = None;
235 let mut value = None;
236 loop {
237 let Some(field) = reader.next_element()? else {
238 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
239 };
240 if field.value == Value::EndOfContainer {
241 break;
242 }
243 match field.tag.context() {
244 Some(0) => mfg_code = Some(<crate::msg::VendorId>::from_tlv(reader, &field)?),
245 Some(1) => value = Some(<u16>::from_tlv(reader, &field)?),
246 _ => reader.skip_value(&field)?,
250 }
251 }
252 Ok(Self {
253 mfg_code,
254 value: value.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
255 })
256 }
257}
258
259#[derive(Debug, Clone, Copy, PartialEq)]
261pub struct ChangeToModeFields {
262 pub new_mode: u8,
264}
265
266impl ToTlv for ChangeToModeFields {
267 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
268 w.start_structure(tag)?;
269 self.new_mode.to_tlv(w, Tag::Context(0))?;
270 w.end_container()
271 }
272}
273
274impl<'a> FromTlv<'a> for ChangeToModeFields {
275 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
276 if element.value.container() != Some(ContainerKind::Structure) {
277 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
278 }
279 let mut new_mode = None;
280 loop {
281 let Some(field) = reader.next_element()? else {
282 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
283 };
284 if field.value == Value::EndOfContainer {
285 break;
286 }
287 match field.tag.context() {
288 Some(0) => new_mode = Some(<u8>::from_tlv(reader, &field)?),
289 _ => reader.skip_value(&field)?,
293 }
294 }
295 Ok(Self {
296 new_mode: new_mode.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
297 })
298 }
299}
300
301#[derive(Debug, Clone, Copy, PartialEq)]
303pub struct ChangeToModeResponseFields<'a> {
304 pub status: u8,
306 pub status_text: &'a str,
308}
309
310impl<'a> ToTlv for ChangeToModeResponseFields<'a> {
311 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
312 w.start_structure(tag)?;
313 self.status.to_tlv(w, Tag::Context(0))?;
314 self.status_text.to_tlv(w, Tag::Context(1))?;
315 w.end_container()
316 }
317}
318
319impl<'a> FromTlv<'a> for ChangeToModeResponseFields<'a> {
320 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
321 if element.value.container() != Some(ContainerKind::Structure) {
322 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
323 }
324 let mut status = None;
325 let mut status_text = None;
326 loop {
327 let Some(field) = reader.next_element()? else {
328 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
329 };
330 if field.value == Value::EndOfContainer {
331 break;
332 }
333 match field.tag.context() {
334 Some(0) => status = Some(<u8>::from_tlv(reader, &field)?),
335 Some(1) => status_text = Some(<&'a str>::from_tlv(reader, &field)?),
336 _ => reader.skip_value(&field)?,
340 }
341 }
342 Ok(Self {
343 status: status.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
344 status_text: status_text.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
345 })
346 }
347}
348
349pub const ATTRIBUTES: &[Attribute] = &[
351 Attribute {
352 id: 0x0000,
353 name: "SupportedModes",
354 kind: "list[ModeOptionStruct]",
355 access: Access::read_only(Privilege::View),
356 qualities: AttributeQualities::empty(),
357 reporting: Reporting::OnChange,
358 conform: Conform::MANDATORY,
359 },
360 Attribute {
361 id: 0x0001,
362 name: "CurrentMode",
363 kind: "uint8",
364 access: Access::read_only(Privilege::View),
365 qualities: AttributeQualities::empty(),
366 reporting: Reporting::OnChange,
367 conform: Conform::MANDATORY,
368 },
369 Attribute {
370 id: 0x0002,
371 name: "StartUpMode",
372 kind: "uint8",
373 access: Access::read_only(Privilege::View),
374 qualities: AttributeQualities::empty(),
375 reporting: Reporting::OnChange,
376 conform: Conform::DISALLOWED,
377 },
378 Attribute {
379 id: 0x0003,
380 name: "OnMode",
381 kind: "uint8",
382 access: Access::read_only(Privilege::View),
383 qualities: AttributeQualities::empty(),
384 reporting: Reporting::OnChange,
385 conform: Conform::DISALLOWED,
386 },
387];
388
389pub const COMMANDS: &[Command] = &[
391 Command {
392 id: 0x00,
393 name: "ChangeToMode",
394 to_server: true,
395 response: Some(0x01),
396 access: Access::invoke(Privilege::Operate),
397 conform: Conform::MANDATORY,
398 },
399 Command {
400 id: 0x01,
401 name: "ChangeToModeResponse",
402 to_server: false,
403 response: None,
404 access: Access::invoke(Privilege::Operate),
405 conform: Conform::MANDATORY,
406 },
407];
408
409pub const EVENTS: &[Event] = &[];
411
412pub const CLUSTER: Cluster = Cluster {
414 id: ID,
415 name: "Dishwasher Mode",
416 revision: REVISION,
417 pics: "DISHM",
418 derived_from: Some("Mode Base"),
419 features: FEATURES,
420 attributes: ATTRIBUTES,
421 commands: COMMANDS,
422 events: EVENTS,
423};