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 = 0x0006;
28
29pub const REVISION: u16 = 6;
32
33pub const PICS: &str = "OO";
35
36pub mod feature {
41 pub const LIGHTING: u32 = 1 << 0;
45 pub const DEAD_FRONT_BEHAVIOR: u32 = 1 << 1;
49 pub const OFF_ONLY: u32 = 1 << 2;
53}
54
55pub const FEATURES: &[Feature] = &[
57 Feature {
58 bit: 0,
59 code: "LT",
60 name: "Lighting",
61 conform: Conform {
62 clauses: &[Clause {
63 verdict: Conformance::Optional,
64 when: Condition::Not(&Condition::Feature(2)),
65 }],
66 },
67 },
68 Feature {
69 bit: 1,
70 code: "DF",
71 name: "DeadFrontBehavior",
72 conform: Conform {
73 clauses: &[Clause {
74 verdict: Conformance::Optional,
75 when: Condition::Not(&Condition::Feature(2)),
76 }],
77 },
78 },
79 Feature {
80 bit: 2,
81 code: "OFFONLY",
82 name: "OffOnly",
83 conform: Conform {
84 clauses: &[Clause {
85 verdict: Conformance::Optional,
86 when: Condition::Not(&Condition::Any(&[
87 Condition::Feature(0),
88 Condition::Feature(1),
89 ])),
90 }],
91 },
92 },
93];
94
95pub mod attribute {
97 use crate::im::AttributeId;
98
99 pub const ON_OFF: AttributeId = 0x00;
101 pub const GLOBAL_SCENE_CONTROL: AttributeId = 0x4000;
103 pub const ON_TIME: AttributeId = 0x4001;
105 pub const OFF_WAIT_TIME: AttributeId = 0x4002;
107 pub const START_UP_ON_OFF: AttributeId = 0x4003;
109}
110
111pub mod command {
113 use crate::im::CommandId;
114
115 pub const OFF: CommandId = 0x00;
117 pub const ON: CommandId = 0x01;
119 pub const TOGGLE: CommandId = 0x02;
121 pub const OFF_WITH_EFFECT: CommandId = 0x40;
123 pub const ON_WITH_RECALL_GLOBAL_SCENE: CommandId = 0x41;
125 pub const ON_WITH_TIMED_OFF: CommandId = 0x42;
127}
128
129#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
131#[repr(u8)]
132pub enum DelayedAllOffEffectVariantEnum {
133 DelayedOffFastFade = 0,
135 NoFade = 1,
137 DelayedOffSlowFade = 2,
139}
140
141impl DelayedAllOffEffectVariantEnum {
142 #[must_use]
144 pub const fn from_value(value: u8) -> Option<Self> {
145 match value {
146 0 => Some(Self::DelayedOffFastFade),
147 1 => Some(Self::NoFade),
148 2 => Some(Self::DelayedOffSlowFade),
149 _ => None,
150 }
151 }
152
153 #[must_use]
155 pub const fn value(self) -> u8 {
156 self as u8
157 }
158}
159
160impl ToTlv for DelayedAllOffEffectVariantEnum {
161 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
162 self.value().to_tlv(w, tag)
163 }
164}
165
166impl<'a> FromTlv<'a> for DelayedAllOffEffectVariantEnum {
167 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
168 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
169 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
170 }
171}
172
173#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
175#[repr(u8)]
176pub enum DyingLightEffectVariantEnum {
177 DyingLightFadeOff = 0,
179}
180
181impl DyingLightEffectVariantEnum {
182 #[must_use]
184 pub const fn from_value(value: u8) -> Option<Self> {
185 match value {
186 0 => Some(Self::DyingLightFadeOff),
187 _ => None,
188 }
189 }
190
191 #[must_use]
193 pub const fn value(self) -> u8 {
194 self as u8
195 }
196}
197
198impl ToTlv for DyingLightEffectVariantEnum {
199 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
200 self.value().to_tlv(w, tag)
201 }
202}
203
204impl<'a> FromTlv<'a> for DyingLightEffectVariantEnum {
205 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
206 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
207 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
208 }
209}
210
211#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
213#[repr(u8)]
214pub enum EffectIdentifierEnum {
215 DelayedAllOff = 0,
217 DyingLight = 1,
219}
220
221impl EffectIdentifierEnum {
222 #[must_use]
224 pub const fn from_value(value: u8) -> Option<Self> {
225 match value {
226 0 => Some(Self::DelayedAllOff),
227 1 => Some(Self::DyingLight),
228 _ => None,
229 }
230 }
231
232 #[must_use]
234 pub const fn value(self) -> u8 {
235 self as u8
236 }
237}
238
239impl ToTlv for EffectIdentifierEnum {
240 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
241 self.value().to_tlv(w, tag)
242 }
243}
244
245impl<'a> FromTlv<'a> for EffectIdentifierEnum {
246 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
247 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
248 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
249 }
250}
251
252#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
254#[repr(u8)]
255pub enum StartUpOnOffEnum {
256 Off = 0,
258 On = 1,
260 Toggle = 2,
262}
263
264impl StartUpOnOffEnum {
265 #[must_use]
267 pub const fn from_value(value: u8) -> Option<Self> {
268 match value {
269 0 => Some(Self::Off),
270 1 => Some(Self::On),
271 2 => Some(Self::Toggle),
272 _ => None,
273 }
274 }
275
276 #[must_use]
278 pub const fn value(self) -> u8 {
279 self as u8
280 }
281}
282
283impl ToTlv for StartUpOnOffEnum {
284 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
285 self.value().to_tlv(w, tag)
286 }
287}
288
289impl<'a> FromTlv<'a> for StartUpOnOffEnum {
290 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
291 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
292 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
293 }
294}
295
296bitflags::bitflags! {
297 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
299 pub struct OnOffControlBitmap: u8 {
300 const ACCEPT_ONLY_WHEN_ON = 1 << 0;
302 }
303}
304
305impl ToTlv for OnOffControlBitmap {
306 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
307 self.bits().to_tlv(w, tag)
308 }
309}
310
311impl<'a> FromTlv<'a> for OnOffControlBitmap {
312 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
313 let bits = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
314 Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
315 }
316}
317
318#[derive(Debug, Clone, Copy, PartialEq)]
320pub struct OffWithEffectFields {
321 pub effect_identifier: EffectIdentifierEnum,
323 pub effect_variant: u8,
325}
326
327impl ToTlv for OffWithEffectFields {
328 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
329 w.start_structure(tag)?;
330 self.effect_identifier.to_tlv(w, Tag::Context(0))?;
331 self.effect_variant.to_tlv(w, Tag::Context(1))?;
332 w.end_container()
333 }
334}
335
336impl<'a> FromTlv<'a> for OffWithEffectFields {
337 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
338 if element.value.container() != Some(ContainerKind::Structure) {
339 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
340 }
341 let mut effect_identifier = None;
342 let mut effect_variant = None;
343 loop {
344 let Some(field) = reader.next_element()? else {
345 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
346 };
347 if field.value == Value::EndOfContainer {
348 break;
349 }
350 match field.tag.context() {
351 Some(0) => {
352 effect_identifier = Some(<EffectIdentifierEnum>::from_tlv(reader, &field)?)
353 }
354 Some(1) => effect_variant = Some(<u8>::from_tlv(reader, &field)?),
355 _ => reader.skip_value(&field)?,
359 }
360 }
361 Ok(Self {
362 effect_identifier: effect_identifier
363 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
364 effect_variant: effect_variant
365 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
366 })
367 }
368}
369
370#[derive(Debug, Clone, Copy, PartialEq)]
372pub struct OnWithTimedOffFields {
373 pub on_off_control: OnOffControlBitmap,
375 pub on_time: u16,
377 pub off_wait_time: u16,
379}
380
381impl ToTlv for OnWithTimedOffFields {
382 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
383 w.start_structure(tag)?;
384 self.on_off_control.to_tlv(w, Tag::Context(0))?;
385 self.on_time.to_tlv(w, Tag::Context(1))?;
386 self.off_wait_time.to_tlv(w, Tag::Context(2))?;
387 w.end_container()
388 }
389}
390
391impl<'a> FromTlv<'a> for OnWithTimedOffFields {
392 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
393 if element.value.container() != Some(ContainerKind::Structure) {
394 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
395 }
396 let mut on_off_control = None;
397 let mut on_time = None;
398 let mut off_wait_time = None;
399 loop {
400 let Some(field) = reader.next_element()? else {
401 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
402 };
403 if field.value == Value::EndOfContainer {
404 break;
405 }
406 match field.tag.context() {
407 Some(0) => on_off_control = Some(<OnOffControlBitmap>::from_tlv(reader, &field)?),
408 Some(1) => on_time = Some(<u16>::from_tlv(reader, &field)?),
409 Some(2) => off_wait_time = Some(<u16>::from_tlv(reader, &field)?),
410 _ => reader.skip_value(&field)?,
414 }
415 }
416 Ok(Self {
417 on_off_control: on_off_control
418 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
419 on_time: on_time.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
420 off_wait_time: off_wait_time.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
421 })
422 }
423}
424
425pub const ATTRIBUTES: &[Attribute] = &[
427 Attribute {
428 id: 0x0000,
429 name: "OnOff",
430 kind: "bool",
431 access: Access::read_only(Privilege::View),
432 qualities: AttributeQualities::NON_VOLATILE.union(AttributeQualities::SCENE),
433 reporting: Reporting::OnChange,
434 conform: Conform::MANDATORY,
435 },
436 Attribute {
437 id: 0x4000,
438 name: "GlobalSceneControl",
439 kind: "bool",
440 access: Access::read_only(Privilege::View),
441 qualities: AttributeQualities::empty(),
442 reporting: Reporting::OnChange,
443 conform: Conform {
444 clauses: &[Clause {
445 verdict: Conformance::Mandatory,
446 when: Condition::Feature(0),
447 }],
448 },
449 },
450 Attribute {
451 id: 0x4001,
452 name: "OnTime",
453 kind: "uint16",
454 access: Access::read_write_with(Privilege::View, Privilege::Operate),
455 qualities: AttributeQualities::empty(),
456 reporting: Reporting::OnChange,
457 conform: Conform {
458 clauses: &[Clause {
459 verdict: Conformance::Mandatory,
460 when: Condition::Feature(0),
461 }],
462 },
463 },
464 Attribute {
465 id: 0x4002,
466 name: "OffWaitTime",
467 kind: "uint16",
468 access: Access::read_write_with(Privilege::View, Privilege::Operate),
469 qualities: AttributeQualities::empty(),
470 reporting: Reporting::OnChange,
471 conform: Conform {
472 clauses: &[Clause {
473 verdict: Conformance::Mandatory,
474 when: Condition::Feature(0),
475 }],
476 },
477 },
478 Attribute {
479 id: 0x4003,
480 name: "StartUpOnOff",
481 kind: "StartUpOnOffEnum",
482 access: Access::read_write_with(Privilege::View, Privilege::Manage),
483 qualities: AttributeQualities::NULLABLE.union(AttributeQualities::NON_VOLATILE),
484 reporting: Reporting::OnChange,
485 conform: Conform {
486 clauses: &[Clause {
487 verdict: Conformance::Mandatory,
488 when: Condition::Feature(0),
489 }],
490 },
491 },
492];
493
494pub const COMMANDS: &[Command] = &[
496 Command {
497 id: 0x00,
498 name: "Off",
499 to_server: true,
500 response: None,
501 access: Access::invoke(Privilege::Operate),
502 conform: Conform::MANDATORY,
503 },
504 Command {
505 id: 0x01,
506 name: "On",
507 to_server: true,
508 response: None,
509 access: Access::invoke(Privilege::Operate),
510 conform: Conform {
511 clauses: &[Clause {
512 verdict: Conformance::Mandatory,
513 when: Condition::Not(&Condition::Feature(2)),
514 }],
515 },
516 },
517 Command {
518 id: 0x02,
519 name: "Toggle",
520 to_server: true,
521 response: None,
522 access: Access::invoke(Privilege::Operate),
523 conform: Conform {
524 clauses: &[Clause {
525 verdict: Conformance::Mandatory,
526 when: Condition::Not(&Condition::Feature(2)),
527 }],
528 },
529 },
530 Command {
531 id: 0x40,
532 name: "OffWithEffect",
533 to_server: true,
534 response: None,
535 access: Access::invoke(Privilege::Operate),
536 conform: Conform {
537 clauses: &[Clause {
538 verdict: Conformance::Mandatory,
539 when: Condition::Feature(0),
540 }],
541 },
542 },
543 Command {
544 id: 0x41,
545 name: "OnWithRecallGlobalScene",
546 to_server: true,
547 response: None,
548 access: Access::invoke(Privilege::Operate),
549 conform: Conform {
550 clauses: &[Clause {
551 verdict: Conformance::Mandatory,
552 when: Condition::Feature(0),
553 }],
554 },
555 },
556 Command {
557 id: 0x42,
558 name: "OnWithTimedOff",
559 to_server: true,
560 response: None,
561 access: Access::invoke(Privilege::Operate),
562 conform: Conform {
563 clauses: &[Clause {
564 verdict: Conformance::Mandatory,
565 when: Condition::Feature(0),
566 }],
567 },
568 },
569];
570
571pub const EVENTS: &[Event] = &[];
573
574pub const CLUSTER: Cluster = Cluster {
576 id: ID,
577 name: "On/Off",
578 revision: REVISION,
579 pics: "OO",
580 derived_from: None,
581 features: FEATURES,
582 attributes: ATTRIBUTES,
583 commands: COMMANDS,
584 events: EVENTS,
585};