#![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 = 0x0006;
pub const CLUSTER_REVISION: u16 = 6;
pub mod command_id {
pub const OFF: u32 = 0x00;
pub const ON: u32 = 0x01;
pub const TOGGLE: u32 = 0x02;
pub const OFF_WITH_EFFECT: u32 = 0x40;
pub const ON_WITH_RECALL_GLOBAL_SCENE: u32 = 0x41;
pub const ON_WITH_TIMED_OFF: u32 = 0x42;
}
pub mod attribute_id {
pub const ON_OFF: u32 = 0x0000;
pub const GLOBAL_SCENE_CONTROL: u32 = 0x4000;
pub const ON_TIME: u32 = 0x4001;
pub const OFF_WAIT_TIME: u32 = 0x4002;
pub const START_UP_ON_OFF: u32 = 0x4003;
}
bitflags::bitflags! {
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct Feature: u32 {
const LT = 1 << 0;
const DF = 1 << 1;
const OFFONLY = 1 << 2;
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum DelayedAllOffEffectVariantEnum {
DelayedOffFastFade,
NoFade,
DelayedOffSlowFade,
Unknown(u8),
}
impl DelayedAllOffEffectVariantEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::DelayedOffFastFade,
1 => Self::NoFade,
2 => Self::DelayedOffSlowFade,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::DelayedOffFastFade => 0,
Self::NoFade => 1,
Self::DelayedOffSlowFade => 2,
Self::Unknown(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum DyingLightEffectVariantEnum {
DyingLightFadeOff,
Unknown(u8),
}
impl DyingLightEffectVariantEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::DyingLightFadeOff,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::DyingLightFadeOff => 0,
Self::Unknown(v) => v,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum EffectIdentifierEnum {
DelayedAllOff,
DyingLight,
Unknown(u8),
}
impl EffectIdentifierEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::DelayedAllOff,
1 => Self::DyingLight,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::DelayedAllOff => 0,
Self::DyingLight => 1,
Self::Unknown(v) => v,
}
}
}
bitflags::bitflags! {
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct OnOffControlBitmap: u8 {
const ACCEPT_ONLY_WHEN_ON = 1 << 0;
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum StartUpOnOffEnum {
Off,
On,
Toggle,
Unknown(u8),
}
impl StartUpOnOffEnum {
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Off,
1 => Self::On,
2 => Self::Toggle,
other => Self::Unknown(other),
}
}
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Off => 0,
Self::On => 1,
Self::Toggle => 2,
Self::Unknown(v) => v,
}
}
}
pub fn decode_on_off(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: "OnOff" }),
}
}
pub fn decode_global_scene_control(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: "GlobalSceneControl",
}),
}
}
pub fn decode_on_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("OnTime"))?),
_ => Err(ClusterError::UnexpectedType { context: "OnTime" }),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_on_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_off_wait_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("OffWaitTime"))?),
_ => Err(ClusterError::UnexpectedType {
context: "OffWaitTime",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_off_wait_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_start_up_on_off(tlv: &[u8]) -> Result<Nullable<StartUpOnOffEnum>, 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(StartUpOnOffEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("StartUpOnOff"))?,
))),
_ => Err(ClusterError::UnexpectedType {
context: "StartUpOnOff",
}),
}
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_start_up_on_off(value: Nullable<StartUpOnOffEnum>) -> 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.to_raw()))
.expect("infallible: vec writer");
}
}
buf
}
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_off() -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.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_on() -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.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_toggle() -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.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_off_with_effect(
effect_identifier: EffectIdentifierEnum,
effect_variant: 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_uint(Tag::Context(0), u64::from(effect_identifier.to_raw()))
.expect("infallible: vec writer");
w.put_uint(Tag::Context(1), u64::from(effect_variant))
.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_on_with_recall_global_scene() -> Vec<u8> {
let mut buf = Vec::new();
let mut w = TlvWriter::new(&mut buf);
w.start_structure(Tag::Anonymous)
.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_on_with_timed_off(
on_off_control: OnOffControlBitmap,
on_time: u16,
off_wait_time: 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(on_off_control.bits()))
.expect("infallible: vec writer");
w.put_uint(Tag::Context(1), u64::from(on_time))
.expect("infallible: vec writer");
w.put_uint(Tag::Context(2), u64::from(off_wait_time))
.expect("infallible: vec writer");
w.end_container().expect("infallible: vec writer");
buf
}