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 = 0x0102;
28
29pub const REVISION: u16 = 8;
32
33pub const PICS: &str = "WNCV";
35
36pub mod feature {
41 pub const LIFT: u32 = 1 << 0;
45 pub const TILT: u32 = 1 << 1;
49 pub const POSITION_AWARE_LIFT: u32 = 1 << 2;
53 pub const POSITION_AWARE_TILT: u32 = 1 << 4;
57}
58
59pub const FEATURES: &[Feature] = &[
61 Feature {
62 bit: 0,
63 code: "LF",
64 name: "Lift",
65 conform: Conform::OPTIONAL,
66 },
67 Feature {
68 bit: 1,
69 code: "TL",
70 name: "Tilt",
71 conform: Conform::OPTIONAL,
72 },
73 Feature {
74 bit: 2,
75 code: "PA_LF",
76 name: "PositionAwareLift",
77 conform: Conform {
78 clauses: &[Clause {
79 verdict: Conformance::Optional,
80 when: Condition::Feature(0),
81 }],
82 },
83 },
84 Feature {
85 bit: 4,
86 code: "PA_TL",
87 name: "PositionAwareTilt",
88 conform: Conform {
89 clauses: &[Clause {
90 verdict: Conformance::Optional,
91 when: Condition::Feature(1),
92 }],
93 },
94 },
95];
96
97pub mod attribute {
99 use crate::im::AttributeId;
100
101 pub const TYPE: AttributeId = 0x00;
103 pub const NUMBER_OF_ACTUATIONS_LIFT: AttributeId = 0x05;
105 pub const NUMBER_OF_ACTUATIONS_TILT: AttributeId = 0x06;
107 pub const CONFIG_STATUS: AttributeId = 0x07;
109 pub const CURRENT_POSITION_LIFT_PERCENTAGE: AttributeId = 0x08;
111 pub const CURRENT_POSITION_TILT_PERCENTAGE: AttributeId = 0x09;
113 pub const OPERATIONAL_STATUS: AttributeId = 0x0A;
115 pub const TARGET_POSITION_LIFT_PERCENT100_THS: AttributeId = 0x0B;
117 pub const TARGET_POSITION_TILT_PERCENT100_THS: AttributeId = 0x0C;
119 pub const END_PRODUCT_TYPE: AttributeId = 0x0D;
121 pub const CURRENT_POSITION_LIFT_PERCENT100_THS: AttributeId = 0x0E;
123 pub const CURRENT_POSITION_TILT_PERCENT100_THS: AttributeId = 0x0F;
125 pub const MODE: AttributeId = 0x17;
127 pub const SAFETY_STATUS: AttributeId = 0x1A;
129}
130
131pub mod command {
133 use crate::im::CommandId;
134
135 pub const UP_OR_OPEN: CommandId = 0x00;
137 pub const DOWN_OR_CLOSE: CommandId = 0x01;
139 pub const STOP_MOTION: CommandId = 0x02;
141 pub const GO_TO_LIFT_PERCENTAGE: CommandId = 0x05;
143 pub const GO_TO_TILT_PERCENTAGE: CommandId = 0x08;
145}
146
147#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
149#[repr(u8)]
150pub enum EndProductTypeEnum {
151 RollerShade = 0,
153 RomanShade = 1,
155 BalloonShade = 2,
157 WovenWood = 3,
159 PleatedShade = 4,
161 CellularShade = 5,
163 LayeredShade = 6,
165 LayeredShade2D = 7,
167 SheerShade = 8,
169 TiltOnlyInteriorBlind = 9,
171 InteriorBlind = 10,
173 VerticalBlindStripCurtain = 11,
175 InteriorVenetianBlind = 12,
177 ExteriorVenetianBlind = 13,
179 LateralLeftCurtain = 14,
181 LateralRightCurtain = 15,
183 CentralCurtain = 16,
185 RollerShutter = 17,
187 ExteriorVerticalScreen = 18,
189 AwningTerracePatio = 19,
191 AwningVerticalScreen = 20,
193 TiltOnlyPergola = 21,
195 SwingingShutter = 22,
197 SlidingShutter = 23,
199 Unknown = 255,
201}
202
203impl EndProductTypeEnum {
204 #[must_use]
206 pub const fn from_value(value: u8) -> Option<Self> {
207 match value {
208 0 => Some(Self::RollerShade),
209 1 => Some(Self::RomanShade),
210 2 => Some(Self::BalloonShade),
211 3 => Some(Self::WovenWood),
212 4 => Some(Self::PleatedShade),
213 5 => Some(Self::CellularShade),
214 6 => Some(Self::LayeredShade),
215 7 => Some(Self::LayeredShade2D),
216 8 => Some(Self::SheerShade),
217 9 => Some(Self::TiltOnlyInteriorBlind),
218 10 => Some(Self::InteriorBlind),
219 11 => Some(Self::VerticalBlindStripCurtain),
220 12 => Some(Self::InteriorVenetianBlind),
221 13 => Some(Self::ExteriorVenetianBlind),
222 14 => Some(Self::LateralLeftCurtain),
223 15 => Some(Self::LateralRightCurtain),
224 16 => Some(Self::CentralCurtain),
225 17 => Some(Self::RollerShutter),
226 18 => Some(Self::ExteriorVerticalScreen),
227 19 => Some(Self::AwningTerracePatio),
228 20 => Some(Self::AwningVerticalScreen),
229 21 => Some(Self::TiltOnlyPergola),
230 22 => Some(Self::SwingingShutter),
231 23 => Some(Self::SlidingShutter),
232 255 => Some(Self::Unknown),
233 _ => None,
234 }
235 }
236
237 #[must_use]
239 pub const fn value(self) -> u8 {
240 self as u8
241 }
242}
243
244impl ToTlv for EndProductTypeEnum {
245 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
246 self.value().to_tlv(w, tag)
247 }
248}
249
250impl<'a> FromTlv<'a> for EndProductTypeEnum {
251 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
252 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
253 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
254 }
255}
256
257#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
259#[repr(u8)]
260pub enum TypeEnum {
261 RollerShade = 0,
263 RollerShade2Motor = 1,
265 RollerShadeExterior = 2,
267 RollerShadeExterior2Motor = 3,
269 Drapery = 4,
271 Awning = 5,
273 Shutter = 6,
275 TiltBlindTiltOnly = 7,
277 TiltBlindLiftAndTilt = 8,
279 ProjectorScreen = 9,
281 Unknown = 255,
283}
284
285impl TypeEnum {
286 #[must_use]
288 pub const fn from_value(value: u8) -> Option<Self> {
289 match value {
290 0 => Some(Self::RollerShade),
291 1 => Some(Self::RollerShade2Motor),
292 2 => Some(Self::RollerShadeExterior),
293 3 => Some(Self::RollerShadeExterior2Motor),
294 4 => Some(Self::Drapery),
295 5 => Some(Self::Awning),
296 6 => Some(Self::Shutter),
297 7 => Some(Self::TiltBlindTiltOnly),
298 8 => Some(Self::TiltBlindLiftAndTilt),
299 9 => Some(Self::ProjectorScreen),
300 255 => Some(Self::Unknown),
301 _ => None,
302 }
303 }
304
305 #[must_use]
307 pub const fn value(self) -> u8 {
308 self as u8
309 }
310}
311
312impl ToTlv for TypeEnum {
313 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
314 self.value().to_tlv(w, tag)
315 }
316}
317
318impl<'a> FromTlv<'a> for TypeEnum {
319 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
320 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
321 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
322 }
323}
324
325bitflags::bitflags! {
326 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
328 pub struct ConfigStatusBitmap: u8 {
329 const OPERATIONAL = 1 << 0;
331 const ONLINE_RESERVED = 1 << 1;
333 const LIFT_MOVEMENT_REVERSED = 1 << 2;
335 const LIFT_POSITION_AWARE = 1 << 3;
337 const TILT_POSITION_AWARE = 1 << 4;
339 const LIFT_ENCODER_CONTROLLED = 1 << 5;
341 const TILT_ENCODER_CONTROLLED = 1 << 6;
343 }
344}
345
346impl ToTlv for ConfigStatusBitmap {
347 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
348 self.bits().to_tlv(w, tag)
349 }
350}
351
352impl<'a> FromTlv<'a> for ConfigStatusBitmap {
353 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
354 let bits = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
355 Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
356 }
357}
358
359bitflags::bitflags! {
360 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
362 pub struct ModeBitmap: u8 {
363 const MOTOR_DIRECTION_REVERSED = 1 << 0;
365 const CALIBRATION_MODE = 1 << 1;
367 const MAINTENANCE_MODE = 1 << 2;
369 const LED_FEEDBACK = 1 << 3;
371 }
372}
373
374impl ToTlv for ModeBitmap {
375 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
376 self.bits().to_tlv(w, tag)
377 }
378}
379
380impl<'a> FromTlv<'a> for ModeBitmap {
381 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
382 let bits = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
383 Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
384 }
385}
386
387bitflags::bitflags! {
388 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
390 pub struct OperationalStatusBitmap: u8 {
391 }
392}
393
394impl ToTlv for OperationalStatusBitmap {
395 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
396 self.bits().to_tlv(w, tag)
397 }
398}
399
400impl<'a> FromTlv<'a> for OperationalStatusBitmap {
401 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
402 let bits = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
403 Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
404 }
405}
406
407bitflags::bitflags! {
408 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
410 pub struct SafetyStatusBitmap: u16 {
411 const REMOTE_LOCKOUT = 1 << 0;
413 const TAMPER_DETECTION = 1 << 1;
415 const FAILED_COMMUNICATION = 1 << 2;
417 const POSITION_FAILURE = 1 << 3;
419 const THERMAL_PROTECTION = 1 << 4;
421 const OBSTACLE_DETECTED = 1 << 5;
423 const POWER = 1 << 6;
425 const STOP_INPUT = 1 << 7;
427 const MOTOR_JAMMED = 1 << 8;
429 const HARDWARE_FAILURE = 1 << 9;
431 const MANUAL_OPERATION = 1 << 10;
433 const PROTECTION = 1 << 11;
435 }
436}
437
438impl ToTlv for SafetyStatusBitmap {
439 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
440 self.bits().to_tlv(w, tag)
441 }
442}
443
444impl<'a> FromTlv<'a> for SafetyStatusBitmap {
445 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
446 let bits = <u16 as FromTlv<'a>>::from_tlv(reader, element)?;
447 Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
448 }
449}
450
451#[derive(Debug, Clone, Copy, PartialEq)]
453pub struct GoToLiftPercentageFields {
454 pub lift_percent100_ths_value: u16,
456}
457
458impl ToTlv for GoToLiftPercentageFields {
459 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
460 w.start_structure(tag)?;
461 self.lift_percent100_ths_value.to_tlv(w, Tag::Context(0))?;
462 w.end_container()
463 }
464}
465
466impl<'a> FromTlv<'a> for GoToLiftPercentageFields {
467 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
468 if element.value.container() != Some(ContainerKind::Structure) {
469 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
470 }
471 let mut lift_percent100_ths_value = None;
472 loop {
473 let Some(field) = reader.next_element()? else {
474 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
475 };
476 if field.value == Value::EndOfContainer {
477 break;
478 }
479 match field.tag.context() {
480 Some(0) => lift_percent100_ths_value = Some(<u16>::from_tlv(reader, &field)?),
481 _ => reader.skip_value(&field)?,
485 }
486 }
487 Ok(Self {
488 lift_percent100_ths_value: lift_percent100_ths_value
489 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
490 })
491 }
492}
493
494#[derive(Debug, Clone, Copy, PartialEq)]
496pub struct GoToTiltPercentageFields {
497 pub tilt_percent100_ths_value: u16,
499}
500
501impl ToTlv for GoToTiltPercentageFields {
502 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
503 w.start_structure(tag)?;
504 self.tilt_percent100_ths_value.to_tlv(w, Tag::Context(0))?;
505 w.end_container()
506 }
507}
508
509impl<'a> FromTlv<'a> for GoToTiltPercentageFields {
510 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
511 if element.value.container() != Some(ContainerKind::Structure) {
512 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
513 }
514 let mut tilt_percent100_ths_value = None;
515 loop {
516 let Some(field) = reader.next_element()? else {
517 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
518 };
519 if field.value == Value::EndOfContainer {
520 break;
521 }
522 match field.tag.context() {
523 Some(0) => tilt_percent100_ths_value = Some(<u16>::from_tlv(reader, &field)?),
524 _ => reader.skip_value(&field)?,
528 }
529 }
530 Ok(Self {
531 tilt_percent100_ths_value: tilt_percent100_ths_value
532 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
533 })
534 }
535}
536
537pub const ATTRIBUTES: &[Attribute] = &[
539 Attribute {
540 id: 0x0000,
541 name: "Type",
542 kind: "TypeEnum",
543 access: Access::read_only(Privilege::View),
544 qualities: AttributeQualities::FIXED,
545 reporting: Reporting::OnChange,
546 conform: Conform::MANDATORY,
547 },
548 Attribute {
549 id: 0x0005,
550 name: "NumberOfActuationsLift",
551 kind: "uint16",
552 access: Access::read_only(Privilege::View),
553 qualities: AttributeQualities::NON_VOLATILE,
554 reporting: Reporting::OnChange,
555 conform: Conform {
556 clauses: &[Clause {
557 verdict: Conformance::Optional,
558 when: Condition::Feature(0),
559 }],
560 },
561 },
562 Attribute {
563 id: 0x0006,
564 name: "NumberOfActuationsTilt",
565 kind: "uint16",
566 access: Access::read_only(Privilege::View),
567 qualities: AttributeQualities::NON_VOLATILE,
568 reporting: Reporting::OnChange,
569 conform: Conform {
570 clauses: &[Clause {
571 verdict: Conformance::Optional,
572 when: Condition::Feature(1),
573 }],
574 },
575 },
576 Attribute {
577 id: 0x0007,
578 name: "ConfigStatus",
579 kind: "ConfigStatusBitmap",
580 access: Access::read_only(Privilege::View),
581 qualities: AttributeQualities::NON_VOLATILE,
582 reporting: Reporting::OnChange,
583 conform: Conform::MANDATORY,
584 },
585 Attribute {
586 id: 0x0008,
587 name: "CurrentPositionLiftPercentage",
588 kind: "percent",
589 access: Access::read_only(Privilege::View),
590 qualities: AttributeQualities::NULLABLE.union(AttributeQualities::NON_VOLATILE),
591 reporting: Reporting::OnChange,
592 conform: Conform {
593 clauses: &[Clause {
594 verdict: Conformance::Optional,
595 when: Condition::All(&[Condition::Feature(0), Condition::Feature(2)]),
596 }],
597 },
598 },
599 Attribute {
600 id: 0x0009,
601 name: "CurrentPositionTiltPercentage",
602 kind: "percent",
603 access: Access::read_only(Privilege::View),
604 qualities: AttributeQualities::NULLABLE.union(AttributeQualities::NON_VOLATILE),
605 reporting: Reporting::OnChange,
606 conform: Conform {
607 clauses: &[Clause {
608 verdict: Conformance::Optional,
609 when: Condition::All(&[Condition::Feature(1), Condition::Feature(4)]),
610 }],
611 },
612 },
613 Attribute {
614 id: 0x000A,
615 name: "OperationalStatus",
616 kind: "OperationalStatusBitmap",
617 access: Access::read_only(Privilege::View),
618 qualities: AttributeQualities::empty(),
619 reporting: Reporting::OnChange,
620 conform: Conform::MANDATORY,
621 },
622 Attribute {
623 id: 0x000B,
624 name: "TargetPositionLiftPercent100ths",
625 kind: "percent100ths",
626 access: Access::read_only(Privilege::View),
627 qualities: AttributeQualities::NULLABLE,
628 reporting: Reporting::OnChange,
629 conform: Conform {
630 clauses: &[Clause {
631 verdict: Conformance::Mandatory,
632 when: Condition::All(&[Condition::Feature(0), Condition::Feature(2)]),
633 }],
634 },
635 },
636 Attribute {
637 id: 0x000C,
638 name: "TargetPositionTiltPercent100ths",
639 kind: "percent100ths",
640 access: Access::read_only(Privilege::View),
641 qualities: AttributeQualities::NULLABLE,
642 reporting: Reporting::OnChange,
643 conform: Conform {
644 clauses: &[Clause {
645 verdict: Conformance::Mandatory,
646 when: Condition::All(&[Condition::Feature(1), Condition::Feature(4)]),
647 }],
648 },
649 },
650 Attribute {
651 id: 0x000D,
652 name: "EndProductType",
653 kind: "EndProductTypeEnum",
654 access: Access::read_only(Privilege::View),
655 qualities: AttributeQualities::FIXED,
656 reporting: Reporting::OnChange,
657 conform: Conform::MANDATORY,
658 },
659 Attribute {
660 id: 0x000E,
661 name: "CurrentPositionLiftPercent100ths",
662 kind: "percent100ths",
663 access: Access::read_only(Privilege::View),
664 qualities: AttributeQualities::NULLABLE.union(AttributeQualities::NON_VOLATILE),
665 reporting: Reporting::OnChange,
666 conform: Conform {
667 clauses: &[Clause {
668 verdict: Conformance::Mandatory,
669 when: Condition::All(&[Condition::Feature(0), Condition::Feature(2)]),
670 }],
671 },
672 },
673 Attribute {
674 id: 0x000F,
675 name: "CurrentPositionTiltPercent100ths",
676 kind: "percent100ths",
677 access: Access::read_only(Privilege::View),
678 qualities: AttributeQualities::NULLABLE.union(AttributeQualities::NON_VOLATILE),
679 reporting: Reporting::OnChange,
680 conform: Conform {
681 clauses: &[Clause {
682 verdict: Conformance::Mandatory,
683 when: Condition::All(&[Condition::Feature(1), Condition::Feature(4)]),
684 }],
685 },
686 },
687 Attribute {
688 id: 0x0017,
689 name: "Mode",
690 kind: "ModeBitmap",
691 access: Access::read_write_with(Privilege::View, Privilege::Manage),
692 qualities: AttributeQualities::NON_VOLATILE,
693 reporting: Reporting::OnChange,
694 conform: Conform::MANDATORY,
695 },
696 Attribute {
697 id: 0x001A,
698 name: "SafetyStatus",
699 kind: "SafetyStatusBitmap",
700 access: Access::read_only(Privilege::View),
701 qualities: AttributeQualities::empty(),
702 reporting: Reporting::OnChange,
703 conform: Conform::OPTIONAL,
704 },
705];
706
707pub const COMMANDS: &[Command] = &[
709 Command {
710 id: 0x00,
711 name: "UpOrOpen",
712 to_server: true,
713 response: None,
714 access: Access::invoke(Privilege::Operate),
715 conform: Conform::MANDATORY,
716 },
717 Command {
718 id: 0x01,
719 name: "DownOrClose",
720 to_server: true,
721 response: None,
722 access: Access::invoke(Privilege::Operate),
723 conform: Conform::MANDATORY,
724 },
725 Command {
726 id: 0x02,
727 name: "StopMotion",
728 to_server: true,
729 response: None,
730 access: Access::invoke(Privilege::Operate),
731 conform: Conform::MANDATORY,
732 },
733 Command {
734 id: 0x05,
735 name: "GoToLiftPercentage",
736 to_server: true,
737 response: None,
738 access: Access::invoke(Privilege::Operate),
739 conform: Conform {
740 clauses: &[
741 Clause {
742 verdict: Conformance::Mandatory,
743 when: Condition::All(&[Condition::Feature(0), Condition::Feature(2)]),
744 },
745 Clause {
746 verdict: Conformance::Optional,
747 when: Condition::Feature(0),
748 },
749 ],
750 },
751 },
752 Command {
753 id: 0x08,
754 name: "GoToTiltPercentage",
755 to_server: true,
756 response: None,
757 access: Access::invoke(Privilege::Operate),
758 conform: Conform {
759 clauses: &[
760 Clause {
761 verdict: Conformance::Mandatory,
762 when: Condition::All(&[Condition::Feature(1), Condition::Feature(4)]),
763 },
764 Clause {
765 verdict: Conformance::Optional,
766 when: Condition::Feature(1),
767 },
768 ],
769 },
770 },
771];
772
773pub const EVENTS: &[Event] = &[];
775
776pub const CLUSTER: Cluster = Cluster {
778 id: ID,
779 name: "Window Covering",
780 revision: REVISION,
781 pics: "WNCV",
782 derived_from: None,
783 features: FEATURES,
784 attributes: ATTRIBUTES,
785 commands: COMMANDS,
786 events: EVENTS,
787};