#![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 = 0x0202;
pub const CLUSTER_REVISION: u16 = 6;
pub mod command_id {
pub const STEP: u32 = 0x00;
}
pub mod attribute_id {
pub const FAN_MODE: u32 = 0x0000;
pub const FAN_MODE_SEQUENCE: u32 = 0x0001;
pub const PERCENT_SETTING: u32 = 0x0002;
pub const PERCENT_CURRENT: u32 = 0x0003;
pub const SPEED_MAX: u32 = 0x0004;
pub const SPEED_SETTING: u32 = 0x0005;
pub const SPEED_CURRENT: u32 = 0x0006;
pub const ROCK_SUPPORT: u32 = 0x0007;
pub const ROCK_SETTING: u32 = 0x0008;
pub const WIND_SUPPORT: u32 = 0x0009;
pub const WIND_SETTING: u32 = 0x000A;
pub const AIRFLOW_DIRECTION: u32 = 0x000B;
}
bitflags::bitflags! {
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct Feature: u32 {
const SPD = 1 << 0;
const AUT = 1 << 1;
const RCK = 1 << 2;
const WND = 1 << 3;
const STEP = 1 << 4;
const DIR = 1 << 5;
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum AirflowDirectionEnum {
Forward,
Reverse,
Unknown(u8),
}
impl AirflowDirectionEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Forward,
1 => Self::Reverse,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Forward => 0,
Self::Reverse => 1,
Self::Unknown(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum FanModeEnum {
Off,
Low,
Medium,
High,
On,
Auto,
Smart,
Unknown(u8),
}
impl FanModeEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Off,
1 => Self::Low,
2 => Self::Medium,
3 => Self::High,
4 => Self::On,
5 => Self::Auto,
6 => Self::Smart,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Off => 0,
Self::Low => 1,
Self::Medium => 2,
Self::High => 3,
Self::On => 4,
Self::Auto => 5,
Self::Smart => 6,
Self::Unknown(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum FanModeSequenceEnum {
OffLowMedHigh,
OffLowHigh,
OffLowMedHighAuto,
OffLowHighAuto,
OffHighAuto,
OffHigh,
Unknown(u8),
}
impl FanModeSequenceEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::OffLowMedHigh,
1 => Self::OffLowHigh,
2 => Self::OffLowMedHighAuto,
3 => Self::OffLowHighAuto,
4 => Self::OffHighAuto,
5 => Self::OffHigh,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::OffLowMedHigh => 0,
Self::OffLowHigh => 1,
Self::OffLowMedHighAuto => 2,
Self::OffLowHighAuto => 3,
Self::OffHighAuto => 4,
Self::OffHigh => 5,
Self::Unknown(v) => v,
}
}
}
bitflags::bitflags! {
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct RockBitmap: u8 {
const ROCK_LEFT_RIGHT = 1 << 0;
const ROCK_UP_DOWN = 1 << 1;
const ROCK_ROUND = 1 << 2;
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum StepDirectionEnum {
Increase,
Decrease,
Unknown(u8),
}
impl StepDirectionEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Increase,
1 => Self::Decrease,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Increase => 0,
Self::Decrease => 1,
Self::Unknown(v) => v,
}
}
}
bitflags::bitflags! {
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct WindBitmap: u8 {
const SLEEP_WIND = 1 << 0;
const NATURAL_WIND = 1 << 1;
}
}
pub fn decode_fan_mode(tlv: &[u8]) -> Result<FanModeEnum, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(FanModeEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("FanMode"))?,
)),
_ => Err(ClusterError::UnexpectedType { context: "FanMode" }),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_fan_mode(value: FanModeEnum) -> 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_fan_mode_sequence(tlv: &[u8]) -> Result<FanModeSequenceEnum, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(FanModeSequenceEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("FanModeSequence"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "FanModeSequence",
}),
}
}
pub fn decode_percent_setting(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("PercentSetting")
})?))
}
_ => Err(ClusterError::UnexpectedType {
context: "PercentSetting",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_percent_setting(value: Nullable<u8>) -> 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_percent_current(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("PercentCurrent"))?),
_ => Err(ClusterError::UnexpectedType {
context: "PercentCurrent",
}),
}
}
pub fn decode_speed_max(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("SpeedMax"))?),
_ => Err(ClusterError::UnexpectedType {
context: "SpeedMax",
}),
}
}
pub fn decode_speed_setting(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("SpeedSetting")
})?))
}
_ => Err(ClusterError::UnexpectedType {
context: "SpeedSetting",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_speed_setting(value: Nullable<u8>) -> 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_speed_current(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("SpeedCurrent"))?),
_ => Err(ClusterError::UnexpectedType {
context: "SpeedCurrent",
}),
}
}
pub fn decode_rock_support(tlv: &[u8]) -> Result<RockBitmap, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(RockBitmap::from_bits_retain(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("RockSupport"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "RockSupport",
}),
}
}
pub fn decode_rock_setting(tlv: &[u8]) -> Result<RockBitmap, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(RockBitmap::from_bits_retain(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("RockSetting"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "RockSetting",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_rock_setting(value: RockBitmap) -> 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_wind_support(tlv: &[u8]) -> Result<WindBitmap, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(WindBitmap::from_bits_retain(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("WindSupport"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "WindSupport",
}),
}
}
pub fn decode_wind_setting(tlv: &[u8]) -> Result<WindBitmap, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(WindBitmap::from_bits_retain(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("WindSetting"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "WindSetting",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_wind_setting(value: WindBitmap) -> 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_airflow_direction(tlv: &[u8]) -> Result<AirflowDirectionEnum, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(AirflowDirectionEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("AirflowDirection"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "AirflowDirection",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_airflow_direction(value: AirflowDirectionEnum) -> 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
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_step(
direction: StepDirectionEnum,
wrap: Option<bool>,
lowest_off: Option<bool>,
) -> 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(direction.to_raw()))
.expect("infallible: vec writer");
if let Some(wrap) = wrap {
w.put_bool(Tag::Context(1), wrap)
.expect("infallible: vec writer");
}
if let Some(lowest_off) = lowest_off {
w.put_bool(Tag::Context(2), lowest_off)
.expect("infallible: vec writer");
}
w.end_container().expect("infallible: vec writer");
buf
}