Skip to main content

matter_clusters/gen/
power_source.rs

1//! PowerSource cluster (0x002F).
2//! @generated by `cargo xtask codegen` — do not edit.
3
4#![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
17/// Cluster ID.
18pub const CLUSTER_ID: u32 = 0x002F;
19/// Cluster revision.
20pub const CLUSTER_REVISION: u16 = 3;
21
22/// Command IDs (requests and responses).
23pub mod command_id {}
24
25/// Attribute IDs (cluster-specific).
26pub mod attribute_id {
27    /// `Status`.
28    pub const STATUS: u32 = 0x0000;
29    /// `Order`.
30    pub const ORDER: u32 = 0x0001;
31    /// `Description`.
32    pub const DESCRIPTION: u32 = 0x0002;
33    /// `WiredAssessedInputVoltage`.
34    pub const WIRED_ASSESSED_INPUT_VOLTAGE: u32 = 0x0003;
35    /// `WiredAssessedInputFrequency`.
36    pub const WIRED_ASSESSED_INPUT_FREQUENCY: u32 = 0x0004;
37    /// `WiredCurrentType`.
38    pub const WIRED_CURRENT_TYPE: u32 = 0x0005;
39    /// `WiredAssessedCurrent`.
40    pub const WIRED_ASSESSED_CURRENT: u32 = 0x0006;
41    /// `WiredNominalVoltage`.
42    pub const WIRED_NOMINAL_VOLTAGE: u32 = 0x0007;
43    /// `WiredMaximumCurrent`.
44    pub const WIRED_MAXIMUM_CURRENT: u32 = 0x0008;
45    /// `WiredPresent`.
46    pub const WIRED_PRESENT: u32 = 0x0009;
47    /// `ActiveWiredFaults`.
48    pub const ACTIVE_WIRED_FAULTS: u32 = 0x000A;
49    /// `BatVoltage`.
50    pub const BAT_VOLTAGE: u32 = 0x000B;
51    /// `BatPercentRemaining`.
52    pub const BAT_PERCENT_REMAINING: u32 = 0x000C;
53    /// `BatTimeRemaining`.
54    pub const BAT_TIME_REMAINING: u32 = 0x000D;
55    /// `BatChargeLevel`.
56    pub const BAT_CHARGE_LEVEL: u32 = 0x000E;
57    /// `BatReplacementNeeded`.
58    pub const BAT_REPLACEMENT_NEEDED: u32 = 0x000F;
59    /// `BatReplaceability`.
60    pub const BAT_REPLACEABILITY: u32 = 0x0010;
61    /// `BatPresent`.
62    pub const BAT_PRESENT: u32 = 0x0011;
63    /// `ActiveBatFaults`.
64    pub const ACTIVE_BAT_FAULTS: u32 = 0x0012;
65    /// `BatReplacementDescription`.
66    pub const BAT_REPLACEMENT_DESCRIPTION: u32 = 0x0013;
67    /// `BatCommonDesignation`.
68    pub const BAT_COMMON_DESIGNATION: u32 = 0x0014;
69    /// `BatAnsiDesignation`.
70    pub const BAT_ANSI_DESIGNATION: u32 = 0x0015;
71    /// `BatIecDesignation`.
72    pub const BAT_IEC_DESIGNATION: u32 = 0x0016;
73    /// `BatApprovedChemistry`.
74    pub const BAT_APPROVED_CHEMISTRY: u32 = 0x0017;
75    /// `BatCapacity`.
76    pub const BAT_CAPACITY: u32 = 0x0018;
77    /// `BatQuantity`.
78    pub const BAT_QUANTITY: u32 = 0x0019;
79    /// `BatChargeState`.
80    pub const BAT_CHARGE_STATE: u32 = 0x001A;
81    /// `BatTimeToFullCharge`.
82    pub const BAT_TIME_TO_FULL_CHARGE: u32 = 0x001B;
83    /// `BatFunctionalWhileCharging`.
84    pub const BAT_FUNCTIONAL_WHILE_CHARGING: u32 = 0x001C;
85    /// `BatChargingCurrent`.
86    pub const BAT_CHARGING_CURRENT: u32 = 0x001D;
87    /// `ActiveBatChargeFaults`.
88    pub const ACTIVE_BAT_CHARGE_FAULTS: u32 = 0x001E;
89    /// `EndpointList`.
90    pub const ENDPOINT_LIST: u32 = 0x001F;
91}
92
93bitflags::bitflags! {
94    /// `PowerSource` feature bits (FeatureMap).
95    #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
96    pub struct Feature: u32 {
97        /// Wired (WIRED).
98        const WIRED = 1 << 0;
99        /// Battery (BAT).
100        const BAT = 1 << 1;
101        /// Rechargeable (RECHG).
102        const RECHG = 1 << 2;
103        /// Replaceable (REPLC).
104        const REPLC = 1 << 3;
105    }
106}
107
108/// `BatApprovedChemistryEnum` (enum16).
109#[derive(Copy, Clone, Debug, PartialEq, Eq)]
110pub enum BatApprovedChemistryEnum {
111    /// Unspecified = 0.
112    Unspecified,
113    /// Alkaline = 1.
114    Alkaline,
115    /// LithiumCarbonFluoride = 2.
116    LithiumCarbonFluoride,
117    /// LithiumChromiumOxide = 3.
118    LithiumChromiumOxide,
119    /// LithiumCopperOxide = 4.
120    LithiumCopperOxide,
121    /// LithiumIronDisulfide = 5.
122    LithiumIronDisulfide,
123    /// LithiumManganeseDioxide = 6.
124    LithiumManganeseDioxide,
125    /// LithiumThionylChloride = 7.
126    LithiumThionylChloride,
127    /// Magnesium = 8.
128    Magnesium,
129    /// MercuryOxide = 9.
130    MercuryOxide,
131    /// NickelOxyhydride = 10.
132    NickelOxyhydride,
133    /// SilverOxide = 11.
134    SilverOxide,
135    /// ZincAir = 12.
136    ZincAir,
137    /// ZincCarbon = 13.
138    ZincCarbon,
139    /// ZincChloride = 14.
140    ZincChloride,
141    /// ZincManganeseDioxide = 15.
142    ZincManganeseDioxide,
143    /// LeadAcid = 16.
144    LeadAcid,
145    /// LithiumCobaltOxide = 17.
146    LithiumCobaltOxide,
147    /// LithiumIon = 18.
148    LithiumIon,
149    /// LithiumIonPolymer = 19.
150    LithiumIonPolymer,
151    /// LithiumIronPhosphate = 20.
152    LithiumIronPhosphate,
153    /// LithiumSulfur = 21.
154    LithiumSulfur,
155    /// LithiumTitanate = 22.
156    LithiumTitanate,
157    /// NickelCadmium = 23.
158    NickelCadmium,
159    /// NickelHydrogen = 24.
160    NickelHydrogen,
161    /// NickelIron = 25.
162    NickelIron,
163    /// NickelMetalHydride = 26.
164    NickelMetalHydride,
165    /// NickelZinc = 27.
166    NickelZinc,
167    /// SilverZinc = 28.
168    SilverZinc,
169    /// SodiumIon = 29.
170    SodiumIon,
171    /// SodiumSulfur = 30.
172    SodiumSulfur,
173    /// ZincBromide = 31.
174    ZincBromide,
175    /// ZincCerium = 32.
176    ZincCerium,
177    /// A value not known to this codegen revision.
178    Unknown(u16),
179}
180
181impl BatApprovedChemistryEnum {
182    /// Decode from its raw discriminant (unknown → `Unknown`).
183    #[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    /// The raw discriminant.
223    #[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/// `BatChargeFaultEnum` (enum8).
265#[derive(Copy, Clone, Debug, PartialEq, Eq)]
266pub enum BatChargeFaultEnum {
267    /// Unspecified = 0.
268    Unspecified,
269    /// AmbientTooHot = 1.
270    AmbientTooHot,
271    /// AmbientTooCold = 2.
272    AmbientTooCold,
273    /// BatteryTooHot = 3.
274    BatteryTooHot,
275    /// BatteryTooCold = 4.
276    BatteryTooCold,
277    /// BatteryAbsent = 5.
278    BatteryAbsent,
279    /// BatteryOverVoltage = 6.
280    BatteryOverVoltage,
281    /// BatteryUnderVoltage = 7.
282    BatteryUnderVoltage,
283    /// ChargerOverVoltage = 8.
284    ChargerOverVoltage,
285    /// ChargerUnderVoltage = 9.
286    ChargerUnderVoltage,
287    /// SafetyTimeout = 10.
288    SafetyTimeout,
289    /// A value not known to this codegen revision.
290    Unknown(u8),
291}
292
293impl BatChargeFaultEnum {
294    /// Decode from its raw discriminant (unknown → `Unknown`).
295    #[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    /// The raw discriminant.
313    #[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/// `BatChargeLevelEnum` (enum8).
333#[derive(Copy, Clone, Debug, PartialEq, Eq)]
334pub enum BatChargeLevelEnum {
335    /// Ok = 0.
336    Ok,
337    /// Warning = 1.
338    Warning,
339    /// Critical = 2.
340    Critical,
341    /// A value not known to this codegen revision.
342    Unknown(u8),
343}
344
345impl BatChargeLevelEnum {
346    /// Decode from its raw discriminant (unknown → `Unknown`).
347    #[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    /// The raw discriminant.
357    #[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/// `BatChargeStateEnum` (enum8).
369#[derive(Copy, Clone, Debug, PartialEq, Eq)]
370pub enum BatChargeStateEnum {
371    /// Unknown = 0.
372    Unknown,
373    /// IsCharging = 1.
374    IsCharging,
375    /// IsAtFullCharge = 2.
376    IsAtFullCharge,
377    /// IsNotCharging = 3.
378    IsNotCharging,
379    /// A value not known to this codegen revision.
380    Unrecognized(u8),
381}
382
383impl BatChargeStateEnum {
384    /// Decode from its raw discriminant (unknown → `Unrecognized`).
385    #[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    /// The raw discriminant.
396    #[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/// `BatCommonDesignationEnum` (enum16).
409#[derive(Copy, Clone, Debug, PartialEq, Eq)]
410#[allow(non_camel_case_types)]
411pub enum BatCommonDesignationEnum {
412    /// Unspecified = 0.
413    Unspecified,
414    /// Aaa = 1.
415    Aaa,
416    /// Aa = 2.
417    Aa,
418    /// C = 3.
419    C,
420    /// D = 4.
421    D,
422    /// 4V5 = 5.
423    _4V5,
424    /// 6V0 = 6.
425    _6V0,
426    /// 9V0 = 7.
427    _9V0,
428    /// 12Aa = 8.
429    _12Aa,
430    /// Aaaa = 9.
431    Aaaa,
432    /// A = 10.
433    A,
434    /// B = 11.
435    B,
436    /// F = 12.
437    F,
438    /// N = 13.
439    N,
440    /// No6 = 14.
441    No6,
442    /// SubC = 15.
443    SubC,
444    /// A23 = 16.
445    A23,
446    /// A27 = 17.
447    A27,
448    /// Ba5800 = 18.
449    Ba5800,
450    /// Duplex = 19.
451    Duplex,
452    /// 4Sr44 = 20.
453    _4Sr44,
454    /// 523 = 21.
455    _523,
456    /// 531 = 22.
457    _531,
458    /// 15V0 = 23.
459    _15V0,
460    /// 22V5 = 24.
461    _22V5,
462    /// 30V0 = 25.
463    _30V0,
464    /// 45V0 = 26.
465    _45V0,
466    /// 67V5 = 27.
467    _67V5,
468    /// J = 28.
469    J,
470    /// Cr123A = 29.
471    Cr123A,
472    /// Cr2 = 30.
473    Cr2,
474    /// 2Cr5 = 31.
475    _2Cr5,
476    /// CrP2 = 32.
477    CrP2,
478    /// CrV3 = 33.
479    CrV3,
480    /// Sr41 = 34.
481    Sr41,
482    /// Sr43 = 35.
483    Sr43,
484    /// Sr44 = 36.
485    Sr44,
486    /// Sr45 = 37.
487    Sr45,
488    /// Sr48 = 38.
489    Sr48,
490    /// Sr54 = 39.
491    Sr54,
492    /// Sr55 = 40.
493    Sr55,
494    /// Sr57 = 41.
495    Sr57,
496    /// Sr58 = 42.
497    Sr58,
498    /// Sr59 = 43.
499    Sr59,
500    /// Sr60 = 44.
501    Sr60,
502    /// Sr63 = 45.
503    Sr63,
504    /// Sr64 = 46.
505    Sr64,
506    /// Sr65 = 47.
507    Sr65,
508    /// Sr66 = 48.
509    Sr66,
510    /// Sr67 = 49.
511    Sr67,
512    /// Sr68 = 50.
513    Sr68,
514    /// Sr69 = 51.
515    Sr69,
516    /// Sr516 = 52.
517    Sr516,
518    /// Sr731 = 53.
519    Sr731,
520    /// Sr712 = 54.
521    Sr712,
522    /// Lr932 = 55.
523    Lr932,
524    /// A5 = 56.
525    A5,
526    /// A10 = 57.
527    A10,
528    /// A13 = 58.
529    A13,
530    /// A312 = 59.
531    A312,
532    /// A675 = 60.
533    A675,
534    /// Ac41E = 61.
535    Ac41E,
536    /// 10180 = 62.
537    _10180,
538    /// 10280 = 63.
539    _10280,
540    /// 10440 = 64.
541    _10440,
542    /// 14250 = 65.
543    _14250,
544    /// 14430 = 66.
545    _14430,
546    /// 14500 = 67.
547    _14500,
548    /// 14650 = 68.
549    _14650,
550    /// 15270 = 69.
551    _15270,
552    /// 16340 = 70.
553    _16340,
554    /// Rcr123A = 71.
555    Rcr123A,
556    /// 17500 = 72.
557    _17500,
558    /// 17670 = 73.
559    _17670,
560    /// 18350 = 74.
561    _18350,
562    /// 18500 = 75.
563    _18500,
564    /// 18650 = 76.
565    _18650,
566    /// 19670 = 77.
567    _19670,
568    /// 25500 = 78.
569    _25500,
570    /// 26650 = 79.
571    _26650,
572    /// 32600 = 80.
573    _32600,
574    /// A value not known to this codegen revision.
575    Unknown(u16),
576}
577
578impl BatCommonDesignationEnum {
579    /// Decode from its raw discriminant (unknown → `Unknown`).
580    #[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    /// The raw discriminant.
668    #[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/// `BatFaultEnum` (enum8).
758#[derive(Copy, Clone, Debug, PartialEq, Eq)]
759pub enum BatFaultEnum {
760    /// Unspecified = 0.
761    Unspecified,
762    /// OverTemp = 1.
763    OverTemp,
764    /// UnderTemp = 2.
765    UnderTemp,
766    /// A value not known to this codegen revision.
767    Unknown(u8),
768}
769
770impl BatFaultEnum {
771    /// Decode from its raw discriminant (unknown → `Unknown`).
772    #[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    /// The raw discriminant.
782    #[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/// `BatReplaceabilityEnum` (enum8).
794#[derive(Copy, Clone, Debug, PartialEq, Eq)]
795pub enum BatReplaceabilityEnum {
796    /// Unspecified = 0.
797    Unspecified,
798    /// NotReplaceable = 1.
799    NotReplaceable,
800    /// UserReplaceable = 2.
801    UserReplaceable,
802    /// FactoryReplaceable = 3.
803    FactoryReplaceable,
804    /// A value not known to this codegen revision.
805    Unknown(u8),
806}
807
808impl BatReplaceabilityEnum {
809    /// Decode from its raw discriminant (unknown → `Unknown`).
810    #[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    /// The raw discriminant.
821    #[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/// `PowerSourceStatusEnum` (enum8).
834#[derive(Copy, Clone, Debug, PartialEq, Eq)]
835pub enum PowerSourceStatusEnum {
836    /// Unspecified = 0.
837    Unspecified,
838    /// Active = 1.
839    Active,
840    /// Standby = 2.
841    Standby,
842    /// Unavailable = 3.
843    Unavailable,
844    /// A value not known to this codegen revision.
845    Unknown(u8),
846}
847
848impl PowerSourceStatusEnum {
849    /// Decode from its raw discriminant (unknown → `Unknown`).
850    #[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    /// The raw discriminant.
861    #[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/// `WiredCurrentTypeEnum` (enum8).
874#[derive(Copy, Clone, Debug, PartialEq, Eq)]
875pub enum WiredCurrentTypeEnum {
876    /// Ac = 0.
877    Ac,
878    /// Dc = 1.
879    Dc,
880    /// A value not known to this codegen revision.
881    Unknown(u8),
882}
883
884impl WiredCurrentTypeEnum {
885    /// Decode from its raw discriminant (unknown → `Unknown`).
886    #[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    /// The raw discriminant.
895    #[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/// `WiredFaultEnum` (enum8).
906#[derive(Copy, Clone, Debug, PartialEq, Eq)]
907pub enum WiredFaultEnum {
908    /// Unspecified = 0.
909    Unspecified,
910    /// OverVoltage = 1.
911    OverVoltage,
912    /// UnderVoltage = 2.
913    UnderVoltage,
914    /// A value not known to this codegen revision.
915    Unknown(u8),
916}
917
918impl WiredFaultEnum {
919    /// Decode from its raw discriminant (unknown → `Unknown`).
920    #[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    /// The raw discriminant.
930    #[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
941/// Decode the `Status` attribute value.
942///
943/// # Errors
944/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
945pub 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
958/// Decode the `Order` attribute value.
959///
960/// # Errors
961/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
962pub 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
973/// Decode the `Description` attribute value.
974///
975/// # Errors
976/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
977pub 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
990/// Decode the `WiredAssessedInputVoltage` attribute value.
991///
992/// # Errors
993/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
994pub 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
1012/// Decode the `WiredAssessedInputFrequency` attribute value.
1013///
1014/// # Errors
1015/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
1016pub 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
1034/// Decode the `WiredCurrentType` attribute value.
1035///
1036/// # Errors
1037/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
1038pub 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
1053/// Decode the `WiredAssessedCurrent` attribute value.
1054///
1055/// # Errors
1056/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
1057pub 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
1075/// Decode the `WiredNominalVoltage` attribute value.
1076///
1077/// # Errors
1078/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
1079pub 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
1092/// Decode the `WiredMaximumCurrent` attribute value.
1093///
1094/// # Errors
1095/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
1096pub 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
1109/// Decode the `WiredPresent` attribute value.
1110///
1111/// # Errors
1112/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
1113pub 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
1126/// Decode the `ActiveWiredFaults` attribute value.
1127///
1128/// # Errors
1129/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
1130pub 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(_) => {} // skip unknown scalar
1157        }
1158    }
1159    Ok(out)
1160}
1161
1162/// Decode the `BatVoltage` attribute value.
1163///
1164/// # Errors
1165/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
1166pub 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
1184/// Decode the `BatPercentRemaining` attribute value.
1185///
1186/// # Errors
1187/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
1188pub 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
1206/// Decode the `BatTimeRemaining` attribute value.
1207///
1208/// # Errors
1209/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
1210pub 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
1230/// Decode the `BatChargeLevel` attribute value.
1231///
1232/// # Errors
1233/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
1234pub 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
1249/// Decode the `BatReplacementNeeded` attribute value.
1250///
1251/// # Errors
1252/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
1253pub 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
1266/// Decode the `BatReplaceability` attribute value.
1267///
1268/// # Errors
1269/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
1270pub 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
1285/// Decode the `BatPresent` attribute value.
1286///
1287/// # Errors
1288/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
1289pub 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
1302/// Decode the `ActiveBatFaults` attribute value.
1303///
1304/// # Errors
1305/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
1306pub 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(_) => {} // skip unknown scalar
1333        }
1334    }
1335    Ok(out)
1336}
1337
1338/// Decode the `BatReplacementDescription` attribute value.
1339///
1340/// # Errors
1341/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
1342pub 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
1355/// Decode the `BatCommonDesignation` attribute value.
1356///
1357/// # Errors
1358/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
1359pub 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
1374/// Decode the `BatAnsiDesignation` attribute value.
1375///
1376/// # Errors
1377/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
1378pub 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
1391/// Decode the `BatIecDesignation` attribute value.
1392///
1393/// # Errors
1394/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
1395pub 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
1408/// Decode the `BatApprovedChemistry` attribute value.
1409///
1410/// # Errors
1411/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
1412pub 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
1427/// Decode the `BatCapacity` attribute value.
1428///
1429/// # Errors
1430/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
1431pub 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
1444/// Decode the `BatQuantity` attribute value.
1445///
1446/// # Errors
1447/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
1448pub 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
1461/// Decode the `BatChargeState` attribute value.
1462///
1463/// # Errors
1464/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
1465pub 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
1480/// Decode the `BatTimeToFullCharge` attribute value.
1481///
1482/// # Errors
1483/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
1484pub 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
1502/// Decode the `BatFunctionalWhileCharging` attribute value.
1503///
1504/// # Errors
1505/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
1506pub 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
1519/// Decode the `BatChargingCurrent` attribute value.
1520///
1521/// # Errors
1522/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
1523pub 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
1541/// Decode the `ActiveBatChargeFaults` attribute value.
1542///
1543/// # Errors
1544/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
1545pub 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(_) => {} // skip unknown scalar
1575        }
1576    }
1577    Ok(out)
1578}
1579
1580/// Decode the `EndpointList` attribute value.
1581///
1582/// # Errors
1583/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
1584pub 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(_) => {} // skip unknown scalar
1611        }
1612    }
1613    Ok(out)
1614}