1#![allow(
5 clippy::all,
6 clippy::pedantic,
7 dead_code,
8 unreachable_pub,
9 unused_imports
10)]
11
12use crate::datatypes::SemanticTagStruct;
13use crate::error::ClusterError;
14use crate::types::Nullable;
15use matter_codec::{ContainerKind, Element, Tag, TlvReader, TlvWriter, Value};
16
17pub const CLUSTER_ID: u32 = 0x002F;
19pub const CLUSTER_REVISION: u16 = 3;
21
22pub mod command_id {}
24
25pub mod attribute_id {
27 pub const STATUS: u32 = 0x0000;
29 pub const ORDER: u32 = 0x0001;
31 pub const DESCRIPTION: u32 = 0x0002;
33 pub const WIRED_ASSESSED_INPUT_VOLTAGE: u32 = 0x0003;
35 pub const WIRED_ASSESSED_INPUT_FREQUENCY: u32 = 0x0004;
37 pub const WIRED_CURRENT_TYPE: u32 = 0x0005;
39 pub const WIRED_ASSESSED_CURRENT: u32 = 0x0006;
41 pub const WIRED_NOMINAL_VOLTAGE: u32 = 0x0007;
43 pub const WIRED_MAXIMUM_CURRENT: u32 = 0x0008;
45 pub const WIRED_PRESENT: u32 = 0x0009;
47 pub const ACTIVE_WIRED_FAULTS: u32 = 0x000A;
49 pub const BAT_VOLTAGE: u32 = 0x000B;
51 pub const BAT_PERCENT_REMAINING: u32 = 0x000C;
53 pub const BAT_TIME_REMAINING: u32 = 0x000D;
55 pub const BAT_CHARGE_LEVEL: u32 = 0x000E;
57 pub const BAT_REPLACEMENT_NEEDED: u32 = 0x000F;
59 pub const BAT_REPLACEABILITY: u32 = 0x0010;
61 pub const BAT_PRESENT: u32 = 0x0011;
63 pub const ACTIVE_BAT_FAULTS: u32 = 0x0012;
65 pub const BAT_REPLACEMENT_DESCRIPTION: u32 = 0x0013;
67 pub const BAT_COMMON_DESIGNATION: u32 = 0x0014;
69 pub const BAT_ANSI_DESIGNATION: u32 = 0x0015;
71 pub const BAT_IEC_DESIGNATION: u32 = 0x0016;
73 pub const BAT_APPROVED_CHEMISTRY: u32 = 0x0017;
75 pub const BAT_CAPACITY: u32 = 0x0018;
77 pub const BAT_QUANTITY: u32 = 0x0019;
79 pub const BAT_CHARGE_STATE: u32 = 0x001A;
81 pub const BAT_TIME_TO_FULL_CHARGE: u32 = 0x001B;
83 pub const BAT_FUNCTIONAL_WHILE_CHARGING: u32 = 0x001C;
85 pub const BAT_CHARGING_CURRENT: u32 = 0x001D;
87 pub const ACTIVE_BAT_CHARGE_FAULTS: u32 = 0x001E;
89 pub const ENDPOINT_LIST: u32 = 0x001F;
91}
92
93bitflags::bitflags! {
94 #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
96 pub struct Feature: u32 {
97 const WIRED = 1 << 0;
99 const BAT = 1 << 1;
101 const RECHG = 1 << 2;
103 const REPLC = 1 << 3;
105 }
106}
107
108#[derive(Copy, Clone, Debug, PartialEq, Eq)]
110pub enum BatApprovedChemistryEnum {
111 Unspecified,
113 Alkaline,
115 LithiumCarbonFluoride,
117 LithiumChromiumOxide,
119 LithiumCopperOxide,
121 LithiumIronDisulfide,
123 LithiumManganeseDioxide,
125 LithiumThionylChloride,
127 Magnesium,
129 MercuryOxide,
131 NickelOxyhydride,
133 SilverOxide,
135 ZincAir,
137 ZincCarbon,
139 ZincChloride,
141 ZincManganeseDioxide,
143 LeadAcid,
145 LithiumCobaltOxide,
147 LithiumIon,
149 LithiumIonPolymer,
151 LithiumIronPhosphate,
153 LithiumSulfur,
155 LithiumTitanate,
157 NickelCadmium,
159 NickelHydrogen,
161 NickelIron,
163 NickelMetalHydride,
165 NickelZinc,
167 SilverZinc,
169 SodiumIon,
171 SodiumSulfur,
173 ZincBromide,
175 ZincCerium,
177 Unknown(u16),
179}
180
181impl BatApprovedChemistryEnum {
182 #[must_use]
184 pub fn from_raw(v: u16) -> Self {
185 match v {
186 0 => Self::Unspecified,
187 1 => Self::Alkaline,
188 2 => Self::LithiumCarbonFluoride,
189 3 => Self::LithiumChromiumOxide,
190 4 => Self::LithiumCopperOxide,
191 5 => Self::LithiumIronDisulfide,
192 6 => Self::LithiumManganeseDioxide,
193 7 => Self::LithiumThionylChloride,
194 8 => Self::Magnesium,
195 9 => Self::MercuryOxide,
196 10 => Self::NickelOxyhydride,
197 11 => Self::SilverOxide,
198 12 => Self::ZincAir,
199 13 => Self::ZincCarbon,
200 14 => Self::ZincChloride,
201 15 => Self::ZincManganeseDioxide,
202 16 => Self::LeadAcid,
203 17 => Self::LithiumCobaltOxide,
204 18 => Self::LithiumIon,
205 19 => Self::LithiumIonPolymer,
206 20 => Self::LithiumIronPhosphate,
207 21 => Self::LithiumSulfur,
208 22 => Self::LithiumTitanate,
209 23 => Self::NickelCadmium,
210 24 => Self::NickelHydrogen,
211 25 => Self::NickelIron,
212 26 => Self::NickelMetalHydride,
213 27 => Self::NickelZinc,
214 28 => Self::SilverZinc,
215 29 => Self::SodiumIon,
216 30 => Self::SodiumSulfur,
217 31 => Self::ZincBromide,
218 32 => Self::ZincCerium,
219 other => Self::Unknown(other),
220 }
221 }
222 #[must_use]
224 pub fn to_raw(self) -> u16 {
225 match self {
226 Self::Unspecified => 0,
227 Self::Alkaline => 1,
228 Self::LithiumCarbonFluoride => 2,
229 Self::LithiumChromiumOxide => 3,
230 Self::LithiumCopperOxide => 4,
231 Self::LithiumIronDisulfide => 5,
232 Self::LithiumManganeseDioxide => 6,
233 Self::LithiumThionylChloride => 7,
234 Self::Magnesium => 8,
235 Self::MercuryOxide => 9,
236 Self::NickelOxyhydride => 10,
237 Self::SilverOxide => 11,
238 Self::ZincAir => 12,
239 Self::ZincCarbon => 13,
240 Self::ZincChloride => 14,
241 Self::ZincManganeseDioxide => 15,
242 Self::LeadAcid => 16,
243 Self::LithiumCobaltOxide => 17,
244 Self::LithiumIon => 18,
245 Self::LithiumIonPolymer => 19,
246 Self::LithiumIronPhosphate => 20,
247 Self::LithiumSulfur => 21,
248 Self::LithiumTitanate => 22,
249 Self::NickelCadmium => 23,
250 Self::NickelHydrogen => 24,
251 Self::NickelIron => 25,
252 Self::NickelMetalHydride => 26,
253 Self::NickelZinc => 27,
254 Self::SilverZinc => 28,
255 Self::SodiumIon => 29,
256 Self::SodiumSulfur => 30,
257 Self::ZincBromide => 31,
258 Self::ZincCerium => 32,
259 Self::Unknown(v) => v,
260 }
261 }
262}
263
264#[derive(Copy, Clone, Debug, PartialEq, Eq)]
266pub enum BatChargeFaultEnum {
267 Unspecified,
269 AmbientTooHot,
271 AmbientTooCold,
273 BatteryTooHot,
275 BatteryTooCold,
277 BatteryAbsent,
279 BatteryOverVoltage,
281 BatteryUnderVoltage,
283 ChargerOverVoltage,
285 ChargerUnderVoltage,
287 SafetyTimeout,
289 Unknown(u8),
291}
292
293impl BatChargeFaultEnum {
294 #[must_use]
296 pub fn from_raw(v: u8) -> Self {
297 match v {
298 0 => Self::Unspecified,
299 1 => Self::AmbientTooHot,
300 2 => Self::AmbientTooCold,
301 3 => Self::BatteryTooHot,
302 4 => Self::BatteryTooCold,
303 5 => Self::BatteryAbsent,
304 6 => Self::BatteryOverVoltage,
305 7 => Self::BatteryUnderVoltage,
306 8 => Self::ChargerOverVoltage,
307 9 => Self::ChargerUnderVoltage,
308 10 => Self::SafetyTimeout,
309 other => Self::Unknown(other),
310 }
311 }
312 #[must_use]
314 pub fn to_raw(self) -> u8 {
315 match self {
316 Self::Unspecified => 0,
317 Self::AmbientTooHot => 1,
318 Self::AmbientTooCold => 2,
319 Self::BatteryTooHot => 3,
320 Self::BatteryTooCold => 4,
321 Self::BatteryAbsent => 5,
322 Self::BatteryOverVoltage => 6,
323 Self::BatteryUnderVoltage => 7,
324 Self::ChargerOverVoltage => 8,
325 Self::ChargerUnderVoltage => 9,
326 Self::SafetyTimeout => 10,
327 Self::Unknown(v) => v,
328 }
329 }
330}
331
332#[derive(Copy, Clone, Debug, PartialEq, Eq)]
334pub enum BatChargeLevelEnum {
335 Ok,
337 Warning,
339 Critical,
341 Unknown(u8),
343}
344
345impl BatChargeLevelEnum {
346 #[must_use]
348 pub fn from_raw(v: u8) -> Self {
349 match v {
350 0 => Self::Ok,
351 1 => Self::Warning,
352 2 => Self::Critical,
353 other => Self::Unknown(other),
354 }
355 }
356 #[must_use]
358 pub fn to_raw(self) -> u8 {
359 match self {
360 Self::Ok => 0,
361 Self::Warning => 1,
362 Self::Critical => 2,
363 Self::Unknown(v) => v,
364 }
365 }
366}
367
368#[derive(Copy, Clone, Debug, PartialEq, Eq)]
370pub enum BatChargeStateEnum {
371 Unknown,
373 IsCharging,
375 IsAtFullCharge,
377 IsNotCharging,
379 Unrecognized(u8),
381}
382
383impl BatChargeStateEnum {
384 #[must_use]
386 pub fn from_raw(v: u8) -> Self {
387 match v {
388 0 => Self::Unknown,
389 1 => Self::IsCharging,
390 2 => Self::IsAtFullCharge,
391 3 => Self::IsNotCharging,
392 other => Self::Unrecognized(other),
393 }
394 }
395 #[must_use]
397 pub fn to_raw(self) -> u8 {
398 match self {
399 Self::Unknown => 0,
400 Self::IsCharging => 1,
401 Self::IsAtFullCharge => 2,
402 Self::IsNotCharging => 3,
403 Self::Unrecognized(v) => v,
404 }
405 }
406}
407
408#[derive(Copy, Clone, Debug, PartialEq, Eq)]
410#[allow(non_camel_case_types)]
411pub enum BatCommonDesignationEnum {
412 Unspecified,
414 Aaa,
416 Aa,
418 C,
420 D,
422 _4V5,
424 _6V0,
426 _9V0,
428 _12Aa,
430 Aaaa,
432 A,
434 B,
436 F,
438 N,
440 No6,
442 SubC,
444 A23,
446 A27,
448 Ba5800,
450 Duplex,
452 _4Sr44,
454 _523,
456 _531,
458 _15V0,
460 _22V5,
462 _30V0,
464 _45V0,
466 _67V5,
468 J,
470 Cr123A,
472 Cr2,
474 _2Cr5,
476 CrP2,
478 CrV3,
480 Sr41,
482 Sr43,
484 Sr44,
486 Sr45,
488 Sr48,
490 Sr54,
492 Sr55,
494 Sr57,
496 Sr58,
498 Sr59,
500 Sr60,
502 Sr63,
504 Sr64,
506 Sr65,
508 Sr66,
510 Sr67,
512 Sr68,
514 Sr69,
516 Sr516,
518 Sr731,
520 Sr712,
522 Lr932,
524 A5,
526 A10,
528 A13,
530 A312,
532 A675,
534 Ac41E,
536 _10180,
538 _10280,
540 _10440,
542 _14250,
544 _14430,
546 _14500,
548 _14650,
550 _15270,
552 _16340,
554 Rcr123A,
556 _17500,
558 _17670,
560 _18350,
562 _18500,
564 _18650,
566 _19670,
568 _25500,
570 _26650,
572 _32600,
574 Unknown(u16),
576}
577
578impl BatCommonDesignationEnum {
579 #[must_use]
581 pub fn from_raw(v: u16) -> Self {
582 match v {
583 0 => Self::Unspecified,
584 1 => Self::Aaa,
585 2 => Self::Aa,
586 3 => Self::C,
587 4 => Self::D,
588 5 => Self::_4V5,
589 6 => Self::_6V0,
590 7 => Self::_9V0,
591 8 => Self::_12Aa,
592 9 => Self::Aaaa,
593 10 => Self::A,
594 11 => Self::B,
595 12 => Self::F,
596 13 => Self::N,
597 14 => Self::No6,
598 15 => Self::SubC,
599 16 => Self::A23,
600 17 => Self::A27,
601 18 => Self::Ba5800,
602 19 => Self::Duplex,
603 20 => Self::_4Sr44,
604 21 => Self::_523,
605 22 => Self::_531,
606 23 => Self::_15V0,
607 24 => Self::_22V5,
608 25 => Self::_30V0,
609 26 => Self::_45V0,
610 27 => Self::_67V5,
611 28 => Self::J,
612 29 => Self::Cr123A,
613 30 => Self::Cr2,
614 31 => Self::_2Cr5,
615 32 => Self::CrP2,
616 33 => Self::CrV3,
617 34 => Self::Sr41,
618 35 => Self::Sr43,
619 36 => Self::Sr44,
620 37 => Self::Sr45,
621 38 => Self::Sr48,
622 39 => Self::Sr54,
623 40 => Self::Sr55,
624 41 => Self::Sr57,
625 42 => Self::Sr58,
626 43 => Self::Sr59,
627 44 => Self::Sr60,
628 45 => Self::Sr63,
629 46 => Self::Sr64,
630 47 => Self::Sr65,
631 48 => Self::Sr66,
632 49 => Self::Sr67,
633 50 => Self::Sr68,
634 51 => Self::Sr69,
635 52 => Self::Sr516,
636 53 => Self::Sr731,
637 54 => Self::Sr712,
638 55 => Self::Lr932,
639 56 => Self::A5,
640 57 => Self::A10,
641 58 => Self::A13,
642 59 => Self::A312,
643 60 => Self::A675,
644 61 => Self::Ac41E,
645 62 => Self::_10180,
646 63 => Self::_10280,
647 64 => Self::_10440,
648 65 => Self::_14250,
649 66 => Self::_14430,
650 67 => Self::_14500,
651 68 => Self::_14650,
652 69 => Self::_15270,
653 70 => Self::_16340,
654 71 => Self::Rcr123A,
655 72 => Self::_17500,
656 73 => Self::_17670,
657 74 => Self::_18350,
658 75 => Self::_18500,
659 76 => Self::_18650,
660 77 => Self::_19670,
661 78 => Self::_25500,
662 79 => Self::_26650,
663 80 => Self::_32600,
664 other => Self::Unknown(other),
665 }
666 }
667 #[must_use]
669 pub fn to_raw(self) -> u16 {
670 match self {
671 Self::Unspecified => 0,
672 Self::Aaa => 1,
673 Self::Aa => 2,
674 Self::C => 3,
675 Self::D => 4,
676 Self::_4V5 => 5,
677 Self::_6V0 => 6,
678 Self::_9V0 => 7,
679 Self::_12Aa => 8,
680 Self::Aaaa => 9,
681 Self::A => 10,
682 Self::B => 11,
683 Self::F => 12,
684 Self::N => 13,
685 Self::No6 => 14,
686 Self::SubC => 15,
687 Self::A23 => 16,
688 Self::A27 => 17,
689 Self::Ba5800 => 18,
690 Self::Duplex => 19,
691 Self::_4Sr44 => 20,
692 Self::_523 => 21,
693 Self::_531 => 22,
694 Self::_15V0 => 23,
695 Self::_22V5 => 24,
696 Self::_30V0 => 25,
697 Self::_45V0 => 26,
698 Self::_67V5 => 27,
699 Self::J => 28,
700 Self::Cr123A => 29,
701 Self::Cr2 => 30,
702 Self::_2Cr5 => 31,
703 Self::CrP2 => 32,
704 Self::CrV3 => 33,
705 Self::Sr41 => 34,
706 Self::Sr43 => 35,
707 Self::Sr44 => 36,
708 Self::Sr45 => 37,
709 Self::Sr48 => 38,
710 Self::Sr54 => 39,
711 Self::Sr55 => 40,
712 Self::Sr57 => 41,
713 Self::Sr58 => 42,
714 Self::Sr59 => 43,
715 Self::Sr60 => 44,
716 Self::Sr63 => 45,
717 Self::Sr64 => 46,
718 Self::Sr65 => 47,
719 Self::Sr66 => 48,
720 Self::Sr67 => 49,
721 Self::Sr68 => 50,
722 Self::Sr69 => 51,
723 Self::Sr516 => 52,
724 Self::Sr731 => 53,
725 Self::Sr712 => 54,
726 Self::Lr932 => 55,
727 Self::A5 => 56,
728 Self::A10 => 57,
729 Self::A13 => 58,
730 Self::A312 => 59,
731 Self::A675 => 60,
732 Self::Ac41E => 61,
733 Self::_10180 => 62,
734 Self::_10280 => 63,
735 Self::_10440 => 64,
736 Self::_14250 => 65,
737 Self::_14430 => 66,
738 Self::_14500 => 67,
739 Self::_14650 => 68,
740 Self::_15270 => 69,
741 Self::_16340 => 70,
742 Self::Rcr123A => 71,
743 Self::_17500 => 72,
744 Self::_17670 => 73,
745 Self::_18350 => 74,
746 Self::_18500 => 75,
747 Self::_18650 => 76,
748 Self::_19670 => 77,
749 Self::_25500 => 78,
750 Self::_26650 => 79,
751 Self::_32600 => 80,
752 Self::Unknown(v) => v,
753 }
754 }
755}
756
757#[derive(Copy, Clone, Debug, PartialEq, Eq)]
759pub enum BatFaultEnum {
760 Unspecified,
762 OverTemp,
764 UnderTemp,
766 Unknown(u8),
768}
769
770impl BatFaultEnum {
771 #[must_use]
773 pub fn from_raw(v: u8) -> Self {
774 match v {
775 0 => Self::Unspecified,
776 1 => Self::OverTemp,
777 2 => Self::UnderTemp,
778 other => Self::Unknown(other),
779 }
780 }
781 #[must_use]
783 pub fn to_raw(self) -> u8 {
784 match self {
785 Self::Unspecified => 0,
786 Self::OverTemp => 1,
787 Self::UnderTemp => 2,
788 Self::Unknown(v) => v,
789 }
790 }
791}
792
793#[derive(Copy, Clone, Debug, PartialEq, Eq)]
795pub enum BatReplaceabilityEnum {
796 Unspecified,
798 NotReplaceable,
800 UserReplaceable,
802 FactoryReplaceable,
804 Unknown(u8),
806}
807
808impl BatReplaceabilityEnum {
809 #[must_use]
811 pub fn from_raw(v: u8) -> Self {
812 match v {
813 0 => Self::Unspecified,
814 1 => Self::NotReplaceable,
815 2 => Self::UserReplaceable,
816 3 => Self::FactoryReplaceable,
817 other => Self::Unknown(other),
818 }
819 }
820 #[must_use]
822 pub fn to_raw(self) -> u8 {
823 match self {
824 Self::Unspecified => 0,
825 Self::NotReplaceable => 1,
826 Self::UserReplaceable => 2,
827 Self::FactoryReplaceable => 3,
828 Self::Unknown(v) => v,
829 }
830 }
831}
832
833#[derive(Copy, Clone, Debug, PartialEq, Eq)]
835pub enum PowerSourceStatusEnum {
836 Unspecified,
838 Active,
840 Standby,
842 Unavailable,
844 Unknown(u8),
846}
847
848impl PowerSourceStatusEnum {
849 #[must_use]
851 pub fn from_raw(v: u8) -> Self {
852 match v {
853 0 => Self::Unspecified,
854 1 => Self::Active,
855 2 => Self::Standby,
856 3 => Self::Unavailable,
857 other => Self::Unknown(other),
858 }
859 }
860 #[must_use]
862 pub fn to_raw(self) -> u8 {
863 match self {
864 Self::Unspecified => 0,
865 Self::Active => 1,
866 Self::Standby => 2,
867 Self::Unavailable => 3,
868 Self::Unknown(v) => v,
869 }
870 }
871}
872
873#[derive(Copy, Clone, Debug, PartialEq, Eq)]
875pub enum WiredCurrentTypeEnum {
876 Ac,
878 Dc,
880 Unknown(u8),
882}
883
884impl WiredCurrentTypeEnum {
885 #[must_use]
887 pub fn from_raw(v: u8) -> Self {
888 match v {
889 0 => Self::Ac,
890 1 => Self::Dc,
891 other => Self::Unknown(other),
892 }
893 }
894 #[must_use]
896 pub fn to_raw(self) -> u8 {
897 match self {
898 Self::Ac => 0,
899 Self::Dc => 1,
900 Self::Unknown(v) => v,
901 }
902 }
903}
904
905#[derive(Copy, Clone, Debug, PartialEq, Eq)]
907pub enum WiredFaultEnum {
908 Unspecified,
910 OverVoltage,
912 UnderVoltage,
914 Unknown(u8),
916}
917
918impl WiredFaultEnum {
919 #[must_use]
921 pub fn from_raw(v: u8) -> Self {
922 match v {
923 0 => Self::Unspecified,
924 1 => Self::OverVoltage,
925 2 => Self::UnderVoltage,
926 other => Self::Unknown(other),
927 }
928 }
929 #[must_use]
931 pub fn to_raw(self) -> u8 {
932 match self {
933 Self::Unspecified => 0,
934 Self::OverVoltage => 1,
935 Self::UnderVoltage => 2,
936 Self::Unknown(v) => v,
937 }
938 }
939}
940
941pub fn decode_status(tlv: &[u8]) -> Result<PowerSourceStatusEnum, ClusterError> {
946 let mut r = TlvReader::new(tlv);
947 match r.next()? {
948 Some(Element::Scalar {
949 value: Value::Uint(v),
950 ..
951 }) => Ok(PowerSourceStatusEnum::from_raw(
952 u8::try_from(v).map_err(|_| ClusterError::InvalidLength("Status"))?,
953 )),
954 _ => Err(ClusterError::UnexpectedType { context: "Status" }),
955 }
956}
957
958pub fn decode_order(tlv: &[u8]) -> Result<u8, ClusterError> {
963 let mut r = TlvReader::new(tlv);
964 match r.next()? {
965 Some(Element::Scalar {
966 value: Value::Uint(v),
967 ..
968 }) => Ok(u8::try_from(v).map_err(|_| ClusterError::InvalidLength("Order"))?),
969 _ => Err(ClusterError::UnexpectedType { context: "Order" }),
970 }
971}
972
973pub fn decode_description(tlv: &[u8]) -> Result<String, ClusterError> {
978 let mut r = TlvReader::new(tlv);
979 match r.next()? {
980 Some(Element::Scalar {
981 value: Value::Utf8(v),
982 ..
983 }) => Ok(v),
984 _ => Err(ClusterError::UnexpectedType {
985 context: "Description",
986 }),
987 }
988}
989
990pub fn decode_wired_assessed_input_voltage(tlv: &[u8]) -> Result<Nullable<u32>, ClusterError> {
995 let mut r = TlvReader::new(tlv);
996 match r.next()? {
997 Some(Element::Scalar {
998 value: Value::Null, ..
999 }) => Ok(Nullable::Null),
1000 Some(Element::Scalar {
1001 value: Value::Uint(v),
1002 ..
1003 }) => Ok(Nullable::Value(u32::try_from(v).map_err(|_| {
1004 ClusterError::InvalidLength("WiredAssessedInputVoltage")
1005 })?)),
1006 _ => Err(ClusterError::UnexpectedType {
1007 context: "WiredAssessedInputVoltage",
1008 }),
1009 }
1010}
1011
1012pub fn decode_wired_assessed_input_frequency(tlv: &[u8]) -> Result<Nullable<u16>, ClusterError> {
1017 let mut r = TlvReader::new(tlv);
1018 match r.next()? {
1019 Some(Element::Scalar {
1020 value: Value::Null, ..
1021 }) => Ok(Nullable::Null),
1022 Some(Element::Scalar {
1023 value: Value::Uint(v),
1024 ..
1025 }) => Ok(Nullable::Value(u16::try_from(v).map_err(|_| {
1026 ClusterError::InvalidLength("WiredAssessedInputFrequency")
1027 })?)),
1028 _ => Err(ClusterError::UnexpectedType {
1029 context: "WiredAssessedInputFrequency",
1030 }),
1031 }
1032}
1033
1034pub fn decode_wired_current_type(tlv: &[u8]) -> Result<WiredCurrentTypeEnum, ClusterError> {
1039 let mut r = TlvReader::new(tlv);
1040 match r.next()? {
1041 Some(Element::Scalar {
1042 value: Value::Uint(v),
1043 ..
1044 }) => Ok(WiredCurrentTypeEnum::from_raw(
1045 u8::try_from(v).map_err(|_| ClusterError::InvalidLength("WiredCurrentType"))?,
1046 )),
1047 _ => Err(ClusterError::UnexpectedType {
1048 context: "WiredCurrentType",
1049 }),
1050 }
1051}
1052
1053pub fn decode_wired_assessed_current(tlv: &[u8]) -> Result<Nullable<u32>, ClusterError> {
1058 let mut r = TlvReader::new(tlv);
1059 match r.next()? {
1060 Some(Element::Scalar {
1061 value: Value::Null, ..
1062 }) => Ok(Nullable::Null),
1063 Some(Element::Scalar {
1064 value: Value::Uint(v),
1065 ..
1066 }) => Ok(Nullable::Value(u32::try_from(v).map_err(|_| {
1067 ClusterError::InvalidLength("WiredAssessedCurrent")
1068 })?)),
1069 _ => Err(ClusterError::UnexpectedType {
1070 context: "WiredAssessedCurrent",
1071 }),
1072 }
1073}
1074
1075pub fn decode_wired_nominal_voltage(tlv: &[u8]) -> Result<u32, ClusterError> {
1080 let mut r = TlvReader::new(tlv);
1081 match r.next()? {
1082 Some(Element::Scalar {
1083 value: Value::Uint(v),
1084 ..
1085 }) => Ok(u32::try_from(v).map_err(|_| ClusterError::InvalidLength("WiredNominalVoltage"))?),
1086 _ => Err(ClusterError::UnexpectedType {
1087 context: "WiredNominalVoltage",
1088 }),
1089 }
1090}
1091
1092pub fn decode_wired_maximum_current(tlv: &[u8]) -> Result<u32, ClusterError> {
1097 let mut r = TlvReader::new(tlv);
1098 match r.next()? {
1099 Some(Element::Scalar {
1100 value: Value::Uint(v),
1101 ..
1102 }) => Ok(u32::try_from(v).map_err(|_| ClusterError::InvalidLength("WiredMaximumCurrent"))?),
1103 _ => Err(ClusterError::UnexpectedType {
1104 context: "WiredMaximumCurrent",
1105 }),
1106 }
1107}
1108
1109pub fn decode_wired_present(tlv: &[u8]) -> Result<bool, ClusterError> {
1114 let mut r = TlvReader::new(tlv);
1115 match r.next()? {
1116 Some(Element::Scalar {
1117 value: Value::Bool(v),
1118 ..
1119 }) => Ok(v),
1120 _ => Err(ClusterError::UnexpectedType {
1121 context: "WiredPresent",
1122 }),
1123 }
1124}
1125
1126pub fn decode_active_wired_faults(tlv: &[u8]) -> Result<Vec<WiredFaultEnum>, ClusterError> {
1131 let mut r = TlvReader::new(tlv);
1132 match r.next()? {
1133 Some(Element::ContainerStart {
1134 kind: ContainerKind::Array,
1135 ..
1136 }) => {}
1137 _ => {
1138 return Err(ClusterError::UnexpectedType {
1139 context: "ActiveWiredFaults",
1140 })
1141 }
1142 }
1143 let r = &mut r;
1144 let mut out = Vec::new();
1145 loop {
1146 match r.next()? {
1147 Some(Element::ContainerEnd) => break,
1148 Some(Element::Scalar {
1149 value: Value::Uint(v),
1150 ..
1151 }) => out.push(WiredFaultEnum::from_raw(
1152 u8::try_from(v).map_err(|_| ClusterError::InvalidLength("ActiveWiredFaults"))?,
1153 )),
1154 None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
1155 Some(Element::ContainerStart { .. }) => r.skip_container()?,
1156 Some(_) => {} }
1158 }
1159 Ok(out)
1160}
1161
1162pub fn decode_bat_voltage(tlv: &[u8]) -> Result<Nullable<u32>, ClusterError> {
1167 let mut r = TlvReader::new(tlv);
1168 match r.next()? {
1169 Some(Element::Scalar {
1170 value: Value::Null, ..
1171 }) => Ok(Nullable::Null),
1172 Some(Element::Scalar {
1173 value: Value::Uint(v),
1174 ..
1175 }) => Ok(Nullable::Value(
1176 u32::try_from(v).map_err(|_| ClusterError::InvalidLength("BatVoltage"))?,
1177 )),
1178 _ => Err(ClusterError::UnexpectedType {
1179 context: "BatVoltage",
1180 }),
1181 }
1182}
1183
1184pub fn decode_bat_percent_remaining(tlv: &[u8]) -> Result<Nullable<u8>, ClusterError> {
1189 let mut r = TlvReader::new(tlv);
1190 match r.next()? {
1191 Some(Element::Scalar {
1192 value: Value::Null, ..
1193 }) => Ok(Nullable::Null),
1194 Some(Element::Scalar {
1195 value: Value::Uint(v),
1196 ..
1197 }) => Ok(Nullable::Value(u8::try_from(v).map_err(|_| {
1198 ClusterError::InvalidLength("BatPercentRemaining")
1199 })?)),
1200 _ => Err(ClusterError::UnexpectedType {
1201 context: "BatPercentRemaining",
1202 }),
1203 }
1204}
1205
1206pub fn decode_bat_time_remaining(tlv: &[u8]) -> Result<Nullable<u32>, ClusterError> {
1211 let mut r = TlvReader::new(tlv);
1212 match r.next()? {
1213 Some(Element::Scalar {
1214 value: Value::Null, ..
1215 }) => Ok(Nullable::Null),
1216 Some(Element::Scalar {
1217 value: Value::Uint(v),
1218 ..
1219 }) => {
1220 Ok(Nullable::Value(u32::try_from(v).map_err(|_| {
1221 ClusterError::InvalidLength("BatTimeRemaining")
1222 })?))
1223 }
1224 _ => Err(ClusterError::UnexpectedType {
1225 context: "BatTimeRemaining",
1226 }),
1227 }
1228}
1229
1230pub fn decode_bat_charge_level(tlv: &[u8]) -> Result<BatChargeLevelEnum, ClusterError> {
1235 let mut r = TlvReader::new(tlv);
1236 match r.next()? {
1237 Some(Element::Scalar {
1238 value: Value::Uint(v),
1239 ..
1240 }) => Ok(BatChargeLevelEnum::from_raw(
1241 u8::try_from(v).map_err(|_| ClusterError::InvalidLength("BatChargeLevel"))?,
1242 )),
1243 _ => Err(ClusterError::UnexpectedType {
1244 context: "BatChargeLevel",
1245 }),
1246 }
1247}
1248
1249pub fn decode_bat_replacement_needed(tlv: &[u8]) -> Result<bool, ClusterError> {
1254 let mut r = TlvReader::new(tlv);
1255 match r.next()? {
1256 Some(Element::Scalar {
1257 value: Value::Bool(v),
1258 ..
1259 }) => Ok(v),
1260 _ => Err(ClusterError::UnexpectedType {
1261 context: "BatReplacementNeeded",
1262 }),
1263 }
1264}
1265
1266pub fn decode_bat_replaceability(tlv: &[u8]) -> Result<BatReplaceabilityEnum, ClusterError> {
1271 let mut r = TlvReader::new(tlv);
1272 match r.next()? {
1273 Some(Element::Scalar {
1274 value: Value::Uint(v),
1275 ..
1276 }) => Ok(BatReplaceabilityEnum::from_raw(
1277 u8::try_from(v).map_err(|_| ClusterError::InvalidLength("BatReplaceability"))?,
1278 )),
1279 _ => Err(ClusterError::UnexpectedType {
1280 context: "BatReplaceability",
1281 }),
1282 }
1283}
1284
1285pub fn decode_bat_present(tlv: &[u8]) -> Result<bool, ClusterError> {
1290 let mut r = TlvReader::new(tlv);
1291 match r.next()? {
1292 Some(Element::Scalar {
1293 value: Value::Bool(v),
1294 ..
1295 }) => Ok(v),
1296 _ => Err(ClusterError::UnexpectedType {
1297 context: "BatPresent",
1298 }),
1299 }
1300}
1301
1302pub fn decode_active_bat_faults(tlv: &[u8]) -> Result<Vec<BatFaultEnum>, ClusterError> {
1307 let mut r = TlvReader::new(tlv);
1308 match r.next()? {
1309 Some(Element::ContainerStart {
1310 kind: ContainerKind::Array,
1311 ..
1312 }) => {}
1313 _ => {
1314 return Err(ClusterError::UnexpectedType {
1315 context: "ActiveBatFaults",
1316 })
1317 }
1318 }
1319 let r = &mut r;
1320 let mut out = Vec::new();
1321 loop {
1322 match r.next()? {
1323 Some(Element::ContainerEnd) => break,
1324 Some(Element::Scalar {
1325 value: Value::Uint(v),
1326 ..
1327 }) => out.push(BatFaultEnum::from_raw(
1328 u8::try_from(v).map_err(|_| ClusterError::InvalidLength("ActiveBatFaults"))?,
1329 )),
1330 None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
1331 Some(Element::ContainerStart { .. }) => r.skip_container()?,
1332 Some(_) => {} }
1334 }
1335 Ok(out)
1336}
1337
1338pub fn decode_bat_replacement_description(tlv: &[u8]) -> Result<String, ClusterError> {
1343 let mut r = TlvReader::new(tlv);
1344 match r.next()? {
1345 Some(Element::Scalar {
1346 value: Value::Utf8(v),
1347 ..
1348 }) => Ok(v),
1349 _ => Err(ClusterError::UnexpectedType {
1350 context: "BatReplacementDescription",
1351 }),
1352 }
1353}
1354
1355pub fn decode_bat_common_designation(tlv: &[u8]) -> Result<BatCommonDesignationEnum, ClusterError> {
1360 let mut r = TlvReader::new(tlv);
1361 match r.next()? {
1362 Some(Element::Scalar {
1363 value: Value::Uint(v),
1364 ..
1365 }) => Ok(BatCommonDesignationEnum::from_raw(
1366 u16::try_from(v).map_err(|_| ClusterError::InvalidLength("BatCommonDesignation"))?,
1367 )),
1368 _ => Err(ClusterError::UnexpectedType {
1369 context: "BatCommonDesignation",
1370 }),
1371 }
1372}
1373
1374pub fn decode_bat_ansi_designation(tlv: &[u8]) -> Result<String, ClusterError> {
1379 let mut r = TlvReader::new(tlv);
1380 match r.next()? {
1381 Some(Element::Scalar {
1382 value: Value::Utf8(v),
1383 ..
1384 }) => Ok(v),
1385 _ => Err(ClusterError::UnexpectedType {
1386 context: "BatAnsiDesignation",
1387 }),
1388 }
1389}
1390
1391pub fn decode_bat_iec_designation(tlv: &[u8]) -> Result<String, ClusterError> {
1396 let mut r = TlvReader::new(tlv);
1397 match r.next()? {
1398 Some(Element::Scalar {
1399 value: Value::Utf8(v),
1400 ..
1401 }) => Ok(v),
1402 _ => Err(ClusterError::UnexpectedType {
1403 context: "BatIecDesignation",
1404 }),
1405 }
1406}
1407
1408pub fn decode_bat_approved_chemistry(tlv: &[u8]) -> Result<BatApprovedChemistryEnum, ClusterError> {
1413 let mut r = TlvReader::new(tlv);
1414 match r.next()? {
1415 Some(Element::Scalar {
1416 value: Value::Uint(v),
1417 ..
1418 }) => Ok(BatApprovedChemistryEnum::from_raw(
1419 u16::try_from(v).map_err(|_| ClusterError::InvalidLength("BatApprovedChemistry"))?,
1420 )),
1421 _ => Err(ClusterError::UnexpectedType {
1422 context: "BatApprovedChemistry",
1423 }),
1424 }
1425}
1426
1427pub fn decode_bat_capacity(tlv: &[u8]) -> Result<u32, ClusterError> {
1432 let mut r = TlvReader::new(tlv);
1433 match r.next()? {
1434 Some(Element::Scalar {
1435 value: Value::Uint(v),
1436 ..
1437 }) => Ok(u32::try_from(v).map_err(|_| ClusterError::InvalidLength("BatCapacity"))?),
1438 _ => Err(ClusterError::UnexpectedType {
1439 context: "BatCapacity",
1440 }),
1441 }
1442}
1443
1444pub fn decode_bat_quantity(tlv: &[u8]) -> Result<u8, ClusterError> {
1449 let mut r = TlvReader::new(tlv);
1450 match r.next()? {
1451 Some(Element::Scalar {
1452 value: Value::Uint(v),
1453 ..
1454 }) => Ok(u8::try_from(v).map_err(|_| ClusterError::InvalidLength("BatQuantity"))?),
1455 _ => Err(ClusterError::UnexpectedType {
1456 context: "BatQuantity",
1457 }),
1458 }
1459}
1460
1461pub fn decode_bat_charge_state(tlv: &[u8]) -> Result<BatChargeStateEnum, ClusterError> {
1466 let mut r = TlvReader::new(tlv);
1467 match r.next()? {
1468 Some(Element::Scalar {
1469 value: Value::Uint(v),
1470 ..
1471 }) => Ok(BatChargeStateEnum::from_raw(
1472 u8::try_from(v).map_err(|_| ClusterError::InvalidLength("BatChargeState"))?,
1473 )),
1474 _ => Err(ClusterError::UnexpectedType {
1475 context: "BatChargeState",
1476 }),
1477 }
1478}
1479
1480pub fn decode_bat_time_to_full_charge(tlv: &[u8]) -> Result<Nullable<u32>, ClusterError> {
1485 let mut r = TlvReader::new(tlv);
1486 match r.next()? {
1487 Some(Element::Scalar {
1488 value: Value::Null, ..
1489 }) => Ok(Nullable::Null),
1490 Some(Element::Scalar {
1491 value: Value::Uint(v),
1492 ..
1493 }) => Ok(Nullable::Value(u32::try_from(v).map_err(|_| {
1494 ClusterError::InvalidLength("BatTimeToFullCharge")
1495 })?)),
1496 _ => Err(ClusterError::UnexpectedType {
1497 context: "BatTimeToFullCharge",
1498 }),
1499 }
1500}
1501
1502pub fn decode_bat_functional_while_charging(tlv: &[u8]) -> Result<bool, ClusterError> {
1507 let mut r = TlvReader::new(tlv);
1508 match r.next()? {
1509 Some(Element::Scalar {
1510 value: Value::Bool(v),
1511 ..
1512 }) => Ok(v),
1513 _ => Err(ClusterError::UnexpectedType {
1514 context: "BatFunctionalWhileCharging",
1515 }),
1516 }
1517}
1518
1519pub fn decode_bat_charging_current(tlv: &[u8]) -> Result<Nullable<u32>, ClusterError> {
1524 let mut r = TlvReader::new(tlv);
1525 match r.next()? {
1526 Some(Element::Scalar {
1527 value: Value::Null, ..
1528 }) => Ok(Nullable::Null),
1529 Some(Element::Scalar {
1530 value: Value::Uint(v),
1531 ..
1532 }) => Ok(Nullable::Value(u32::try_from(v).map_err(|_| {
1533 ClusterError::InvalidLength("BatChargingCurrent")
1534 })?)),
1535 _ => Err(ClusterError::UnexpectedType {
1536 context: "BatChargingCurrent",
1537 }),
1538 }
1539}
1540
1541pub fn decode_active_bat_charge_faults(
1546 tlv: &[u8],
1547) -> Result<Vec<BatChargeFaultEnum>, ClusterError> {
1548 let mut r = TlvReader::new(tlv);
1549 match r.next()? {
1550 Some(Element::ContainerStart {
1551 kind: ContainerKind::Array,
1552 ..
1553 }) => {}
1554 _ => {
1555 return Err(ClusterError::UnexpectedType {
1556 context: "ActiveBatChargeFaults",
1557 })
1558 }
1559 }
1560 let r = &mut r;
1561 let mut out = Vec::new();
1562 loop {
1563 match r.next()? {
1564 Some(Element::ContainerEnd) => break,
1565 Some(Element::Scalar {
1566 value: Value::Uint(v),
1567 ..
1568 }) => out
1569 .push(BatChargeFaultEnum::from_raw(u8::try_from(v).map_err(
1570 |_| ClusterError::InvalidLength("ActiveBatChargeFaults"),
1571 )?)),
1572 None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
1573 Some(Element::ContainerStart { .. }) => r.skip_container()?,
1574 Some(_) => {} }
1576 }
1577 Ok(out)
1578}
1579
1580pub fn decode_endpoint_list(tlv: &[u8]) -> Result<Vec<u16>, ClusterError> {
1585 let mut r = TlvReader::new(tlv);
1586 match r.next()? {
1587 Some(Element::ContainerStart {
1588 kind: ContainerKind::Array,
1589 ..
1590 }) => {}
1591 _ => {
1592 return Err(ClusterError::UnexpectedType {
1593 context: "EndpointList",
1594 })
1595 }
1596 }
1597 let r = &mut r;
1598 let mut out = Vec::new();
1599 loop {
1600 match r.next()? {
1601 Some(Element::ContainerEnd) => break,
1602 Some(Element::Scalar {
1603 value: Value::Uint(v),
1604 ..
1605 }) => {
1606 out.push(u16::try_from(v).map_err(|_| ClusterError::InvalidLength("EndpointList"))?)
1607 }
1608 None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
1609 Some(Element::ContainerStart { .. }) => r.skip_container()?,
1610 Some(_) => {} }
1612 }
1613 Ok(out)
1614}