#![allow(
clippy::all,
clippy::pedantic,
dead_code,
unreachable_pub,
unused_imports
)]
use crate::datatypes::SemanticTagStruct;
use crate::error::ClusterError;
use crate::types::Nullable;
use matter_codec::{ContainerKind, Element, Tag, TlvReader, TlvWriter, Value};
pub const CLUSTER_ID: u32 = 0x002F;
pub const CLUSTER_REVISION: u16 = 3;
pub mod command_id {}
pub mod attribute_id {
pub const STATUS: u32 = 0x0000;
pub const ORDER: u32 = 0x0001;
pub const DESCRIPTION: u32 = 0x0002;
pub const WIRED_ASSESSED_INPUT_VOLTAGE: u32 = 0x0003;
pub const WIRED_ASSESSED_INPUT_FREQUENCY: u32 = 0x0004;
pub const WIRED_CURRENT_TYPE: u32 = 0x0005;
pub const WIRED_ASSESSED_CURRENT: u32 = 0x0006;
pub const WIRED_NOMINAL_VOLTAGE: u32 = 0x0007;
pub const WIRED_MAXIMUM_CURRENT: u32 = 0x0008;
pub const WIRED_PRESENT: u32 = 0x0009;
pub const ACTIVE_WIRED_FAULTS: u32 = 0x000A;
pub const BAT_VOLTAGE: u32 = 0x000B;
pub const BAT_PERCENT_REMAINING: u32 = 0x000C;
pub const BAT_TIME_REMAINING: u32 = 0x000D;
pub const BAT_CHARGE_LEVEL: u32 = 0x000E;
pub const BAT_REPLACEMENT_NEEDED: u32 = 0x000F;
pub const BAT_REPLACEABILITY: u32 = 0x0010;
pub const BAT_PRESENT: u32 = 0x0011;
pub const ACTIVE_BAT_FAULTS: u32 = 0x0012;
pub const BAT_REPLACEMENT_DESCRIPTION: u32 = 0x0013;
pub const BAT_COMMON_DESIGNATION: u32 = 0x0014;
pub const BAT_ANSI_DESIGNATION: u32 = 0x0015;
pub const BAT_IEC_DESIGNATION: u32 = 0x0016;
pub const BAT_APPROVED_CHEMISTRY: u32 = 0x0017;
pub const BAT_CAPACITY: u32 = 0x0018;
pub const BAT_QUANTITY: u32 = 0x0019;
pub const BAT_CHARGE_STATE: u32 = 0x001A;
pub const BAT_TIME_TO_FULL_CHARGE: u32 = 0x001B;
pub const BAT_FUNCTIONAL_WHILE_CHARGING: u32 = 0x001C;
pub const BAT_CHARGING_CURRENT: u32 = 0x001D;
pub const ACTIVE_BAT_CHARGE_FAULTS: u32 = 0x001E;
pub const ENDPOINT_LIST: u32 = 0x001F;
}
bitflags::bitflags! {
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct Feature: u32 {
const WIRED = 1 << 0;
const BAT = 1 << 1;
const RECHG = 1 << 2;
const REPLC = 1 << 3;
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum BatApprovedChemistryEnum {
Unspecified,
Alkaline,
LithiumCarbonFluoride,
LithiumChromiumOxide,
LithiumCopperOxide,
LithiumIronDisulfide,
LithiumManganeseDioxide,
LithiumThionylChloride,
Magnesium,
MercuryOxide,
NickelOxyhydride,
SilverOxide,
ZincAir,
ZincCarbon,
ZincChloride,
ZincManganeseDioxide,
LeadAcid,
LithiumCobaltOxide,
LithiumIon,
LithiumIonPolymer,
LithiumIronPhosphate,
LithiumSulfur,
LithiumTitanate,
NickelCadmium,
NickelHydrogen,
NickelIron,
NickelMetalHydride,
NickelZinc,
SilverZinc,
SodiumIon,
SodiumSulfur,
ZincBromide,
ZincCerium,
Unknown(u16),
}
impl BatApprovedChemistryEnum {
#[must_use]
pub fn from_raw(v: u16) -> Self {
match v {
0 => Self::Unspecified,
1 => Self::Alkaline,
2 => Self::LithiumCarbonFluoride,
3 => Self::LithiumChromiumOxide,
4 => Self::LithiumCopperOxide,
5 => Self::LithiumIronDisulfide,
6 => Self::LithiumManganeseDioxide,
7 => Self::LithiumThionylChloride,
8 => Self::Magnesium,
9 => Self::MercuryOxide,
10 => Self::NickelOxyhydride,
11 => Self::SilverOxide,
12 => Self::ZincAir,
13 => Self::ZincCarbon,
14 => Self::ZincChloride,
15 => Self::ZincManganeseDioxide,
16 => Self::LeadAcid,
17 => Self::LithiumCobaltOxide,
18 => Self::LithiumIon,
19 => Self::LithiumIonPolymer,
20 => Self::LithiumIronPhosphate,
21 => Self::LithiumSulfur,
22 => Self::LithiumTitanate,
23 => Self::NickelCadmium,
24 => Self::NickelHydrogen,
25 => Self::NickelIron,
26 => Self::NickelMetalHydride,
27 => Self::NickelZinc,
28 => Self::SilverZinc,
29 => Self::SodiumIon,
30 => Self::SodiumSulfur,
31 => Self::ZincBromide,
32 => Self::ZincCerium,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u16 {
match self {
Self::Unspecified => 0,
Self::Alkaline => 1,
Self::LithiumCarbonFluoride => 2,
Self::LithiumChromiumOxide => 3,
Self::LithiumCopperOxide => 4,
Self::LithiumIronDisulfide => 5,
Self::LithiumManganeseDioxide => 6,
Self::LithiumThionylChloride => 7,
Self::Magnesium => 8,
Self::MercuryOxide => 9,
Self::NickelOxyhydride => 10,
Self::SilverOxide => 11,
Self::ZincAir => 12,
Self::ZincCarbon => 13,
Self::ZincChloride => 14,
Self::ZincManganeseDioxide => 15,
Self::LeadAcid => 16,
Self::LithiumCobaltOxide => 17,
Self::LithiumIon => 18,
Self::LithiumIonPolymer => 19,
Self::LithiumIronPhosphate => 20,
Self::LithiumSulfur => 21,
Self::LithiumTitanate => 22,
Self::NickelCadmium => 23,
Self::NickelHydrogen => 24,
Self::NickelIron => 25,
Self::NickelMetalHydride => 26,
Self::NickelZinc => 27,
Self::SilverZinc => 28,
Self::SodiumIon => 29,
Self::SodiumSulfur => 30,
Self::ZincBromide => 31,
Self::ZincCerium => 32,
Self::Unknown(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum BatChargeFaultEnum {
Unspecified,
AmbientTooHot,
AmbientTooCold,
BatteryTooHot,
BatteryTooCold,
BatteryAbsent,
BatteryOverVoltage,
BatteryUnderVoltage,
ChargerOverVoltage,
ChargerUnderVoltage,
SafetyTimeout,
Unknown(u8),
}
impl BatChargeFaultEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Unspecified,
1 => Self::AmbientTooHot,
2 => Self::AmbientTooCold,
3 => Self::BatteryTooHot,
4 => Self::BatteryTooCold,
5 => Self::BatteryAbsent,
6 => Self::BatteryOverVoltage,
7 => Self::BatteryUnderVoltage,
8 => Self::ChargerOverVoltage,
9 => Self::ChargerUnderVoltage,
10 => Self::SafetyTimeout,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Unspecified => 0,
Self::AmbientTooHot => 1,
Self::AmbientTooCold => 2,
Self::BatteryTooHot => 3,
Self::BatteryTooCold => 4,
Self::BatteryAbsent => 5,
Self::BatteryOverVoltage => 6,
Self::BatteryUnderVoltage => 7,
Self::ChargerOverVoltage => 8,
Self::ChargerUnderVoltage => 9,
Self::SafetyTimeout => 10,
Self::Unknown(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum BatChargeLevelEnum {
Ok,
Warning,
Critical,
Unknown(u8),
}
impl BatChargeLevelEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Ok,
1 => Self::Warning,
2 => Self::Critical,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Ok => 0,
Self::Warning => 1,
Self::Critical => 2,
Self::Unknown(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum BatChargeStateEnum {
Unknown,
IsCharging,
IsAtFullCharge,
IsNotCharging,
Unrecognized(u8),
}
impl BatChargeStateEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Unknown,
1 => Self::IsCharging,
2 => Self::IsAtFullCharge,
3 => Self::IsNotCharging,
other => Self::Unrecognized(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Unknown => 0,
Self::IsCharging => 1,
Self::IsAtFullCharge => 2,
Self::IsNotCharging => 3,
Self::Unrecognized(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[allow(non_camel_case_types)]
pub enum BatCommonDesignationEnum {
Unspecified,
Aaa,
Aa,
C,
D,
_4V5,
_6V0,
_9V0,
_12Aa,
Aaaa,
A,
B,
F,
N,
No6,
SubC,
A23,
A27,
Ba5800,
Duplex,
_4Sr44,
_523,
_531,
_15V0,
_22V5,
_30V0,
_45V0,
_67V5,
J,
Cr123A,
Cr2,
_2Cr5,
CrP2,
CrV3,
Sr41,
Sr43,
Sr44,
Sr45,
Sr48,
Sr54,
Sr55,
Sr57,
Sr58,
Sr59,
Sr60,
Sr63,
Sr64,
Sr65,
Sr66,
Sr67,
Sr68,
Sr69,
Sr516,
Sr731,
Sr712,
Lr932,
A5,
A10,
A13,
A312,
A675,
Ac41E,
_10180,
_10280,
_10440,
_14250,
_14430,
_14500,
_14650,
_15270,
_16340,
Rcr123A,
_17500,
_17670,
_18350,
_18500,
_18650,
_19670,
_25500,
_26650,
_32600,
Unknown(u16),
}
impl BatCommonDesignationEnum {
#[must_use]
pub fn from_raw(v: u16) -> Self {
match v {
0 => Self::Unspecified,
1 => Self::Aaa,
2 => Self::Aa,
3 => Self::C,
4 => Self::D,
5 => Self::_4V5,
6 => Self::_6V0,
7 => Self::_9V0,
8 => Self::_12Aa,
9 => Self::Aaaa,
10 => Self::A,
11 => Self::B,
12 => Self::F,
13 => Self::N,
14 => Self::No6,
15 => Self::SubC,
16 => Self::A23,
17 => Self::A27,
18 => Self::Ba5800,
19 => Self::Duplex,
20 => Self::_4Sr44,
21 => Self::_523,
22 => Self::_531,
23 => Self::_15V0,
24 => Self::_22V5,
25 => Self::_30V0,
26 => Self::_45V0,
27 => Self::_67V5,
28 => Self::J,
29 => Self::Cr123A,
30 => Self::Cr2,
31 => Self::_2Cr5,
32 => Self::CrP2,
33 => Self::CrV3,
34 => Self::Sr41,
35 => Self::Sr43,
36 => Self::Sr44,
37 => Self::Sr45,
38 => Self::Sr48,
39 => Self::Sr54,
40 => Self::Sr55,
41 => Self::Sr57,
42 => Self::Sr58,
43 => Self::Sr59,
44 => Self::Sr60,
45 => Self::Sr63,
46 => Self::Sr64,
47 => Self::Sr65,
48 => Self::Sr66,
49 => Self::Sr67,
50 => Self::Sr68,
51 => Self::Sr69,
52 => Self::Sr516,
53 => Self::Sr731,
54 => Self::Sr712,
55 => Self::Lr932,
56 => Self::A5,
57 => Self::A10,
58 => Self::A13,
59 => Self::A312,
60 => Self::A675,
61 => Self::Ac41E,
62 => Self::_10180,
63 => Self::_10280,
64 => Self::_10440,
65 => Self::_14250,
66 => Self::_14430,
67 => Self::_14500,
68 => Self::_14650,
69 => Self::_15270,
70 => Self::_16340,
71 => Self::Rcr123A,
72 => Self::_17500,
73 => Self::_17670,
74 => Self::_18350,
75 => Self::_18500,
76 => Self::_18650,
77 => Self::_19670,
78 => Self::_25500,
79 => Self::_26650,
80 => Self::_32600,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u16 {
match self {
Self::Unspecified => 0,
Self::Aaa => 1,
Self::Aa => 2,
Self::C => 3,
Self::D => 4,
Self::_4V5 => 5,
Self::_6V0 => 6,
Self::_9V0 => 7,
Self::_12Aa => 8,
Self::Aaaa => 9,
Self::A => 10,
Self::B => 11,
Self::F => 12,
Self::N => 13,
Self::No6 => 14,
Self::SubC => 15,
Self::A23 => 16,
Self::A27 => 17,
Self::Ba5800 => 18,
Self::Duplex => 19,
Self::_4Sr44 => 20,
Self::_523 => 21,
Self::_531 => 22,
Self::_15V0 => 23,
Self::_22V5 => 24,
Self::_30V0 => 25,
Self::_45V0 => 26,
Self::_67V5 => 27,
Self::J => 28,
Self::Cr123A => 29,
Self::Cr2 => 30,
Self::_2Cr5 => 31,
Self::CrP2 => 32,
Self::CrV3 => 33,
Self::Sr41 => 34,
Self::Sr43 => 35,
Self::Sr44 => 36,
Self::Sr45 => 37,
Self::Sr48 => 38,
Self::Sr54 => 39,
Self::Sr55 => 40,
Self::Sr57 => 41,
Self::Sr58 => 42,
Self::Sr59 => 43,
Self::Sr60 => 44,
Self::Sr63 => 45,
Self::Sr64 => 46,
Self::Sr65 => 47,
Self::Sr66 => 48,
Self::Sr67 => 49,
Self::Sr68 => 50,
Self::Sr69 => 51,
Self::Sr516 => 52,
Self::Sr731 => 53,
Self::Sr712 => 54,
Self::Lr932 => 55,
Self::A5 => 56,
Self::A10 => 57,
Self::A13 => 58,
Self::A312 => 59,
Self::A675 => 60,
Self::Ac41E => 61,
Self::_10180 => 62,
Self::_10280 => 63,
Self::_10440 => 64,
Self::_14250 => 65,
Self::_14430 => 66,
Self::_14500 => 67,
Self::_14650 => 68,
Self::_15270 => 69,
Self::_16340 => 70,
Self::Rcr123A => 71,
Self::_17500 => 72,
Self::_17670 => 73,
Self::_18350 => 74,
Self::_18500 => 75,
Self::_18650 => 76,
Self::_19670 => 77,
Self::_25500 => 78,
Self::_26650 => 79,
Self::_32600 => 80,
Self::Unknown(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum BatFaultEnum {
Unspecified,
OverTemp,
UnderTemp,
Unknown(u8),
}
impl BatFaultEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Unspecified,
1 => Self::OverTemp,
2 => Self::UnderTemp,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Unspecified => 0,
Self::OverTemp => 1,
Self::UnderTemp => 2,
Self::Unknown(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum BatReplaceabilityEnum {
Unspecified,
NotReplaceable,
UserReplaceable,
FactoryReplaceable,
Unknown(u8),
}
impl BatReplaceabilityEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Unspecified,
1 => Self::NotReplaceable,
2 => Self::UserReplaceable,
3 => Self::FactoryReplaceable,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Unspecified => 0,
Self::NotReplaceable => 1,
Self::UserReplaceable => 2,
Self::FactoryReplaceable => 3,
Self::Unknown(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum PowerSourceStatusEnum {
Unspecified,
Active,
Standby,
Unavailable,
Unknown(u8),
}
impl PowerSourceStatusEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Unspecified,
1 => Self::Active,
2 => Self::Standby,
3 => Self::Unavailable,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Unspecified => 0,
Self::Active => 1,
Self::Standby => 2,
Self::Unavailable => 3,
Self::Unknown(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum WiredCurrentTypeEnum {
Ac,
Dc,
Unknown(u8),
}
impl WiredCurrentTypeEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Ac,
1 => Self::Dc,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Ac => 0,
Self::Dc => 1,
Self::Unknown(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum WiredFaultEnum {
Unspecified,
OverVoltage,
UnderVoltage,
Unknown(u8),
}
impl WiredFaultEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Unspecified,
1 => Self::OverVoltage,
2 => Self::UnderVoltage,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Unspecified => 0,
Self::OverVoltage => 1,
Self::UnderVoltage => 2,
Self::Unknown(v) => v,
}
}
}
pub fn decode_status(tlv: &[u8]) -> Result<PowerSourceStatusEnum, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(PowerSourceStatusEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("Status"))?,
)),
_ => Err(ClusterError::UnexpectedType { context: "Status" }),
}
}
pub fn decode_order(tlv: &[u8]) -> Result<u8, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(u8::try_from(v).map_err(|_| ClusterError::InvalidLength("Order"))?),
_ => Err(ClusterError::UnexpectedType { context: "Order" }),
}
}
pub fn decode_description(tlv: &[u8]) -> Result<String, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Utf8(v),
..
}) => Ok(v),
_ => Err(ClusterError::UnexpectedType {
context: "Description",
}),
}
}
pub fn decode_wired_assessed_input_voltage(tlv: &[u8]) -> Result<Nullable<u32>, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Null, ..
}) => Ok(Nullable::Null),
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(Nullable::Value(u32::try_from(v).map_err(|_| {
ClusterError::InvalidLength("WiredAssessedInputVoltage")
})?)),
_ => Err(ClusterError::UnexpectedType {
context: "WiredAssessedInputVoltage",
}),
}
}
pub fn decode_wired_assessed_input_frequency(tlv: &[u8]) -> Result<Nullable<u16>, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Null, ..
}) => Ok(Nullable::Null),
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(Nullable::Value(u16::try_from(v).map_err(|_| {
ClusterError::InvalidLength("WiredAssessedInputFrequency")
})?)),
_ => Err(ClusterError::UnexpectedType {
context: "WiredAssessedInputFrequency",
}),
}
}
pub fn decode_wired_current_type(tlv: &[u8]) -> Result<WiredCurrentTypeEnum, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(WiredCurrentTypeEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("WiredCurrentType"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "WiredCurrentType",
}),
}
}
pub fn decode_wired_assessed_current(tlv: &[u8]) -> Result<Nullable<u32>, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Null, ..
}) => Ok(Nullable::Null),
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(Nullable::Value(u32::try_from(v).map_err(|_| {
ClusterError::InvalidLength("WiredAssessedCurrent")
})?)),
_ => Err(ClusterError::UnexpectedType {
context: "WiredAssessedCurrent",
}),
}
}
pub fn decode_wired_nominal_voltage(tlv: &[u8]) -> Result<u32, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(u32::try_from(v).map_err(|_| ClusterError::InvalidLength("WiredNominalVoltage"))?),
_ => Err(ClusterError::UnexpectedType {
context: "WiredNominalVoltage",
}),
}
}
pub fn decode_wired_maximum_current(tlv: &[u8]) -> Result<u32, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(u32::try_from(v).map_err(|_| ClusterError::InvalidLength("WiredMaximumCurrent"))?),
_ => Err(ClusterError::UnexpectedType {
context: "WiredMaximumCurrent",
}),
}
}
pub fn decode_wired_present(tlv: &[u8]) -> Result<bool, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Bool(v),
..
}) => Ok(v),
_ => Err(ClusterError::UnexpectedType {
context: "WiredPresent",
}),
}
}
pub fn decode_active_wired_faults(tlv: &[u8]) -> Result<Vec<WiredFaultEnum>, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::ContainerStart {
kind: ContainerKind::Array,
..
}) => {}
_ => {
return Err(ClusterError::UnexpectedType {
context: "ActiveWiredFaults",
})
}
}
let r = &mut r;
let mut out = Vec::new();
loop {
match r.next()? {
Some(Element::ContainerEnd) => break,
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => out.push(WiredFaultEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("ActiveWiredFaults"))?,
)),
None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
Some(Element::ContainerStart { .. }) => r.skip_container()?,
Some(_) => {} }
}
Ok(out)
}
pub fn decode_bat_voltage(tlv: &[u8]) -> Result<Nullable<u32>, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Null, ..
}) => Ok(Nullable::Null),
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(Nullable::Value(
u32::try_from(v).map_err(|_| ClusterError::InvalidLength("BatVoltage"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "BatVoltage",
}),
}
}
pub fn decode_bat_percent_remaining(tlv: &[u8]) -> Result<Nullable<u8>, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Null, ..
}) => Ok(Nullable::Null),
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(Nullable::Value(u8::try_from(v).map_err(|_| {
ClusterError::InvalidLength("BatPercentRemaining")
})?)),
_ => Err(ClusterError::UnexpectedType {
context: "BatPercentRemaining",
}),
}
}
pub fn decode_bat_time_remaining(tlv: &[u8]) -> Result<Nullable<u32>, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Null, ..
}) => Ok(Nullable::Null),
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => {
Ok(Nullable::Value(u32::try_from(v).map_err(|_| {
ClusterError::InvalidLength("BatTimeRemaining")
})?))
}
_ => Err(ClusterError::UnexpectedType {
context: "BatTimeRemaining",
}),
}
}
pub fn decode_bat_charge_level(tlv: &[u8]) -> Result<BatChargeLevelEnum, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(BatChargeLevelEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("BatChargeLevel"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "BatChargeLevel",
}),
}
}
pub fn decode_bat_replacement_needed(tlv: &[u8]) -> Result<bool, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Bool(v),
..
}) => Ok(v),
_ => Err(ClusterError::UnexpectedType {
context: "BatReplacementNeeded",
}),
}
}
pub fn decode_bat_replaceability(tlv: &[u8]) -> Result<BatReplaceabilityEnum, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(BatReplaceabilityEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("BatReplaceability"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "BatReplaceability",
}),
}
}
pub fn decode_bat_present(tlv: &[u8]) -> Result<bool, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Bool(v),
..
}) => Ok(v),
_ => Err(ClusterError::UnexpectedType {
context: "BatPresent",
}),
}
}
pub fn decode_active_bat_faults(tlv: &[u8]) -> Result<Vec<BatFaultEnum>, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::ContainerStart {
kind: ContainerKind::Array,
..
}) => {}
_ => {
return Err(ClusterError::UnexpectedType {
context: "ActiveBatFaults",
})
}
}
let r = &mut r;
let mut out = Vec::new();
loop {
match r.next()? {
Some(Element::ContainerEnd) => break,
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => out.push(BatFaultEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("ActiveBatFaults"))?,
)),
None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
Some(Element::ContainerStart { .. }) => r.skip_container()?,
Some(_) => {} }
}
Ok(out)
}
pub fn decode_bat_replacement_description(tlv: &[u8]) -> Result<String, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Utf8(v),
..
}) => Ok(v),
_ => Err(ClusterError::UnexpectedType {
context: "BatReplacementDescription",
}),
}
}
pub fn decode_bat_common_designation(tlv: &[u8]) -> Result<BatCommonDesignationEnum, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(BatCommonDesignationEnum::from_raw(
u16::try_from(v).map_err(|_| ClusterError::InvalidLength("BatCommonDesignation"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "BatCommonDesignation",
}),
}
}
pub fn decode_bat_ansi_designation(tlv: &[u8]) -> Result<String, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Utf8(v),
..
}) => Ok(v),
_ => Err(ClusterError::UnexpectedType {
context: "BatAnsiDesignation",
}),
}
}
pub fn decode_bat_iec_designation(tlv: &[u8]) -> Result<String, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Utf8(v),
..
}) => Ok(v),
_ => Err(ClusterError::UnexpectedType {
context: "BatIecDesignation",
}),
}
}
pub fn decode_bat_approved_chemistry(tlv: &[u8]) -> Result<BatApprovedChemistryEnum, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(BatApprovedChemistryEnum::from_raw(
u16::try_from(v).map_err(|_| ClusterError::InvalidLength("BatApprovedChemistry"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "BatApprovedChemistry",
}),
}
}
pub fn decode_bat_capacity(tlv: &[u8]) -> Result<u32, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(u32::try_from(v).map_err(|_| ClusterError::InvalidLength("BatCapacity"))?),
_ => Err(ClusterError::UnexpectedType {
context: "BatCapacity",
}),
}
}
pub fn decode_bat_quantity(tlv: &[u8]) -> Result<u8, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(u8::try_from(v).map_err(|_| ClusterError::InvalidLength("BatQuantity"))?),
_ => Err(ClusterError::UnexpectedType {
context: "BatQuantity",
}),
}
}
pub fn decode_bat_charge_state(tlv: &[u8]) -> Result<BatChargeStateEnum, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(BatChargeStateEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("BatChargeState"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "BatChargeState",
}),
}
}
pub fn decode_bat_time_to_full_charge(tlv: &[u8]) -> Result<Nullable<u32>, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Null, ..
}) => Ok(Nullable::Null),
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(Nullable::Value(u32::try_from(v).map_err(|_| {
ClusterError::InvalidLength("BatTimeToFullCharge")
})?)),
_ => Err(ClusterError::UnexpectedType {
context: "BatTimeToFullCharge",
}),
}
}
pub fn decode_bat_functional_while_charging(tlv: &[u8]) -> Result<bool, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Bool(v),
..
}) => Ok(v),
_ => Err(ClusterError::UnexpectedType {
context: "BatFunctionalWhileCharging",
}),
}
}
pub fn decode_bat_charging_current(tlv: &[u8]) -> Result<Nullable<u32>, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Null, ..
}) => Ok(Nullable::Null),
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(Nullable::Value(u32::try_from(v).map_err(|_| {
ClusterError::InvalidLength("BatChargingCurrent")
})?)),
_ => Err(ClusterError::UnexpectedType {
context: "BatChargingCurrent",
}),
}
}
pub fn decode_active_bat_charge_faults(
tlv: &[u8],
) -> Result<Vec<BatChargeFaultEnum>, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::ContainerStart {
kind: ContainerKind::Array,
..
}) => {}
_ => {
return Err(ClusterError::UnexpectedType {
context: "ActiveBatChargeFaults",
})
}
}
let r = &mut r;
let mut out = Vec::new();
loop {
match r.next()? {
Some(Element::ContainerEnd) => break,
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => out
.push(BatChargeFaultEnum::from_raw(u8::try_from(v).map_err(
|_| ClusterError::InvalidLength("ActiveBatChargeFaults"),
)?)),
None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
Some(Element::ContainerStart { .. }) => r.skip_container()?,
Some(_) => {} }
}
Ok(out)
}
pub fn decode_endpoint_list(tlv: &[u8]) -> Result<Vec<u16>, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::ContainerStart {
kind: ContainerKind::Array,
..
}) => {}
_ => {
return Err(ClusterError::UnexpectedType {
context: "EndpointList",
})
}
}
let r = &mut r;
let mut out = Vec::new();
loop {
match r.next()? {
Some(Element::ContainerEnd) => break,
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => {
out.push(u16::try_from(v).map_err(|_| ClusterError::InvalidLength("EndpointList"))?)
}
None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
Some(Element::ContainerStart { .. }) => r.skip_container()?,
Some(_) => {} }
}
Ok(out)
}