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 = 0x0055;
28
29pub const REVISION: u16 = 5;
32
33pub const PICS: &str = "RVCCLEANM";
35
36pub mod feature {
41 pub const ON_OFF: u32 = 1 << 0;
45 pub const DIRECT_MODE_CHANGE: u32 = 1 << 20;
49}
50
51pub 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
67pub mod attribute {
69 use crate::im::AttributeId;
70
71 pub const SUPPORTED_MODES: AttributeId = 0x00;
73 pub const CURRENT_MODE: AttributeId = 0x01;
75 pub const START_UP_MODE: AttributeId = 0x02;
77 pub const ON_MODE: AttributeId = 0x03;
79}
80
81pub mod command {
83 use crate::im::CommandId;
84
85 pub const CHANGE_TO_MODE: CommandId = 0x00;
87 pub const CHANGE_TO_MODE_RESPONSE: CommandId = 0x01;
89}
90
91#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
93#[repr(u16)]
94pub enum ModeTag {
95 Auto = 0,
97 Quick = 1,
99 Quiet = 2,
101 LowNoise = 3,
103 LowEnergy = 4,
105 Vacation = 5,
107 Min = 6,
109 Max = 7,
111 Night = 8,
113 Day = 9,
115 DeepClean = 16384,
117 Vacuum = 16385,
119 Mop = 16386,
121 VacuumThenMop = 16387,
123}
124
125impl ModeTag {
126 #[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 #[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#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
170#[repr(u8)]
171pub enum StatusCodeEnum {
172 CleaningInProgress = 64,
174}
175
176impl StatusCodeEnum {
177 #[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 #[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#[derive(Debug, Clone, Copy, PartialEq)]
208pub struct ModeOptionStruct<'a> {
209 pub label: &'a str,
211 pub mode: u8,
213 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
264pub struct ModeTagStruct {
265 pub mfg_code: Option<crate::msg::VendorId>,
267 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
314pub struct ChangeToModeFields {
315 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
356pub struct ChangeToModeResponseFields<'a> {
357 pub status: u8,
359 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 _ => 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
402pub 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
442pub 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
462pub const EVENTS: &[Event] = &[];
464
465pub 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};