#![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 = 0x0201;
pub const CLUSTER_REVISION: u16 = 10;
pub mod command_id {
pub const SETPOINT_RAISE_LOWER: u32 = 0x00;
pub const SET_ACTIVE_SCHEDULE_REQUEST: u32 = 0x05;
pub const SET_ACTIVE_PRESET_REQUEST: u32 = 0x06;
pub const ATOMIC_RESPONSE: u32 = 0xFD;
pub const ATOMIC_REQUEST: u32 = 0xFE;
}
pub mod attribute_id {
pub const LOCAL_TEMPERATURE: u32 = 0x0000;
pub const OUTDOOR_TEMPERATURE: u32 = 0x0001;
pub const OCCUPANCY: u32 = 0x0002;
pub const ABS_MIN_HEAT_SETPOINT_LIMIT: u32 = 0x0003;
pub const ABS_MAX_HEAT_SETPOINT_LIMIT: u32 = 0x0004;
pub const ABS_MIN_COOL_SETPOINT_LIMIT: u32 = 0x0005;
pub const ABS_MAX_COOL_SETPOINT_LIMIT: u32 = 0x0006;
pub const LOCAL_TEMPERATURE_CALIBRATION: u32 = 0x0010;
pub const OCCUPIED_COOLING_SETPOINT: u32 = 0x0011;
pub const OCCUPIED_HEATING_SETPOINT: u32 = 0x0012;
pub const UNOCCUPIED_COOLING_SETPOINT: u32 = 0x0013;
pub const UNOCCUPIED_HEATING_SETPOINT: u32 = 0x0014;
pub const MIN_HEAT_SETPOINT_LIMIT: u32 = 0x0015;
pub const MAX_HEAT_SETPOINT_LIMIT: u32 = 0x0016;
pub const MIN_COOL_SETPOINT_LIMIT: u32 = 0x0017;
pub const MAX_COOL_SETPOINT_LIMIT: u32 = 0x0018;
pub const MIN_SETPOINT_DEAD_BAND: u32 = 0x0019;
pub const REMOTE_SENSING: u32 = 0x001A;
pub const CONTROL_SEQUENCE_OF_OPERATION: u32 = 0x001B;
pub const SYSTEM_MODE: u32 = 0x001C;
pub const THERMOSTAT_RUNNING_MODE: u32 = 0x001E;
pub const TEMPERATURE_SETPOINT_HOLD: u32 = 0x0023;
pub const TEMPERATURE_SETPOINT_HOLD_DURATION: u32 = 0x0024;
pub const THERMOSTAT_RUNNING_STATE: u32 = 0x0029;
pub const SETPOINT_CHANGE_SOURCE: u32 = 0x0030;
pub const SETPOINT_CHANGE_AMOUNT: u32 = 0x0031;
pub const SETPOINT_CHANGE_SOURCE_TIMESTAMP: u32 = 0x0032;
pub const EMERGENCY_HEAT_DELTA: u32 = 0x003A;
pub const AC_TYPE: u32 = 0x0040;
pub const AC_CAPACITY: u32 = 0x0041;
pub const AC_REFRIGERANT_TYPE: u32 = 0x0042;
pub const AC_COMPRESSOR_TYPE: u32 = 0x0043;
pub const AC_ERROR_CODE: u32 = 0x0044;
pub const AC_LOUVER_POSITION: u32 = 0x0045;
pub const AC_COIL_TEMPERATURE: u32 = 0x0046;
pub const AC_CAPACITY_FORMAT: u32 = 0x0047;
pub const PRESET_TYPES: u32 = 0x0048;
pub const SCHEDULE_TYPES: u32 = 0x0049;
pub const NUMBER_OF_PRESETS: u32 = 0x004A;
pub const NUMBER_OF_SCHEDULES: u32 = 0x004B;
pub const NUMBER_OF_SCHEDULE_TRANSITIONS: u32 = 0x004C;
pub const NUMBER_OF_SCHEDULE_TRANSITION_PER_DAY: u32 = 0x004D;
pub const ACTIVE_PRESET_HANDLE: u32 = 0x004E;
pub const ACTIVE_SCHEDULE_HANDLE: u32 = 0x004F;
pub const PRESETS: u32 = 0x0050;
pub const SCHEDULES: u32 = 0x0051;
pub const SETPOINT_HOLD_EXPIRY_TIMESTAMP: u32 = 0x0052;
}
bitflags::bitflags! {
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct Feature: u32 {
const HEAT = 1 << 0;
const COOL = 1 << 1;
const OCC = 1 << 2;
const SB = 1 << 4;
const AUTO = 1 << 5;
const LTNE = 1 << 6;
const MSCH = 1 << 7;
const PRES = 1 << 8;
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ACCapacityFormatEnum {
BtUh,
Unknown(u8),
}
impl ACCapacityFormatEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::BtUh,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::BtUh => 0,
Self::Unknown(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ACCompressorTypeEnum {
Unknown,
T1,
T2,
T3,
Unrecognized(u8),
}
impl ACCompressorTypeEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Unknown,
1 => Self::T1,
2 => Self::T2,
3 => Self::T3,
other => Self::Unrecognized(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Unknown => 0,
Self::T1 => 1,
Self::T2 => 2,
Self::T3 => 3,
Self::Unrecognized(v) => v,
}
}
}
bitflags::bitflags! {
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct ACErrorCodeBitmap: u32 {
const COMPRESSOR_FAIL = 1 << 0;
const ROOM_SENSOR_FAIL = 1 << 1;
const OUTDOOR_SENSOR_FAIL = 1 << 2;
const COIL_SENSOR_FAIL = 1 << 3;
const FAN_FAIL = 1 << 4;
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ACLouverPositionEnum {
Closed,
Open,
Quarter,
Half,
ThreeQuarters,
Unknown(u8),
}
impl ACLouverPositionEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
1 => Self::Closed,
2 => Self::Open,
3 => Self::Quarter,
4 => Self::Half,
5 => Self::ThreeQuarters,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Closed => 1,
Self::Open => 2,
Self::Quarter => 3,
Self::Half => 4,
Self::ThreeQuarters => 5,
Self::Unknown(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ACRefrigerantTypeEnum {
Unknown,
R22,
R410A,
R407C,
Unrecognized(u8),
}
impl ACRefrigerantTypeEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Unknown,
1 => Self::R22,
2 => Self::R410A,
3 => Self::R407C,
other => Self::Unrecognized(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Unknown => 0,
Self::R22 => 1,
Self::R410A => 2,
Self::R407C => 3,
Self::Unrecognized(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ACTypeEnum {
Unknown,
CoolingFixed,
HeatPumpFixed,
CoolingInverter,
HeatPumpInverter,
Unrecognized(u8),
}
impl ACTypeEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Unknown,
1 => Self::CoolingFixed,
2 => Self::HeatPumpFixed,
3 => Self::CoolingInverter,
4 => Self::HeatPumpInverter,
other => Self::Unrecognized(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Unknown => 0,
Self::CoolingFixed => 1,
Self::HeatPumpFixed => 2,
Self::CoolingInverter => 3,
Self::HeatPumpInverter => 4,
Self::Unrecognized(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ControlSequenceOfOperationEnum {
CoolingOnly,
CoolingWithReheat,
HeatingOnly,
HeatingWithReheat,
CoolingAndHeating,
CoolingAndHeatingWithReheat,
Unknown(u8),
}
impl ControlSequenceOfOperationEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::CoolingOnly,
1 => Self::CoolingWithReheat,
2 => Self::HeatingOnly,
3 => Self::HeatingWithReheat,
4 => Self::CoolingAndHeating,
5 => Self::CoolingAndHeatingWithReheat,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::CoolingOnly => 0,
Self::CoolingWithReheat => 1,
Self::HeatingOnly => 2,
Self::HeatingWithReheat => 3,
Self::CoolingAndHeating => 4,
Self::CoolingAndHeatingWithReheat => 5,
Self::Unknown(v) => v,
}
}
}
bitflags::bitflags! {
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct OccupancyBitmap: u8 {
const OCCUPIED = 1 << 0;
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum PresetScenarioEnum {
Occupied,
Unoccupied,
Sleep,
Wake,
Vacation,
GoingToSleep,
UserDefined,
Unknown(u8),
}
impl PresetScenarioEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
1 => Self::Occupied,
2 => Self::Unoccupied,
3 => Self::Sleep,
4 => Self::Wake,
5 => Self::Vacation,
6 => Self::GoingToSleep,
254 => Self::UserDefined,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Occupied => 1,
Self::Unoccupied => 2,
Self::Sleep => 3,
Self::Wake => 4,
Self::Vacation => 5,
Self::GoingToSleep => 6,
Self::UserDefined => 254,
Self::Unknown(v) => v,
}
}
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub struct PresetStruct {
pub preset_handle: Nullable<Vec<u8>>,
pub preset_scenario: PresetScenarioEnum,
pub name: Option<Nullable<String>>,
pub cooling_setpoint: Option<i16>,
pub heating_setpoint: Option<i16>,
pub built_in: Nullable<bool>,
}
bitflags::bitflags! {
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct PresetTypeFeaturesBitmap: u16 {
const AUTOMATIC = 1 << 0;
const SUPPORTS_NAMES = 1 << 1;
}
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub struct PresetTypeStruct {
pub preset_scenario: PresetScenarioEnum,
pub number_of_presets: u8,
pub preset_type_features: PresetTypeFeaturesBitmap,
}
bitflags::bitflags! {
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct RelayStateBitmap: u16 {
const HEAT = 1 << 0;
const COOL = 1 << 1;
const FAN = 1 << 2;
const HEAT_STAGE2 = 1 << 3;
const COOL_STAGE2 = 1 << 4;
const FAN_STAGE2 = 1 << 5;
const FAN_STAGE3 = 1 << 6;
}
}
bitflags::bitflags! {
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct RemoteSensingBitmap: u8 {
const LOCAL_TEMPERATURE = 1 << 0;
const OUTDOOR_TEMPERATURE = 1 << 1;
const OCCUPANCY = 1 << 2;
}
}
bitflags::bitflags! {
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct ScheduleDayOfWeekBitmap: u8 {
const SUNDAY = 1 << 0;
const MONDAY = 1 << 1;
const TUESDAY = 1 << 2;
const WEDNESDAY = 1 << 3;
const THURSDAY = 1 << 4;
const FRIDAY = 1 << 5;
const SATURDAY = 1 << 6;
const AWAY = 1 << 7;
}
}
bitflags::bitflags! {
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct ScheduleModeBitmap: u8 {
const HEAT_SETPOINT_PRESENT = 1 << 0;
const COOL_SETPOINT_PRESENT = 1 << 1;
}
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub struct ScheduleStruct {
pub schedule_handle: Nullable<Vec<u8>>,
pub system_mode: SystemModeEnum,
pub name: Option<String>,
pub preset_handle: Option<Vec<u8>>,
pub transitions: Vec<ScheduleTransitionStruct>,
pub built_in: Nullable<bool>,
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub struct ScheduleTransitionStruct {
pub day_of_week: ScheduleDayOfWeekBitmap,
pub transition_time: u16,
pub preset_handle: Option<Vec<u8>>,
pub system_mode: Option<SystemModeEnum>,
pub cooling_setpoint: Option<i16>,
pub heating_setpoint: Option<i16>,
}
bitflags::bitflags! {
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct ScheduleTypeFeaturesBitmap: u16 {
const SUPPORTS_PRESETS = 1 << 0;
const SUPPORTS_SETPOINTS = 1 << 1;
const SUPPORTS_NAMES = 1 << 2;
const SUPPORTS_OFF = 1 << 3;
}
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub struct ScheduleTypeStruct {
pub system_mode: SystemModeEnum,
pub number_of_schedules: u8,
pub schedule_type_features: ScheduleTypeFeaturesBitmap,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum SetpointChangeSourceEnum {
Manual,
Schedule,
External,
Unknown(u8),
}
impl SetpointChangeSourceEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Manual,
1 => Self::Schedule,
2 => Self::External,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Manual => 0,
Self::Schedule => 1,
Self::External => 2,
Self::Unknown(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum SetpointRaiseLowerModeEnum {
Heat,
Cool,
Both,
Unknown(u8),
}
impl SetpointRaiseLowerModeEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Heat,
1 => Self::Cool,
2 => Self::Both,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Heat => 0,
Self::Cool => 1,
Self::Both => 2,
Self::Unknown(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum StartOfWeekEnum {
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
Unknown(u8),
}
impl StartOfWeekEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Sunday,
1 => Self::Monday,
2 => Self::Tuesday,
3 => Self::Wednesday,
4 => Self::Thursday,
5 => Self::Friday,
6 => Self::Saturday,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Sunday => 0,
Self::Monday => 1,
Self::Tuesday => 2,
Self::Wednesday => 3,
Self::Thursday => 4,
Self::Friday => 5,
Self::Saturday => 6,
Self::Unknown(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum SystemModeEnum {
Off,
Auto,
Cool,
Heat,
EmergencyHeat,
Precooling,
FanOnly,
Dry,
Sleep,
Unknown(u8),
}
impl SystemModeEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Off,
1 => Self::Auto,
3 => Self::Cool,
4 => Self::Heat,
5 => Self::EmergencyHeat,
6 => Self::Precooling,
7 => Self::FanOnly,
8 => Self::Dry,
9 => Self::Sleep,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Off => 0,
Self::Auto => 1,
Self::Cool => 3,
Self::Heat => 4,
Self::EmergencyHeat => 5,
Self::Precooling => 6,
Self::FanOnly => 7,
Self::Dry => 8,
Self::Sleep => 9,
Self::Unknown(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum TemperatureSetpointHoldEnum {
SetpointHoldOff,
SetpointHoldOn,
Unknown(u8),
}
impl TemperatureSetpointHoldEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::SetpointHoldOff,
1 => Self::SetpointHoldOn,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::SetpointHoldOff => 0,
Self::SetpointHoldOn => 1,
Self::Unknown(v) => v,
}
}
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub struct ThermostatAttributeStatusEntryStruct {
pub attribute_id: u32,
pub status_code: u8,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ThermostatRunningModeEnum {
Off,
Cool,
Heat,
Unknown(u8),
}
impl ThermostatRunningModeEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Off,
3 => Self::Cool,
4 => Self::Heat,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Off => 0,
Self::Cool => 3,
Self::Heat => 4,
Self::Unknown(v) => v,
}
}
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub struct WeeklyScheduleTransitionStruct {
pub transition_time: u16,
pub heat_setpoint: Nullable<i16>,
pub cool_setpoint: Nullable<i16>,
}
impl PresetStruct {
pub fn decode_from(r: &mut TlvReader<'_>) -> Result<Self, ClusterError> {
let mut f_preset_handle: Option<Nullable<Vec<u8>>> = None;
let mut f_preset_scenario: Option<PresetScenarioEnum> = None;
let mut f_name: Option<Nullable<String>> = None;
let mut f_cooling_setpoint: Option<i16> = None;
let mut f_heating_setpoint: Option<i16> = None;
let mut f_built_in: Option<Nullable<bool>> = None;
loop {
match r.next()? {
Some(Element::ContainerEnd) => break,
Some(Element::Scalar {
tag: Tag::Context(0),
value: Value::Null,
}) => f_preset_handle = Some(Nullable::Null),
Some(Element::Scalar {
tag: Tag::Context(0),
value: Value::Bytes(v),
}) => f_preset_handle = Some(Nullable::Value(v)),
Some(Element::Scalar {
tag: Tag::Context(1),
value: Value::Uint(v),
}) => {
f_preset_scenario = Some(PresetScenarioEnum::from_raw(
u8::try_from(v)
.map_err(|_| ClusterError::InvalidLength("PresetScenario"))?,
))
}
Some(Element::Scalar {
tag: Tag::Context(2),
value: Value::Null,
}) => f_name = Some(Nullable::Null),
Some(Element::Scalar {
tag: Tag::Context(2),
value: Value::Utf8(v),
}) => f_name = Some(Nullable::Value(v)),
Some(Element::Scalar {
tag: Tag::Context(3),
value: Value::Int(v),
}) => {
f_cooling_setpoint = Some(
i16::try_from(v)
.map_err(|_| ClusterError::InvalidLength("CoolingSetpoint"))?,
)
}
Some(Element::Scalar {
tag: Tag::Context(4),
value: Value::Int(v),
}) => {
f_heating_setpoint = Some(
i16::try_from(v)
.map_err(|_| ClusterError::InvalidLength("HeatingSetpoint"))?,
)
}
Some(Element::Scalar {
tag: Tag::Context(5),
value: Value::Null,
}) => f_built_in = Some(Nullable::Null),
Some(Element::Scalar {
tag: Tag::Context(5),
value: Value::Bool(v),
}) => f_built_in = Some(Nullable::Value(v)),
None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
Some(Element::ContainerStart { .. }) => r.skip_container()?,
Some(_) => {} }
}
Ok(Self {
preset_handle: f_preset_handle.ok_or(ClusterError::MissingField("PresetHandle"))?,
preset_scenario: f_preset_scenario
.ok_or(ClusterError::MissingField("PresetScenario"))?,
name: f_name,
cooling_setpoint: f_cooling_setpoint,
heating_setpoint: f_heating_setpoint,
built_in: f_built_in.ok_or(ClusterError::MissingField("BuiltIn"))?,
})
}
pub fn decode(tlv: &[u8]) -> Result<Self, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::ContainerStart {
kind: ContainerKind::Structure,
..
}) => {}
_ => {
return Err(ClusterError::UnexpectedType {
context: "PresetStruct",
})
}
}
Self::decode_from(&mut r)
}
#[allow(clippy::expect_used)] pub fn write_fields(&self, w: &mut TlvWriter<'_>) {
match &self.preset_handle {
Nullable::Null => w.put_null(Tag::Context(0)).expect("infallible: vec writer"),
Nullable::Value(preset_handle) => {
w.put_bytes(Tag::Context(0), &*preset_handle)
.expect("infallible: vec writer");
}
}
w.put_uint(Tag::Context(1), u64::from(self.preset_scenario.to_raw()))
.expect("infallible: vec writer");
if let Some(name) = &self.name {
match name {
Nullable::Null => w.put_null(Tag::Context(2)).expect("infallible: vec writer"),
Nullable::Value(name) => {
w.put_utf8(Tag::Context(2), &*name)
.expect("infallible: vec writer");
}
}
}
if let Some(cooling_setpoint) = &self.cooling_setpoint {
w.put_int(Tag::Context(3), i64::from(*cooling_setpoint))
.expect("infallible: vec writer");
}
if let Some(heating_setpoint) = &self.heating_setpoint {
w.put_int(Tag::Context(4), i64::from(*heating_setpoint))
.expect("infallible: vec writer");
}
match &self.built_in {
Nullable::Null => w.put_null(Tag::Context(5)).expect("infallible: vec writer"),
Nullable::Value(built_in) => {
w.put_bool(Tag::Context(5), *built_in)
.expect("infallible: vec writer");
}
}
}
#[must_use]
#[allow(clippy::expect_used)] pub fn encode(&self) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
self.write_fields(&mut w);
w.end_container().expect("infallible: vec writer");
buf
}
}
impl PresetTypeStruct {
pub fn decode_from(r: &mut TlvReader<'_>) -> Result<Self, ClusterError> {
let mut f_preset_scenario: Option<PresetScenarioEnum> = None;
let mut f_number_of_presets: Option<u8> = None;
let mut f_preset_type_features: Option<PresetTypeFeaturesBitmap> = None;
loop {
match r.next()? {
Some(Element::ContainerEnd) => break,
Some(Element::Scalar {
tag: Tag::Context(0),
value: Value::Uint(v),
}) => {
f_preset_scenario = Some(PresetScenarioEnum::from_raw(
u8::try_from(v)
.map_err(|_| ClusterError::InvalidLength("PresetScenario"))?,
))
}
Some(Element::Scalar {
tag: Tag::Context(1),
value: Value::Uint(v),
}) => {
f_number_of_presets = Some(
u8::try_from(v)
.map_err(|_| ClusterError::InvalidLength("NumberOfPresets"))?,
)
}
Some(Element::Scalar {
tag: Tag::Context(2),
value: Value::Uint(v),
}) => {
f_preset_type_features = Some(PresetTypeFeaturesBitmap::from_bits_retain(
u16::try_from(v)
.map_err(|_| ClusterError::InvalidLength("PresetTypeFeatures"))?,
))
}
None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
Some(Element::ContainerStart { .. }) => r.skip_container()?,
Some(_) => {} }
}
Ok(Self {
preset_scenario: f_preset_scenario
.ok_or(ClusterError::MissingField("PresetScenario"))?,
number_of_presets: f_number_of_presets
.ok_or(ClusterError::MissingField("NumberOfPresets"))?,
preset_type_features: f_preset_type_features
.ok_or(ClusterError::MissingField("PresetTypeFeatures"))?,
})
}
pub fn decode(tlv: &[u8]) -> Result<Self, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::ContainerStart {
kind: ContainerKind::Structure,
..
}) => {}
_ => {
return Err(ClusterError::UnexpectedType {
context: "PresetTypeStruct",
})
}
}
Self::decode_from(&mut r)
}
#[allow(clippy::expect_used)] pub fn write_fields(&self, w: &mut TlvWriter<'_>) {
w.put_uint(Tag::Context(0), u64::from(self.preset_scenario.to_raw()))
.expect("infallible: vec writer");
w.put_uint(Tag::Context(1), u64::from(self.number_of_presets))
.expect("infallible: vec writer");
w.put_uint(Tag::Context(2), u64::from(self.preset_type_features.bits()))
.expect("infallible: vec writer");
}
#[must_use]
#[allow(clippy::expect_used)] pub fn encode(&self) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
self.write_fields(&mut w);
w.end_container().expect("infallible: vec writer");
buf
}
}
impl ScheduleStruct {
pub fn decode_from(r: &mut TlvReader<'_>) -> Result<Self, ClusterError> {
let mut f_schedule_handle: Option<Nullable<Vec<u8>>> = None;
let mut f_system_mode: Option<SystemModeEnum> = None;
let mut f_name: Option<String> = None;
let mut f_preset_handle: Option<Vec<u8>> = None;
let mut f_transitions: Option<Vec<ScheduleTransitionStruct>> = None;
let mut f_built_in: Option<Nullable<bool>> = None;
loop {
match r.next()? {
Some(Element::ContainerEnd) => break,
Some(Element::Scalar {
tag: Tag::Context(0),
value: Value::Null,
}) => f_schedule_handle = Some(Nullable::Null),
Some(Element::Scalar {
tag: Tag::Context(0),
value: Value::Bytes(v),
}) => f_schedule_handle = Some(Nullable::Value(v)),
Some(Element::Scalar {
tag: Tag::Context(1),
value: Value::Uint(v),
}) => {
f_system_mode = Some(SystemModeEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("SystemMode"))?,
))
}
Some(Element::Scalar {
tag: Tag::Context(2),
value: Value::Utf8(v),
}) => f_name = Some(v),
Some(Element::Scalar {
tag: Tag::Context(3),
value: Value::Bytes(v),
}) => f_preset_handle = Some(v),
Some(Element::ContainerStart {
tag: Tag::Context(4),
kind: ContainerKind::Array,
}) => {
let mut out = Vec::new();
loop {
match r.next()? {
Some(Element::ContainerEnd) => break,
Some(Element::ContainerStart {
kind: ContainerKind::Structure,
..
}) => {
out.push(ScheduleTransitionStruct::decode_from(r)?);
}
None => {
return Err(ClusterError::Tlv(
matter_codec::Error::UnclosedContainer,
))
}
Some(Element::ContainerStart { .. }) => r.skip_container()?,
Some(_) => {} }
}
f_transitions = Some(out);
}
Some(Element::Scalar {
tag: Tag::Context(5),
value: Value::Null,
}) => f_built_in = Some(Nullable::Null),
Some(Element::Scalar {
tag: Tag::Context(5),
value: Value::Bool(v),
}) => f_built_in = Some(Nullable::Value(v)),
None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
Some(Element::ContainerStart { .. }) => r.skip_container()?,
Some(_) => {} }
}
Ok(Self {
schedule_handle: f_schedule_handle
.ok_or(ClusterError::MissingField("ScheduleHandle"))?,
system_mode: f_system_mode.ok_or(ClusterError::MissingField("SystemMode"))?,
name: f_name,
preset_handle: f_preset_handle,
transitions: f_transitions.ok_or(ClusterError::MissingField("Transitions"))?,
built_in: f_built_in.ok_or(ClusterError::MissingField("BuiltIn"))?,
})
}
pub fn decode(tlv: &[u8]) -> Result<Self, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::ContainerStart {
kind: ContainerKind::Structure,
..
}) => {}
_ => {
return Err(ClusterError::UnexpectedType {
context: "ScheduleStruct",
})
}
}
Self::decode_from(&mut r)
}
}
impl ScheduleTransitionStruct {
pub fn decode_from(r: &mut TlvReader<'_>) -> Result<Self, ClusterError> {
let mut f_day_of_week: Option<ScheduleDayOfWeekBitmap> = None;
let mut f_transition_time: Option<u16> = None;
let mut f_preset_handle: Option<Vec<u8>> = None;
let mut f_system_mode: Option<SystemModeEnum> = None;
let mut f_cooling_setpoint: Option<i16> = None;
let mut f_heating_setpoint: Option<i16> = None;
loop {
match r.next()? {
Some(Element::ContainerEnd) => break,
Some(Element::Scalar {
tag: Tag::Context(0),
value: Value::Uint(v),
}) => {
f_day_of_week = Some(ScheduleDayOfWeekBitmap::from_bits_retain(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("DayOfWeek"))?,
))
}
Some(Element::Scalar {
tag: Tag::Context(1),
value: Value::Uint(v),
}) => {
f_transition_time = Some(
u16::try_from(v)
.map_err(|_| ClusterError::InvalidLength("TransitionTime"))?,
)
}
Some(Element::Scalar {
tag: Tag::Context(2),
value: Value::Bytes(v),
}) => f_preset_handle = Some(v),
Some(Element::Scalar {
tag: Tag::Context(3),
value: Value::Uint(v),
}) => {
f_system_mode = Some(SystemModeEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("SystemMode"))?,
))
}
Some(Element::Scalar {
tag: Tag::Context(4),
value: Value::Int(v),
}) => {
f_cooling_setpoint = Some(
i16::try_from(v)
.map_err(|_| ClusterError::InvalidLength("CoolingSetpoint"))?,
)
}
Some(Element::Scalar {
tag: Tag::Context(5),
value: Value::Int(v),
}) => {
f_heating_setpoint = Some(
i16::try_from(v)
.map_err(|_| ClusterError::InvalidLength("HeatingSetpoint"))?,
)
}
None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
Some(Element::ContainerStart { .. }) => r.skip_container()?,
Some(_) => {} }
}
Ok(Self {
day_of_week: f_day_of_week.ok_or(ClusterError::MissingField("DayOfWeek"))?,
transition_time: f_transition_time
.ok_or(ClusterError::MissingField("TransitionTime"))?,
preset_handle: f_preset_handle,
system_mode: f_system_mode,
cooling_setpoint: f_cooling_setpoint,
heating_setpoint: f_heating_setpoint,
})
}
pub fn decode(tlv: &[u8]) -> Result<Self, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::ContainerStart {
kind: ContainerKind::Structure,
..
}) => {}
_ => {
return Err(ClusterError::UnexpectedType {
context: "ScheduleTransitionStruct",
})
}
}
Self::decode_from(&mut r)
}
#[allow(clippy::expect_used)] pub fn write_fields(&self, w: &mut TlvWriter<'_>) {
w.put_uint(Tag::Context(0), u64::from(self.day_of_week.bits()))
.expect("infallible: vec writer");
w.put_uint(Tag::Context(1), u64::from(self.transition_time))
.expect("infallible: vec writer");
if let Some(preset_handle) = &self.preset_handle {
w.put_bytes(Tag::Context(2), &*preset_handle)
.expect("infallible: vec writer");
}
if let Some(system_mode) = &self.system_mode {
w.put_uint(Tag::Context(3), u64::from((*system_mode).to_raw()))
.expect("infallible: vec writer");
}
if let Some(cooling_setpoint) = &self.cooling_setpoint {
w.put_int(Tag::Context(4), i64::from(*cooling_setpoint))
.expect("infallible: vec writer");
}
if let Some(heating_setpoint) = &self.heating_setpoint {
w.put_int(Tag::Context(5), i64::from(*heating_setpoint))
.expect("infallible: vec writer");
}
}
#[must_use]
#[allow(clippy::expect_used)] pub fn encode(&self) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
self.write_fields(&mut w);
w.end_container().expect("infallible: vec writer");
buf
}
}
impl ScheduleTypeStruct {
pub fn decode_from(r: &mut TlvReader<'_>) -> Result<Self, ClusterError> {
let mut f_system_mode: Option<SystemModeEnum> = None;
let mut f_number_of_schedules: Option<u8> = None;
let mut f_schedule_type_features: Option<ScheduleTypeFeaturesBitmap> = None;
loop {
match r.next()? {
Some(Element::ContainerEnd) => break,
Some(Element::Scalar {
tag: Tag::Context(0),
value: Value::Uint(v),
}) => {
f_system_mode = Some(SystemModeEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("SystemMode"))?,
))
}
Some(Element::Scalar {
tag: Tag::Context(1),
value: Value::Uint(v),
}) => {
f_number_of_schedules = Some(
u8::try_from(v)
.map_err(|_| ClusterError::InvalidLength("NumberOfSchedules"))?,
)
}
Some(Element::Scalar {
tag: Tag::Context(2),
value: Value::Uint(v),
}) => {
f_schedule_type_features = Some(ScheduleTypeFeaturesBitmap::from_bits_retain(
u16::try_from(v)
.map_err(|_| ClusterError::InvalidLength("ScheduleTypeFeatures"))?,
))
}
None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
Some(Element::ContainerStart { .. }) => r.skip_container()?,
Some(_) => {} }
}
Ok(Self {
system_mode: f_system_mode.ok_or(ClusterError::MissingField("SystemMode"))?,
number_of_schedules: f_number_of_schedules
.ok_or(ClusterError::MissingField("NumberOfSchedules"))?,
schedule_type_features: f_schedule_type_features
.ok_or(ClusterError::MissingField("ScheduleTypeFeatures"))?,
})
}
pub fn decode(tlv: &[u8]) -> Result<Self, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::ContainerStart {
kind: ContainerKind::Structure,
..
}) => {}
_ => {
return Err(ClusterError::UnexpectedType {
context: "ScheduleTypeStruct",
})
}
}
Self::decode_from(&mut r)
}
#[allow(clippy::expect_used)] pub fn write_fields(&self, w: &mut TlvWriter<'_>) {
w.put_uint(Tag::Context(0), u64::from(self.system_mode.to_raw()))
.expect("infallible: vec writer");
w.put_uint(Tag::Context(1), u64::from(self.number_of_schedules))
.expect("infallible: vec writer");
w.put_uint(
Tag::Context(2),
u64::from(self.schedule_type_features.bits()),
)
.expect("infallible: vec writer");
}
#[must_use]
#[allow(clippy::expect_used)] pub fn encode(&self) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
self.write_fields(&mut w);
w.end_container().expect("infallible: vec writer");
buf
}
}
impl ThermostatAttributeStatusEntryStruct {
pub fn decode_from(r: &mut TlvReader<'_>) -> Result<Self, ClusterError> {
let mut f_attribute_id: Option<u32> = None;
let mut f_status_code: Option<u8> = None;
loop {
match r.next()? {
Some(Element::ContainerEnd) => break,
Some(Element::Scalar {
tag: Tag::Context(0),
value: Value::Uint(v),
}) => {
f_attribute_id = Some(
u32::try_from(v).map_err(|_| ClusterError::InvalidLength("AttributeId"))?,
)
}
Some(Element::Scalar {
tag: Tag::Context(1),
value: Value::Uint(v),
}) => {
f_status_code = Some(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("StatusCode"))?,
)
}
None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
Some(Element::ContainerStart { .. }) => r.skip_container()?,
Some(_) => {} }
}
Ok(Self {
attribute_id: f_attribute_id.ok_or(ClusterError::MissingField("AttributeId"))?,
status_code: f_status_code.ok_or(ClusterError::MissingField("StatusCode"))?,
})
}
pub fn decode(tlv: &[u8]) -> Result<Self, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::ContainerStart {
kind: ContainerKind::Structure,
..
}) => {}
_ => {
return Err(ClusterError::UnexpectedType {
context: "ThermostatAttributeStatusEntryStruct",
})
}
}
Self::decode_from(&mut r)
}
#[allow(clippy::expect_used)] pub fn write_fields(&self, w: &mut TlvWriter<'_>) {
w.put_uint(Tag::Context(0), u64::from(self.attribute_id))
.expect("infallible: vec writer");
w.put_uint(Tag::Context(1), u64::from(self.status_code))
.expect("infallible: vec writer");
}
#[must_use]
#[allow(clippy::expect_used)] pub fn encode(&self) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
self.write_fields(&mut w);
w.end_container().expect("infallible: vec writer");
buf
}
}
impl WeeklyScheduleTransitionStruct {
pub fn decode_from(r: &mut TlvReader<'_>) -> Result<Self, ClusterError> {
let mut f_transition_time: Option<u16> = None;
let mut f_heat_setpoint: Option<Nullable<i16>> = None;
let mut f_cool_setpoint: Option<Nullable<i16>> = None;
loop {
match r.next()? {
Some(Element::ContainerEnd) => break,
Some(Element::Scalar {
tag: Tag::Context(0),
value: Value::Uint(v),
}) => {
f_transition_time = Some(
u16::try_from(v)
.map_err(|_| ClusterError::InvalidLength("TransitionTime"))?,
)
}
Some(Element::Scalar {
tag: Tag::Context(1),
value: Value::Null,
}) => f_heat_setpoint = Some(Nullable::Null),
Some(Element::Scalar {
tag: Tag::Context(1),
value: Value::Int(v),
}) => {
f_heat_setpoint = Some(Nullable::Value(
i16::try_from(v)
.map_err(|_| ClusterError::InvalidLength("HeatSetpoint"))?,
))
}
Some(Element::Scalar {
tag: Tag::Context(2),
value: Value::Null,
}) => f_cool_setpoint = Some(Nullable::Null),
Some(Element::Scalar {
tag: Tag::Context(2),
value: Value::Int(v),
}) => {
f_cool_setpoint = Some(Nullable::Value(
i16::try_from(v)
.map_err(|_| ClusterError::InvalidLength("CoolSetpoint"))?,
))
}
None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
Some(Element::ContainerStart { .. }) => r.skip_container()?,
Some(_) => {} }
}
Ok(Self {
transition_time: f_transition_time
.ok_or(ClusterError::MissingField("TransitionTime"))?,
heat_setpoint: f_heat_setpoint.ok_or(ClusterError::MissingField("HeatSetpoint"))?,
cool_setpoint: f_cool_setpoint.ok_or(ClusterError::MissingField("CoolSetpoint"))?,
})
}
pub fn decode(tlv: &[u8]) -> Result<Self, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::ContainerStart {
kind: ContainerKind::Structure,
..
}) => {}
_ => {
return Err(ClusterError::UnexpectedType {
context: "WeeklyScheduleTransitionStruct",
})
}
}
Self::decode_from(&mut r)
}
#[allow(clippy::expect_used)] pub fn write_fields(&self, w: &mut TlvWriter<'_>) {
w.put_uint(Tag::Context(0), u64::from(self.transition_time))
.expect("infallible: vec writer");
match &self.heat_setpoint {
Nullable::Null => w.put_null(Tag::Context(1)).expect("infallible: vec writer"),
Nullable::Value(heat_setpoint) => {
w.put_int(Tag::Context(1), i64::from(*heat_setpoint))
.expect("infallible: vec writer");
}
}
match &self.cool_setpoint {
Nullable::Null => w.put_null(Tag::Context(2)).expect("infallible: vec writer"),
Nullable::Value(cool_setpoint) => {
w.put_int(Tag::Context(2), i64::from(*cool_setpoint))
.expect("infallible: vec writer");
}
}
}
#[must_use]
#[allow(clippy::expect_used)] pub fn encode(&self) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
self.write_fields(&mut w);
w.end_container().expect("infallible: vec writer");
buf
}
}
pub fn decode_local_temperature(tlv: &[u8]) -> Result<Nullable<i16>, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Null, ..
}) => Ok(Nullable::Null),
Some(Element::Scalar {
value: Value::Int(v),
..
}) => {
Ok(Nullable::Value(i16::try_from(v).map_err(|_| {
ClusterError::InvalidLength("LocalTemperature")
})?))
}
_ => Err(ClusterError::UnexpectedType {
context: "LocalTemperature",
}),
}
}
pub fn decode_outdoor_temperature(tlv: &[u8]) -> Result<Nullable<i16>, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Null, ..
}) => Ok(Nullable::Null),
Some(Element::Scalar {
value: Value::Int(v),
..
}) => Ok(Nullable::Value(i16::try_from(v).map_err(|_| {
ClusterError::InvalidLength("OutdoorTemperature")
})?)),
_ => Err(ClusterError::UnexpectedType {
context: "OutdoorTemperature",
}),
}
}
pub fn decode_occupancy(tlv: &[u8]) -> Result<OccupancyBitmap, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(OccupancyBitmap::from_bits_retain(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("Occupancy"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "Occupancy",
}),
}
}
pub fn decode_abs_min_heat_setpoint_limit(tlv: &[u8]) -> Result<i16, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Int(v),
..
}) => {
Ok(i16::try_from(v)
.map_err(|_| ClusterError::InvalidLength("AbsMinHeatSetpointLimit"))?)
}
_ => Err(ClusterError::UnexpectedType {
context: "AbsMinHeatSetpointLimit",
}),
}
}
pub fn decode_abs_max_heat_setpoint_limit(tlv: &[u8]) -> Result<i16, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Int(v),
..
}) => {
Ok(i16::try_from(v)
.map_err(|_| ClusterError::InvalidLength("AbsMaxHeatSetpointLimit"))?)
}
_ => Err(ClusterError::UnexpectedType {
context: "AbsMaxHeatSetpointLimit",
}),
}
}
pub fn decode_abs_min_cool_setpoint_limit(tlv: &[u8]) -> Result<i16, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Int(v),
..
}) => {
Ok(i16::try_from(v)
.map_err(|_| ClusterError::InvalidLength("AbsMinCoolSetpointLimit"))?)
}
_ => Err(ClusterError::UnexpectedType {
context: "AbsMinCoolSetpointLimit",
}),
}
}
pub fn decode_abs_max_cool_setpoint_limit(tlv: &[u8]) -> Result<i16, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Int(v),
..
}) => {
Ok(i16::try_from(v)
.map_err(|_| ClusterError::InvalidLength("AbsMaxCoolSetpointLimit"))?)
}
_ => Err(ClusterError::UnexpectedType {
context: "AbsMaxCoolSetpointLimit",
}),
}
}
pub fn decode_local_temperature_calibration(tlv: &[u8]) -> Result<i8, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Int(v),
..
}) => Ok(i8::try_from(v)
.map_err(|_| ClusterError::InvalidLength("LocalTemperatureCalibration"))?),
_ => Err(ClusterError::UnexpectedType {
context: "LocalTemperatureCalibration",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_local_temperature_calibration(value: i8) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_int(Tag::Anonymous, i64::from(value))
.expect("infallible: vec writer");
buf
}
pub fn decode_occupied_cooling_setpoint(tlv: &[u8]) -> Result<i16, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Int(v),
..
}) => {
Ok(i16::try_from(v)
.map_err(|_| ClusterError::InvalidLength("OccupiedCoolingSetpoint"))?)
}
_ => Err(ClusterError::UnexpectedType {
context: "OccupiedCoolingSetpoint",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_occupied_cooling_setpoint(value: i16) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_int(Tag::Anonymous, i64::from(value))
.expect("infallible: vec writer");
buf
}
pub fn decode_occupied_heating_setpoint(tlv: &[u8]) -> Result<i16, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Int(v),
..
}) => {
Ok(i16::try_from(v)
.map_err(|_| ClusterError::InvalidLength("OccupiedHeatingSetpoint"))?)
}
_ => Err(ClusterError::UnexpectedType {
context: "OccupiedHeatingSetpoint",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_occupied_heating_setpoint(value: i16) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_int(Tag::Anonymous, i64::from(value))
.expect("infallible: vec writer");
buf
}
pub fn decode_unoccupied_cooling_setpoint(tlv: &[u8]) -> Result<i16, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Int(v),
..
}) => Ok(i16::try_from(v)
.map_err(|_| ClusterError::InvalidLength("UnoccupiedCoolingSetpoint"))?),
_ => Err(ClusterError::UnexpectedType {
context: "UnoccupiedCoolingSetpoint",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_unoccupied_cooling_setpoint(value: i16) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_int(Tag::Anonymous, i64::from(value))
.expect("infallible: vec writer");
buf
}
pub fn decode_unoccupied_heating_setpoint(tlv: &[u8]) -> Result<i16, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Int(v),
..
}) => Ok(i16::try_from(v)
.map_err(|_| ClusterError::InvalidLength("UnoccupiedHeatingSetpoint"))?),
_ => Err(ClusterError::UnexpectedType {
context: "UnoccupiedHeatingSetpoint",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_unoccupied_heating_setpoint(value: i16) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_int(Tag::Anonymous, i64::from(value))
.expect("infallible: vec writer");
buf
}
pub fn decode_min_heat_setpoint_limit(tlv: &[u8]) -> Result<i16, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Int(v),
..
}) => Ok(i16::try_from(v).map_err(|_| ClusterError::InvalidLength("MinHeatSetpointLimit"))?),
_ => Err(ClusterError::UnexpectedType {
context: "MinHeatSetpointLimit",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_min_heat_setpoint_limit(value: i16) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_int(Tag::Anonymous, i64::from(value))
.expect("infallible: vec writer");
buf
}
pub fn decode_max_heat_setpoint_limit(tlv: &[u8]) -> Result<i16, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Int(v),
..
}) => Ok(i16::try_from(v).map_err(|_| ClusterError::InvalidLength("MaxHeatSetpointLimit"))?),
_ => Err(ClusterError::UnexpectedType {
context: "MaxHeatSetpointLimit",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_max_heat_setpoint_limit(value: i16) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_int(Tag::Anonymous, i64::from(value))
.expect("infallible: vec writer");
buf
}
pub fn decode_min_cool_setpoint_limit(tlv: &[u8]) -> Result<i16, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Int(v),
..
}) => Ok(i16::try_from(v).map_err(|_| ClusterError::InvalidLength("MinCoolSetpointLimit"))?),
_ => Err(ClusterError::UnexpectedType {
context: "MinCoolSetpointLimit",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_min_cool_setpoint_limit(value: i16) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_int(Tag::Anonymous, i64::from(value))
.expect("infallible: vec writer");
buf
}
pub fn decode_max_cool_setpoint_limit(tlv: &[u8]) -> Result<i16, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Int(v),
..
}) => Ok(i16::try_from(v).map_err(|_| ClusterError::InvalidLength("MaxCoolSetpointLimit"))?),
_ => Err(ClusterError::UnexpectedType {
context: "MaxCoolSetpointLimit",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_max_cool_setpoint_limit(value: i16) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_int(Tag::Anonymous, i64::from(value))
.expect("infallible: vec writer");
buf
}
pub fn decode_min_setpoint_dead_band(tlv: &[u8]) -> Result<i8, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Int(v),
..
}) => Ok(i8::try_from(v).map_err(|_| ClusterError::InvalidLength("MinSetpointDeadBand"))?),
_ => Err(ClusterError::UnexpectedType {
context: "MinSetpointDeadBand",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_min_setpoint_dead_band(value: i8) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_int(Tag::Anonymous, i64::from(value))
.expect("infallible: vec writer");
buf
}
pub fn decode_remote_sensing(tlv: &[u8]) -> Result<RemoteSensingBitmap, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(RemoteSensingBitmap::from_bits_retain(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("RemoteSensing"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "RemoteSensing",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_remote_sensing(value: RemoteSensingBitmap) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_uint(Tag::Anonymous, u64::from(value.bits()))
.expect("infallible: vec writer");
buf
}
pub fn decode_control_sequence_of_operation(
tlv: &[u8],
) -> Result<ControlSequenceOfOperationEnum, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(ControlSequenceOfOperationEnum::from_raw(
u8::try_from(v)
.map_err(|_| ClusterError::InvalidLength("ControlSequenceOfOperation"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "ControlSequenceOfOperation",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_control_sequence_of_operation(value: ControlSequenceOfOperationEnum) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_uint(Tag::Anonymous, u64::from(value.to_raw()))
.expect("infallible: vec writer");
buf
}
pub fn decode_system_mode(tlv: &[u8]) -> Result<SystemModeEnum, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(SystemModeEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("SystemMode"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "SystemMode",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_system_mode(value: SystemModeEnum) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_uint(Tag::Anonymous, u64::from(value.to_raw()))
.expect("infallible: vec writer");
buf
}
pub fn decode_thermostat_running_mode(
tlv: &[u8],
) -> Result<ThermostatRunningModeEnum, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(ThermostatRunningModeEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("ThermostatRunningMode"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "ThermostatRunningMode",
}),
}
}
pub fn decode_temperature_setpoint_hold(
tlv: &[u8],
) -> Result<TemperatureSetpointHoldEnum, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(TemperatureSetpointHoldEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("TemperatureSetpointHold"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "TemperatureSetpointHold",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_temperature_setpoint_hold(value: TemperatureSetpointHoldEnum) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_uint(Tag::Anonymous, u64::from(value.to_raw()))
.expect("infallible: vec writer");
buf
}
pub fn decode_temperature_setpoint_hold_duration(
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("TemperatureSetpointHoldDuration")
})?)),
_ => Err(ClusterError::UnexpectedType {
context: "TemperatureSetpointHoldDuration",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_temperature_setpoint_hold_duration(value: Nullable<u16>) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
match value {
Nullable::Null => w.put_null(Tag::Anonymous).expect("infallible: vec writer"),
Nullable::Value(value) => {
w.put_uint(Tag::Anonymous, u64::from(value))
.expect("infallible: vec writer");
}
}
buf
}
pub fn decode_thermostat_running_state(tlv: &[u8]) -> Result<RelayStateBitmap, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(RelayStateBitmap::from_bits_retain(
u16::try_from(v).map_err(|_| ClusterError::InvalidLength("ThermostatRunningState"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "ThermostatRunningState",
}),
}
}
pub fn decode_setpoint_change_source(tlv: &[u8]) -> Result<SetpointChangeSourceEnum, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(SetpointChangeSourceEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("SetpointChangeSource"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "SetpointChangeSource",
}),
}
}
pub fn decode_setpoint_change_amount(tlv: &[u8]) -> Result<Nullable<i16>, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Null, ..
}) => Ok(Nullable::Null),
Some(Element::Scalar {
value: Value::Int(v),
..
}) => Ok(Nullable::Value(i16::try_from(v).map_err(|_| {
ClusterError::InvalidLength("SetpointChangeAmount")
})?)),
_ => Err(ClusterError::UnexpectedType {
context: "SetpointChangeAmount",
}),
}
}
pub fn decode_setpoint_change_source_timestamp(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("SetpointChangeSourceTimestamp"))?),
_ => Err(ClusterError::UnexpectedType {
context: "SetpointChangeSourceTimestamp",
}),
}
}
pub fn decode_emergency_heat_delta(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("EmergencyHeatDelta"))?),
_ => Err(ClusterError::UnexpectedType {
context: "EmergencyHeatDelta",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_emergency_heat_delta(value: u8) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_uint(Tag::Anonymous, u64::from(value))
.expect("infallible: vec writer");
buf
}
pub fn decode_ac_type(tlv: &[u8]) -> Result<ACTypeEnum, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(ACTypeEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("AcType"))?,
)),
_ => Err(ClusterError::UnexpectedType { context: "AcType" }),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_ac_type(value: ACTypeEnum) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_uint(Tag::Anonymous, u64::from(value.to_raw()))
.expect("infallible: vec writer");
buf
}
pub fn decode_ac_capacity(tlv: &[u8]) -> Result<u16, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(u16::try_from(v).map_err(|_| ClusterError::InvalidLength("AcCapacity"))?),
_ => Err(ClusterError::UnexpectedType {
context: "AcCapacity",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_ac_capacity(value: u16) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_uint(Tag::Anonymous, u64::from(value))
.expect("infallible: vec writer");
buf
}
pub fn decode_ac_refrigerant_type(tlv: &[u8]) -> Result<ACRefrigerantTypeEnum, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(ACRefrigerantTypeEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("AcRefrigerantType"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "AcRefrigerantType",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_ac_refrigerant_type(value: ACRefrigerantTypeEnum) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_uint(Tag::Anonymous, u64::from(value.to_raw()))
.expect("infallible: vec writer");
buf
}
pub fn decode_ac_compressor_type(tlv: &[u8]) -> Result<ACCompressorTypeEnum, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(ACCompressorTypeEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("AcCompressorType"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "AcCompressorType",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_ac_compressor_type(value: ACCompressorTypeEnum) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_uint(Tag::Anonymous, u64::from(value.to_raw()))
.expect("infallible: vec writer");
buf
}
pub fn decode_ac_error_code(tlv: &[u8]) -> Result<ACErrorCodeBitmap, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(ACErrorCodeBitmap::from_bits_retain(
u32::try_from(v).map_err(|_| ClusterError::InvalidLength("AcErrorCode"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "AcErrorCode",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_ac_error_code(value: ACErrorCodeBitmap) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_uint(Tag::Anonymous, u64::from(value.bits()))
.expect("infallible: vec writer");
buf
}
pub fn decode_ac_louver_position(tlv: &[u8]) -> Result<ACLouverPositionEnum, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(ACLouverPositionEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("AcLouverPosition"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "AcLouverPosition",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_ac_louver_position(value: ACLouverPositionEnum) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_uint(Tag::Anonymous, u64::from(value.to_raw()))
.expect("infallible: vec writer");
buf
}
pub fn decode_ac_coil_temperature(tlv: &[u8]) -> Result<Nullable<i16>, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Null, ..
}) => Ok(Nullable::Null),
Some(Element::Scalar {
value: Value::Int(v),
..
}) => {
Ok(Nullable::Value(i16::try_from(v).map_err(|_| {
ClusterError::InvalidLength("AcCoilTemperature")
})?))
}
_ => Err(ClusterError::UnexpectedType {
context: "AcCoilTemperature",
}),
}
}
pub fn decode_ac_capacity_format(tlv: &[u8]) -> Result<ACCapacityFormatEnum, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(ACCapacityFormatEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("AcCapacityFormat"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "AcCapacityFormat",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_ac_capacity_format(value: ACCapacityFormatEnum) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.put_uint(Tag::Anonymous, u64::from(value.to_raw()))
.expect("infallible: vec writer");
buf
}
pub fn decode_preset_types(tlv: &[u8]) -> Result<Vec<PresetTypeStruct>, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::ContainerStart {
kind: ContainerKind::Array,
..
}) => {}
_ => {
return Err(ClusterError::UnexpectedType {
context: "PresetTypes",
})
}
}
let r = &mut r;
let mut out = Vec::new();
loop {
match r.next()? {
Some(Element::ContainerEnd) => break,
Some(Element::ContainerStart {
kind: ContainerKind::Structure,
..
}) => {
out.push(PresetTypeStruct::decode_from(r)?);
}
None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
Some(Element::ContainerStart { .. }) => r.skip_container()?,
Some(_) => {} }
}
Ok(out)
}
pub fn decode_schedule_types(tlv: &[u8]) -> Result<Vec<ScheduleTypeStruct>, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::ContainerStart {
kind: ContainerKind::Array,
..
}) => {}
_ => {
return Err(ClusterError::UnexpectedType {
context: "ScheduleTypes",
})
}
}
let r = &mut r;
let mut out = Vec::new();
loop {
match r.next()? {
Some(Element::ContainerEnd) => break,
Some(Element::ContainerStart {
kind: ContainerKind::Structure,
..
}) => {
out.push(ScheduleTypeStruct::decode_from(r)?);
}
None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
Some(Element::ContainerStart { .. }) => r.skip_container()?,
Some(_) => {} }
}
Ok(out)
}
pub fn decode_number_of_presets(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("NumberOfPresets"))?),
_ => Err(ClusterError::UnexpectedType {
context: "NumberOfPresets",
}),
}
}
pub fn decode_number_of_schedules(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("NumberOfSchedules"))?),
_ => Err(ClusterError::UnexpectedType {
context: "NumberOfSchedules",
}),
}
}
pub fn decode_number_of_schedule_transitions(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("NumberOfScheduleTransitions"))?),
_ => Err(ClusterError::UnexpectedType {
context: "NumberOfScheduleTransitions",
}),
}
}
pub fn decode_number_of_schedule_transition_per_day(
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("NumberOfScheduleTransitionPerDay")
})?)),
_ => Err(ClusterError::UnexpectedType {
context: "NumberOfScheduleTransitionPerDay",
}),
}
}
pub fn decode_active_preset_handle(tlv: &[u8]) -> Result<Nullable<Vec<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::Bytes(v),
..
}) => Ok(Nullable::Value(v)),
_ => Err(ClusterError::UnexpectedType {
context: "ActivePresetHandle",
}),
}
}
pub fn decode_active_schedule_handle(tlv: &[u8]) -> Result<Nullable<Vec<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::Bytes(v),
..
}) => Ok(Nullable::Value(v)),
_ => Err(ClusterError::UnexpectedType {
context: "ActiveScheduleHandle",
}),
}
}
pub fn decode_presets(tlv: &[u8]) -> Result<Vec<PresetStruct>, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::ContainerStart {
kind: ContainerKind::Array,
..
}) => {}
_ => return Err(ClusterError::UnexpectedType { context: "Presets" }),
}
let r = &mut r;
let mut out = Vec::new();
loop {
match r.next()? {
Some(Element::ContainerEnd) => break,
Some(Element::ContainerStart {
kind: ContainerKind::Structure,
..
}) => {
out.push(PresetStruct::decode_from(r)?);
}
None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
Some(Element::ContainerStart { .. }) => r.skip_container()?,
Some(_) => {} }
}
Ok(out)
}
pub fn decode_schedules(tlv: &[u8]) -> Result<Vec<ScheduleStruct>, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::ContainerStart {
kind: ContainerKind::Array,
..
}) => {}
_ => {
return Err(ClusterError::UnexpectedType {
context: "Schedules",
})
}
}
let r = &mut r;
let mut out = Vec::new();
loop {
match r.next()? {
Some(Element::ContainerEnd) => break,
Some(Element::ContainerStart {
kind: ContainerKind::Structure,
..
}) => {
out.push(ScheduleStruct::decode_from(r)?);
}
None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
Some(Element::ContainerStart { .. }) => r.skip_container()?,
Some(_) => {} }
}
Ok(out)
}
pub fn decode_setpoint_hold_expiry_timestamp(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("SetpointHoldExpiryTimestamp")
})?)),
_ => Err(ClusterError::UnexpectedType {
context: "SetpointHoldExpiryTimestamp",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_setpoint_raise_lower(mode: SetpointRaiseLowerModeEnum, amount: i8) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
w.put_uint(Tag::Context(0), u64::from(mode.to_raw()))
.expect("infallible: vec writer");
w.put_int(Tag::Context(1), i64::from(amount))
.expect("infallible: vec writer");
w.end_container().expect("infallible: vec writer");
buf
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_set_active_schedule_request(schedule_handle: &Vec<u8>) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
w.put_bytes(Tag::Context(0), &schedule_handle)
.expect("infallible: vec writer");
w.end_container().expect("infallible: vec writer");
buf
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_set_active_preset_request(preset_handle: Nullable<Vec<u8>>) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
match preset_handle {
Nullable::Null => w.put_null(Tag::Context(0)).expect("infallible: vec writer"),
Nullable::Value(preset_handle) => {
w.put_bytes(Tag::Context(0), &preset_handle)
.expect("infallible: vec writer");
}
}
w.end_container().expect("infallible: vec writer");
buf
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub struct AtomicResponse {
pub status_code: u8,
pub attribute_status: Vec<ThermostatAttributeStatusEntryStruct>,
pub timeout: Option<u16>,
}
impl AtomicResponse {
pub fn decode_from(r: &mut TlvReader<'_>) -> Result<Self, ClusterError> {
let mut f_status_code: Option<u8> = None;
let mut f_attribute_status: Option<Vec<ThermostatAttributeStatusEntryStruct>> = None;
let mut f_timeout: Option<u16> = None;
loop {
match r.next()? {
Some(Element::ContainerEnd) => break,
Some(Element::Scalar {
tag: Tag::Context(0),
value: Value::Uint(v),
}) => {
f_status_code = Some(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("StatusCode"))?,
)
}
Some(Element::ContainerStart {
tag: Tag::Context(1),
kind: ContainerKind::Array,
}) => {
let mut out = Vec::new();
loop {
match r.next()? {
Some(Element::ContainerEnd) => break,
Some(Element::ContainerStart {
kind: ContainerKind::Structure,
..
}) => {
out.push(ThermostatAttributeStatusEntryStruct::decode_from(r)?);
}
None => {
return Err(ClusterError::Tlv(
matter_codec::Error::UnclosedContainer,
))
}
Some(Element::ContainerStart { .. }) => r.skip_container()?,
Some(_) => {} }
}
f_attribute_status = Some(out);
}
Some(Element::Scalar {
tag: Tag::Context(2),
value: Value::Uint(v),
}) => {
f_timeout =
Some(u16::try_from(v).map_err(|_| ClusterError::InvalidLength("Timeout"))?)
}
None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
Some(Element::ContainerStart { .. }) => r.skip_container()?,
Some(_) => {} }
}
Ok(Self {
status_code: f_status_code.ok_or(ClusterError::MissingField("StatusCode"))?,
attribute_status: f_attribute_status
.ok_or(ClusterError::MissingField("AttributeStatus"))?,
timeout: f_timeout,
})
}
pub fn decode(tlv: &[u8]) -> Result<Self, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::ContainerStart {
kind: ContainerKind::Structure,
..
}) => {}
_ => {
return Err(ClusterError::UnexpectedType {
context: "AtomicResponse",
})
}
}
Self::decode_from(&mut r)
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_atomic_request(
request_type: u8,
attribute_requests: &Vec<u32>,
timeout: Option<u16>,
) -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.expect("infallible: vec writer");
w.put_uint(Tag::Context(0), u64::from(request_type))
.expect("infallible: vec writer");
w.start_array(Tag::Context(1))
.expect("infallible: vec writer");
for el in attribute_requests.iter().copied() {
w.put_uint(Tag::Anonymous, u64::from(el))
.expect("infallible: vec writer");
}
w.end_container().expect("infallible: vec writer");
if let Some(timeout) = timeout {
w.put_uint(Tag::Context(2), u64::from(timeout))
.expect("infallible: vec writer");
}
w.end_container().expect("infallible: vec writer");
buf
}