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 = 0x0104;
28
29pub const REVISION: u16 = 1;
32
33pub const PICS: &str = "CLCTRL";
35
36pub mod feature {
41 pub const POSITIONING: u32 = 1 << 0;
45 pub const MOTION_LATCHING: u32 = 1 << 1;
49 pub const INSTANTANEOUS: u32 = 1 << 2;
53 pub const SPEED: u32 = 1 << 3;
57 pub const VENTILATION: u32 = 1 << 4;
61 pub const PEDESTRIAN: u32 = 1 << 5;
65 pub const CALIBRATION: u32 = 1 << 6;
69 pub const PROTECTION: u32 = 1 << 7;
73 pub const MANUALLY_OPERABLE: u32 = 1 << 8;
77}
78
79pub const FEATURES: &[Feature] = &[
81 Feature {
82 bit: 0,
83 code: "PS",
84 name: "Positioning",
85 conform: Conform::OPTIONAL,
86 },
87 Feature {
88 bit: 1,
89 code: "LT",
90 name: "MotionLatching",
91 conform: Conform::OPTIONAL,
92 },
93 Feature {
94 bit: 2,
95 code: "IS",
96 name: "Instantaneous",
97 conform: Conform::OPTIONAL,
98 },
99 Feature {
100 bit: 3,
101 code: "SP",
102 name: "Speed",
103 conform: Conform {
104 clauses: &[Clause {
105 verdict: Conformance::Optional,
106 when: Condition::All(&[
107 Condition::Feature(0),
108 Condition::Not(&Condition::Feature(2)),
109 ]),
110 }],
111 },
112 },
113 Feature {
114 bit: 4,
115 code: "VT",
116 name: "Ventilation",
117 conform: Conform {
118 clauses: &[Clause {
119 verdict: Conformance::Optional,
120 when: Condition::Feature(0),
121 }],
122 },
123 },
124 Feature {
125 bit: 5,
126 code: "PD",
127 name: "Pedestrian",
128 conform: Conform {
129 clauses: &[Clause {
130 verdict: Conformance::Optional,
131 when: Condition::Feature(0),
132 }],
133 },
134 },
135 Feature {
136 bit: 6,
137 code: "CL",
138 name: "Calibration",
139 conform: Conform {
140 clauses: &[Clause {
141 verdict: Conformance::Optional,
142 when: Condition::Feature(0),
143 }],
144 },
145 },
146 Feature {
147 bit: 7,
148 code: "PT",
149 name: "Protection",
150 conform: Conform::OPTIONAL,
151 },
152 Feature {
153 bit: 8,
154 code: "MO",
155 name: "ManuallyOperable",
156 conform: Conform::OPTIONAL,
157 },
158];
159
160pub mod attribute {
162 use crate::im::AttributeId;
163
164 pub const COUNTDOWN_TIME: AttributeId = 0x00;
166 pub const MAIN_STATE: AttributeId = 0x01;
168 pub const CURRENT_ERROR_LIST: AttributeId = 0x02;
170 pub const OVERALL_CURRENT_STATE: AttributeId = 0x03;
172 pub const OVERALL_TARGET_STATE: AttributeId = 0x04;
174 pub const LATCH_CONTROL_MODES: AttributeId = 0x05;
176}
177
178pub mod command {
180 use crate::im::CommandId;
181
182 pub const STOP: CommandId = 0x00;
184 pub const MOVE_TO: CommandId = 0x01;
186 pub const CALIBRATE: CommandId = 0x02;
188}
189
190pub mod event {
192 use crate::im::EventId;
193
194 pub const OPERATIONAL_ERROR: EventId = 0x00;
196 pub const MOVEMENT_COMPLETED: EventId = 0x01;
198 pub const ENGAGE_STATE_CHANGED: EventId = 0x02;
200 pub const SECURE_STATE_CHANGED: EventId = 0x03;
202}
203
204#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
206#[repr(u8)]
207pub enum ClosureErrorEnum {
208 PhysicallyBlocked = 0,
210 BlockedBySensor = 1,
212 TemperatureLimited = 2,
214 MaintenanceRequired = 3,
216 InternalInterference = 4,
218}
219
220impl ClosureErrorEnum {
221 #[must_use]
223 pub const fn from_value(value: u8) -> Option<Self> {
224 match value {
225 0 => Some(Self::PhysicallyBlocked),
226 1 => Some(Self::BlockedBySensor),
227 2 => Some(Self::TemperatureLimited),
228 3 => Some(Self::MaintenanceRequired),
229 4 => Some(Self::InternalInterference),
230 _ => None,
231 }
232 }
233
234 #[must_use]
236 pub const fn value(self) -> u8 {
237 self as u8
238 }
239}
240
241impl ToTlv for ClosureErrorEnum {
242 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
243 self.value().to_tlv(w, tag)
244 }
245}
246
247impl<'a> FromTlv<'a> for ClosureErrorEnum {
248 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
249 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
250 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
251 }
252}
253
254#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
256#[repr(u8)]
257pub enum CurrentPositionEnum {
258 FullyClosed = 0,
260 FullyOpened = 1,
262 PartiallyOpened = 2,
264 OpenedForPedestrian = 3,
266 OpenedForVentilation = 4,
268 OpenedAtSignature = 5,
270}
271
272impl CurrentPositionEnum {
273 #[must_use]
275 pub const fn from_value(value: u8) -> Option<Self> {
276 match value {
277 0 => Some(Self::FullyClosed),
278 1 => Some(Self::FullyOpened),
279 2 => Some(Self::PartiallyOpened),
280 3 => Some(Self::OpenedForPedestrian),
281 4 => Some(Self::OpenedForVentilation),
282 5 => Some(Self::OpenedAtSignature),
283 _ => None,
284 }
285 }
286
287 #[must_use]
289 pub const fn value(self) -> u8 {
290 self as u8
291 }
292}
293
294impl ToTlv for CurrentPositionEnum {
295 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
296 self.value().to_tlv(w, tag)
297 }
298}
299
300impl<'a> FromTlv<'a> for CurrentPositionEnum {
301 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
302 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
303 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
304 }
305}
306
307#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
309#[repr(u8)]
310pub enum MainStateEnum {
311 Stopped = 0,
313 Moving = 1,
315 WaitingForMotion = 2,
317 Error = 3,
319 Calibrating = 4,
321 Protected = 5,
323 Disengaged = 6,
325 SetupRequired = 7,
327}
328
329impl MainStateEnum {
330 #[must_use]
332 pub const fn from_value(value: u8) -> Option<Self> {
333 match value {
334 0 => Some(Self::Stopped),
335 1 => Some(Self::Moving),
336 2 => Some(Self::WaitingForMotion),
337 3 => Some(Self::Error),
338 4 => Some(Self::Calibrating),
339 5 => Some(Self::Protected),
340 6 => Some(Self::Disengaged),
341 7 => Some(Self::SetupRequired),
342 _ => None,
343 }
344 }
345
346 #[must_use]
348 pub const fn value(self) -> u8 {
349 self as u8
350 }
351}
352
353impl ToTlv for MainStateEnum {
354 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
355 self.value().to_tlv(w, tag)
356 }
357}
358
359impl<'a> FromTlv<'a> for MainStateEnum {
360 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
361 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
362 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
363 }
364}
365
366#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
368#[repr(u8)]
369pub enum TargetPositionEnum {
370 MoveToFullyClosed = 0,
372 MoveToFullyOpen = 1,
374 MoveToPedestrianPosition = 2,
376 MoveToVentilationPosition = 3,
378 MoveToSignaturePosition = 4,
380}
381
382impl TargetPositionEnum {
383 #[must_use]
385 pub const fn from_value(value: u8) -> Option<Self> {
386 match value {
387 0 => Some(Self::MoveToFullyClosed),
388 1 => Some(Self::MoveToFullyOpen),
389 2 => Some(Self::MoveToPedestrianPosition),
390 3 => Some(Self::MoveToVentilationPosition),
391 4 => Some(Self::MoveToSignaturePosition),
392 _ => None,
393 }
394 }
395
396 #[must_use]
398 pub const fn value(self) -> u8 {
399 self as u8
400 }
401}
402
403impl ToTlv for TargetPositionEnum {
404 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
405 self.value().to_tlv(w, tag)
406 }
407}
408
409impl<'a> FromTlv<'a> for TargetPositionEnum {
410 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
411 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
412 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
413 }
414}
415
416bitflags::bitflags! {
417 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
419 pub struct LatchControlModesBitmap: u8 {
420 const REMOTE_LATCHING = 1 << 0;
422 const REMOTE_UNLATCHING = 1 << 1;
424 }
425}
426
427impl ToTlv for LatchControlModesBitmap {
428 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
429 self.bits().to_tlv(w, tag)
430 }
431}
432
433impl<'a> FromTlv<'a> for LatchControlModesBitmap {
434 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
435 let bits = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
436 Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
437 }
438}
439
440#[derive(Debug, Clone, Copy, PartialEq)]
442pub struct OverallCurrentStateStruct {
443 pub position: Option<Nullable<CurrentPositionEnum>>,
445 pub latch: Option<Nullable<bool>>,
447 pub speed: Option<crate::clusters::generated::globals::ThreeLevelAutoEnum>,
449 pub secure_state: Nullable<bool>,
451}
452
453impl ToTlv for OverallCurrentStateStruct {
454 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
455 w.start_structure(tag)?;
456 if let Some(value) = &self.position {
457 value.to_tlv(w, Tag::Context(0))?;
458 }
459 if let Some(value) = &self.latch {
460 value.to_tlv(w, Tag::Context(1))?;
461 }
462 if let Some(value) = &self.speed {
463 value.to_tlv(w, Tag::Context(2))?;
464 }
465 self.secure_state.to_tlv(w, Tag::Context(3))?;
466 w.end_container()
467 }
468}
469
470impl<'a> FromTlv<'a> for OverallCurrentStateStruct {
471 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
472 if element.value.container() != Some(ContainerKind::Structure) {
473 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
474 }
475 let mut position = None;
476 let mut latch = None;
477 let mut speed = None;
478 let mut secure_state = None;
479 loop {
480 let Some(field) = reader.next_element()? else {
481 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
482 };
483 if field.value == Value::EndOfContainer {
484 break;
485 }
486 match field.tag.context() {
487 Some(0) => {
488 position = Some(<Nullable<CurrentPositionEnum>>::from_tlv(reader, &field)?)
489 }
490 Some(1) => latch = Some(<Nullable<bool>>::from_tlv(reader, &field)?),
491 Some(2) => {
492 speed = Some(
493 <crate::clusters::generated::globals::ThreeLevelAutoEnum>::from_tlv(
494 reader, &field,
495 )?,
496 )
497 }
498 Some(3) => secure_state = Some(<Nullable<bool>>::from_tlv(reader, &field)?),
499 _ => reader.skip_value(&field)?,
503 }
504 }
505 Ok(Self {
506 position,
507 latch,
508 speed,
509 secure_state: secure_state.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
510 })
511 }
512}
513
514#[derive(Debug, Clone, Copy, PartialEq)]
516pub struct OverallTargetStateStruct {
517 pub position: Option<Nullable<TargetPositionEnum>>,
519 pub latch: Option<Nullable<bool>>,
521 pub speed: Option<crate::clusters::generated::globals::ThreeLevelAutoEnum>,
523}
524
525impl ToTlv for OverallTargetStateStruct {
526 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
527 w.start_structure(tag)?;
528 if let Some(value) = &self.position {
529 value.to_tlv(w, Tag::Context(0))?;
530 }
531 if let Some(value) = &self.latch {
532 value.to_tlv(w, Tag::Context(1))?;
533 }
534 if let Some(value) = &self.speed {
535 value.to_tlv(w, Tag::Context(2))?;
536 }
537 w.end_container()
538 }
539}
540
541impl<'a> FromTlv<'a> for OverallTargetStateStruct {
542 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
543 if element.value.container() != Some(ContainerKind::Structure) {
544 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
545 }
546 let mut position = None;
547 let mut latch = None;
548 let mut speed = None;
549 loop {
550 let Some(field) = reader.next_element()? else {
551 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
552 };
553 if field.value == Value::EndOfContainer {
554 break;
555 }
556 match field.tag.context() {
557 Some(0) => {
558 position = Some(<Nullable<TargetPositionEnum>>::from_tlv(reader, &field)?)
559 }
560 Some(1) => latch = Some(<Nullable<bool>>::from_tlv(reader, &field)?),
561 Some(2) => {
562 speed = Some(
563 <crate::clusters::generated::globals::ThreeLevelAutoEnum>::from_tlv(
564 reader, &field,
565 )?,
566 )
567 }
568 _ => reader.skip_value(&field)?,
572 }
573 }
574 Ok(Self {
575 position,
576 latch,
577 speed,
578 })
579 }
580}
581
582#[derive(Debug, Clone, Copy, PartialEq)]
584pub struct MoveToFields {
585 pub position: Option<TargetPositionEnum>,
587 pub latch: Option<bool>,
589 pub speed: Option<crate::clusters::generated::globals::ThreeLevelAutoEnum>,
591}
592
593impl ToTlv for MoveToFields {
594 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
595 w.start_structure(tag)?;
596 if let Some(value) = &self.position {
597 value.to_tlv(w, Tag::Context(0))?;
598 }
599 if let Some(value) = &self.latch {
600 value.to_tlv(w, Tag::Context(1))?;
601 }
602 if let Some(value) = &self.speed {
603 value.to_tlv(w, Tag::Context(2))?;
604 }
605 w.end_container()
606 }
607}
608
609impl<'a> FromTlv<'a> for MoveToFields {
610 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
611 if element.value.container() != Some(ContainerKind::Structure) {
612 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
613 }
614 let mut position = None;
615 let mut latch = None;
616 let mut speed = None;
617 loop {
618 let Some(field) = reader.next_element()? else {
619 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
620 };
621 if field.value == Value::EndOfContainer {
622 break;
623 }
624 match field.tag.context() {
625 Some(0) => position = Some(<TargetPositionEnum>::from_tlv(reader, &field)?),
626 Some(1) => latch = Some(<bool>::from_tlv(reader, &field)?),
627 Some(2) => {
628 speed = Some(
629 <crate::clusters::generated::globals::ThreeLevelAutoEnum>::from_tlv(
630 reader, &field,
631 )?,
632 )
633 }
634 _ => reader.skip_value(&field)?,
638 }
639 }
640 Ok(Self {
641 position,
642 latch,
643 speed,
644 })
645 }
646}
647
648pub const ATTRIBUTES: &[Attribute] = &[
650 Attribute {
651 id: 0x0000,
652 name: "CountdownTime",
653 kind: "elapsed-s",
654 access: Access::read_only(Privilege::View),
655 qualities: AttributeQualities::NULLABLE,
656 reporting: Reporting::Quieter,
657 conform: Conform {
658 clauses: &[Clause {
659 verdict: Conformance::Optional,
660 when: Condition::All(&[
661 Condition::Feature(0),
662 Condition::Not(&Condition::Feature(2)),
663 ]),
664 }],
665 },
666 },
667 Attribute {
668 id: 0x0001,
669 name: "MainState",
670 kind: "MainStateEnum",
671 access: Access::read_only(Privilege::View),
672 qualities: AttributeQualities::empty(),
673 reporting: Reporting::OnChange,
674 conform: Conform::MANDATORY,
675 },
676 Attribute {
677 id: 0x0002,
678 name: "CurrentErrorList",
679 kind: "list[ClosureErrorEnum]",
680 access: Access::read_only(Privilege::View),
681 qualities: AttributeQualities::empty(),
682 reporting: Reporting::OnChange,
683 conform: Conform::MANDATORY,
684 },
685 Attribute {
686 id: 0x0003,
687 name: "OverallCurrentState",
688 kind: "OverallCurrentStateStruct",
689 access: Access::read_only(Privilege::View),
690 qualities: AttributeQualities::NULLABLE,
691 reporting: Reporting::OnChange,
692 conform: Conform::MANDATORY,
693 },
694 Attribute {
695 id: 0x0004,
696 name: "OverallTargetState",
697 kind: "OverallTargetStateStruct",
698 access: Access::read_only(Privilege::View),
699 qualities: AttributeQualities::NULLABLE,
700 reporting: Reporting::OnChange,
701 conform: Conform::MANDATORY,
702 },
703 Attribute {
704 id: 0x0005,
705 name: "LatchControlModes",
706 kind: "LatchControlModesBitmap",
707 access: Access::read_only(Privilege::View),
708 qualities: AttributeQualities::FIXED,
709 reporting: Reporting::OnChange,
710 conform: Conform {
711 clauses: &[Clause {
712 verdict: Conformance::Mandatory,
713 when: Condition::Feature(1),
714 }],
715 },
716 },
717];
718
719pub const COMMANDS: &[Command] = &[
721 Command {
722 id: 0x00,
723 name: "Stop",
724 to_server: true,
725 response: None,
726 access: Access::invoke(Privilege::Operate),
727 conform: Conform {
728 clauses: &[Clause {
729 verdict: Conformance::Mandatory,
730 when: Condition::Not(&Condition::Feature(2)),
731 }],
732 },
733 },
734 Command {
735 id: 0x01,
736 name: "MoveTo",
737 to_server: true,
738 response: None,
739 access: Access::invoke(Privilege::Operate).with_qualities(AccessQualities::TIMED),
740 conform: Conform::MANDATORY,
741 },
742 Command {
743 id: 0x02,
744 name: "Calibrate",
745 to_server: true,
746 response: None,
747 access: Access::invoke(Privilege::Manage).with_qualities(AccessQualities::TIMED),
748 conform: Conform {
749 clauses: &[Clause {
750 verdict: Conformance::Mandatory,
751 when: Condition::Feature(6),
752 }],
753 },
754 },
755];
756
757pub const EVENTS: &[Event] = &[
759 Event {
760 id: 0x00,
761 name: "OperationalError",
762 priority: EventPriority::Critical,
763 access: Access::read_only(Privilege::View),
764 conform: Conform::MANDATORY,
765 },
766 Event {
767 id: 0x01,
768 name: "MovementCompleted",
769 priority: EventPriority::Info,
770 access: Access::read_only(Privilege::View),
771 conform: Conform {
772 clauses: &[Clause {
773 verdict: Conformance::Mandatory,
774 when: Condition::Not(&Condition::Feature(2)),
775 }],
776 },
777 },
778 Event {
779 id: 0x02,
780 name: "EngageStateChanged",
781 priority: EventPriority::Info,
782 access: Access::read_only(Privilege::View),
783 conform: Conform {
784 clauses: &[Clause {
785 verdict: Conformance::Mandatory,
786 when: Condition::Feature(8),
787 }],
788 },
789 },
790 Event {
791 id: 0x03,
792 name: "SecureStateChanged",
793 priority: EventPriority::Info,
794 access: Access::read_only(Privilege::View),
795 conform: Conform::MANDATORY,
796 },
797];
798
799pub const CLUSTER: Cluster = Cluster {
801 id: ID,
802 name: "Closure Control",
803 revision: REVISION,
804 pics: "CLCTRL",
805 derived_from: None,
806 features: FEATURES,
807 attributes: ATTRIBUTES,
808 commands: COMMANDS,
809 events: EVENTS,
810};