#![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 = 0x0406;
pub const CLUSTER_REVISION: u16 = 6;
pub mod command_id {}
pub mod attribute_id {
pub const OCCUPANCY: u32 = 0x0000;
pub const OCCUPANCY_SENSOR_TYPE: u32 = 0x0001;
pub const OCCUPANCY_SENSOR_TYPE_BITMAP: u32 = 0x0002;
pub const HOLD_TIME: u32 = 0x0003;
pub const HOLD_TIME_LIMITS: u32 = 0x0004;
pub const PIR_OCCUPIED_TO_UNOCCUPIED_DELAY: u32 = 0x0010;
pub const PIR_UNOCCUPIED_TO_OCCUPIED_DELAY: u32 = 0x0011;
pub const PIR_UNOCCUPIED_TO_OCCUPIED_THRESHOLD: u32 = 0x0012;
pub const ULTRASONIC_OCCUPIED_TO_UNOCCUPIED_DELAY: u32 = 0x0020;
pub const ULTRASONIC_UNOCCUPIED_TO_OCCUPIED_DELAY: u32 = 0x0021;
pub const ULTRASONIC_UNOCCUPIED_TO_OCCUPIED_THRESHOLD: u32 = 0x0022;
pub const PHYSICAL_CONTACT_OCCUPIED_TO_UNOCCUPIED_DELAY: u32 = 0x0030;
pub const PHYSICAL_CONTACT_UNOCCUPIED_TO_OCCUPIED_DELAY: u32 = 0x0031;
pub const PHYSICAL_CONTACT_UNOCCUPIED_TO_OCCUPIED_THRESHOLD: u32 = 0x0032;
}
bitflags::bitflags! {
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct Feature: u32 {
const OTHER = 1 << 0;
const PIR = 1 << 1;
const US = 1 << 2;
const PHY = 1 << 3;
const AIR = 1 << 4;
const RAD = 1 << 5;
const RFS = 1 << 6;
const VIS = 1 << 7;
}
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub struct HoldTimeLimitsStruct {
pub hold_time_min: u16,
pub hold_time_max: u16,
pub hold_time_default: u16,
}
bitflags::bitflags! {
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct OccupancyBitmap: u8 {
const OCCUPIED = 1 << 0;
}
}
bitflags::bitflags! {
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct OccupancySensorTypeBitmap: u8 {
const PIR = 1 << 0;
const ULTRASONIC = 1 << 1;
const PHYSICAL_CONTACT = 1 << 2;
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum OccupancySensorTypeEnum {
Pir,
Ultrasonic,
PirAndUltrasonic,
PhysicalContact,
Unknown(u8),
}
impl OccupancySensorTypeEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Pir,
1 => Self::Ultrasonic,
2 => Self::PirAndUltrasonic,
3 => Self::PhysicalContact,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Pir => 0,
Self::Ultrasonic => 1,
Self::PirAndUltrasonic => 2,
Self::PhysicalContact => 3,
Self::Unknown(v) => v,
}
}
}
impl HoldTimeLimitsStruct {
pub fn decode_from(r: &mut TlvReader<'_>) -> Result<Self, ClusterError> {
let mut f_hold_time_min: Option<u16> = None;
let mut f_hold_time_max: Option<u16> = None;
let mut f_hold_time_default: Option<u16> = None;
loop {
match r.next()? {
Some(Element::ContainerEnd) => break,
Some(Element::Scalar {
tag: Tag::Context(0),
value: Value::Uint(v),
}) => {
f_hold_time_min = Some(
u16::try_from(v).map_err(|_| ClusterError::InvalidLength("HoldTimeMin"))?,
)
}
Some(Element::Scalar {
tag: Tag::Context(1),
value: Value::Uint(v),
}) => {
f_hold_time_max = Some(
u16::try_from(v).map_err(|_| ClusterError::InvalidLength("HoldTimeMax"))?,
)
}
Some(Element::Scalar {
tag: Tag::Context(2),
value: Value::Uint(v),
}) => {
f_hold_time_default = Some(
u16::try_from(v)
.map_err(|_| ClusterError::InvalidLength("HoldTimeDefault"))?,
)
}
None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
Some(Element::ContainerStart { .. }) => r.skip_container()?,
Some(_) => {} }
}
Ok(Self {
hold_time_min: f_hold_time_min.ok_or(ClusterError::MissingField("HoldTimeMin"))?,
hold_time_max: f_hold_time_max.ok_or(ClusterError::MissingField("HoldTimeMax"))?,
hold_time_default: f_hold_time_default
.ok_or(ClusterError::MissingField("HoldTimeDefault"))?,
})
}
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: "HoldTimeLimitsStruct",
})
}
}
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.hold_time_min))
.expect("infallible: vec writer");
w.put_uint(Tag::Context(1), u64::from(self.hold_time_max))
.expect("infallible: vec writer");
w.put_uint(Tag::Context(2), u64::from(self.hold_time_default))
.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_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_occupancy_sensor_type(tlv: &[u8]) -> Result<OccupancySensorTypeEnum, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(OccupancySensorTypeEnum::from_raw(u8::try_from(v).map_err(
|_| ClusterError::InvalidLength("OccupancySensorType"),
)?)),
_ => Err(ClusterError::UnexpectedType {
context: "OccupancySensorType",
}),
}
}
pub fn decode_occupancy_sensor_type_bitmap(
tlv: &[u8],
) -> Result<OccupancySensorTypeBitmap, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(OccupancySensorTypeBitmap::from_bits_retain(
u8::try_from(v)
.map_err(|_| ClusterError::InvalidLength("OccupancySensorTypeBitmap"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "OccupancySensorTypeBitmap",
}),
}
}
pub fn decode_hold_time(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("HoldTime"))?),
_ => Err(ClusterError::UnexpectedType {
context: "HoldTime",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_hold_time(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_hold_time_limits(tlv: &[u8]) -> Result<HoldTimeLimitsStruct, ClusterError> {
HoldTimeLimitsStruct::decode(tlv)
}
pub fn decode_pir_occupied_to_unoccupied_delay(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("PirOccupiedToUnoccupiedDelay"))?),
_ => Err(ClusterError::UnexpectedType {
context: "PirOccupiedToUnoccupiedDelay",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_pir_occupied_to_unoccupied_delay(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_pir_unoccupied_to_occupied_delay(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("PirUnoccupiedToOccupiedDelay"))?),
_ => Err(ClusterError::UnexpectedType {
context: "PirUnoccupiedToOccupiedDelay",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_pir_unoccupied_to_occupied_delay(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_pir_unoccupied_to_occupied_threshold(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("PirUnoccupiedToOccupiedThreshold"))?),
_ => Err(ClusterError::UnexpectedType {
context: "PirUnoccupiedToOccupiedThreshold",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_pir_unoccupied_to_occupied_threshold(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_ultrasonic_occupied_to_unoccupied_delay(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("UltrasonicOccupiedToUnoccupiedDelay"))?),
_ => Err(ClusterError::UnexpectedType {
context: "UltrasonicOccupiedToUnoccupiedDelay",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_ultrasonic_occupied_to_unoccupied_delay(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_ultrasonic_unoccupied_to_occupied_delay(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("UltrasonicUnoccupiedToOccupiedDelay"))?),
_ => Err(ClusterError::UnexpectedType {
context: "UltrasonicUnoccupiedToOccupiedDelay",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_ultrasonic_unoccupied_to_occupied_delay(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_ultrasonic_unoccupied_to_occupied_threshold(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("UltrasonicUnoccupiedToOccupiedThreshold"))?),
_ => Err(ClusterError::UnexpectedType {
context: "UltrasonicUnoccupiedToOccupiedThreshold",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_ultrasonic_unoccupied_to_occupied_threshold(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_physical_contact_occupied_to_unoccupied_delay(
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("PhysicalContactOccupiedToUnoccupiedDelay")
})?),
_ => Err(ClusterError::UnexpectedType {
context: "PhysicalContactOccupiedToUnoccupiedDelay",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_physical_contact_occupied_to_unoccupied_delay(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_physical_contact_unoccupied_to_occupied_delay(
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("PhysicalContactUnoccupiedToOccupiedDelay")
})?),
_ => Err(ClusterError::UnexpectedType {
context: "PhysicalContactUnoccupiedToOccupiedDelay",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_physical_contact_unoccupied_to_occupied_delay(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_physical_contact_unoccupied_to_occupied_threshold(
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("PhysicalContactUnoccupiedToOccupiedThreshold")
})?),
_ => Err(ClusterError::UnexpectedType {
context: "PhysicalContactUnoccupiedToOccupiedThreshold",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_physical_contact_unoccupied_to_occupied_threshold(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
}