#![allow(unused_imports)]
use crate::dm::conformance::{Clause, Condition, Conform, Conformance};
use crate::dm::meta::{EventPriority, Reporting};
use crate::dm::spec::{Attribute, Cluster, Command, Event, Feature};
use crate::dm::{Access, AccessQualities, AttributeQualities, Privilege};
use crate::error::Result;
use crate::im::{AttributeId, ClusterId, CommandId, EventId};
use crate::tlv::{
ContainerKind, Element, FromTlv, Nullable, Tag, TlvList, TlvReader, TlvWriter, ToTlv, Value,
};
pub const ID: ClusterId = 0x0102;
pub const REVISION: u16 = 8;
pub const PICS: &str = "WNCV";
pub mod feature {
pub const LIFT: u32 = 1 << 0;
pub const TILT: u32 = 1 << 1;
pub const POSITION_AWARE_LIFT: u32 = 1 << 2;
pub const POSITION_AWARE_TILT: u32 = 1 << 4;
}
pub const FEATURES: &[Feature] = &[
Feature {
bit: 0,
code: "LF",
name: "Lift",
conform: Conform::OPTIONAL,
},
Feature {
bit: 1,
code: "TL",
name: "Tilt",
conform: Conform::OPTIONAL,
},
Feature {
bit: 2,
code: "PA_LF",
name: "PositionAwareLift",
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Optional,
when: Condition::Feature(0),
}],
},
},
Feature {
bit: 4,
code: "PA_TL",
name: "PositionAwareTilt",
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Optional,
when: Condition::Feature(1),
}],
},
},
];
pub mod attribute {
use crate::im::AttributeId;
pub const TYPE: AttributeId = 0x00;
pub const NUMBER_OF_ACTUATIONS_LIFT: AttributeId = 0x05;
pub const NUMBER_OF_ACTUATIONS_TILT: AttributeId = 0x06;
pub const CONFIG_STATUS: AttributeId = 0x07;
pub const CURRENT_POSITION_LIFT_PERCENTAGE: AttributeId = 0x08;
pub const CURRENT_POSITION_TILT_PERCENTAGE: AttributeId = 0x09;
pub const OPERATIONAL_STATUS: AttributeId = 0x0A;
pub const TARGET_POSITION_LIFT_PERCENT100_THS: AttributeId = 0x0B;
pub const TARGET_POSITION_TILT_PERCENT100_THS: AttributeId = 0x0C;
pub const END_PRODUCT_TYPE: AttributeId = 0x0D;
pub const CURRENT_POSITION_LIFT_PERCENT100_THS: AttributeId = 0x0E;
pub const CURRENT_POSITION_TILT_PERCENT100_THS: AttributeId = 0x0F;
pub const MODE: AttributeId = 0x17;
pub const SAFETY_STATUS: AttributeId = 0x1A;
}
pub mod command {
use crate::im::CommandId;
pub const UP_OR_OPEN: CommandId = 0x00;
pub const DOWN_OR_CLOSE: CommandId = 0x01;
pub const STOP_MOTION: CommandId = 0x02;
pub const GO_TO_LIFT_PERCENTAGE: CommandId = 0x05;
pub const GO_TO_TILT_PERCENTAGE: CommandId = 0x08;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum EndProductTypeEnum {
RollerShade = 0,
RomanShade = 1,
BalloonShade = 2,
WovenWood = 3,
PleatedShade = 4,
CellularShade = 5,
LayeredShade = 6,
LayeredShade2D = 7,
SheerShade = 8,
TiltOnlyInteriorBlind = 9,
InteriorBlind = 10,
VerticalBlindStripCurtain = 11,
InteriorVenetianBlind = 12,
ExteriorVenetianBlind = 13,
LateralLeftCurtain = 14,
LateralRightCurtain = 15,
CentralCurtain = 16,
RollerShutter = 17,
ExteriorVerticalScreen = 18,
AwningTerracePatio = 19,
AwningVerticalScreen = 20,
TiltOnlyPergola = 21,
SwingingShutter = 22,
SlidingShutter = 23,
Unknown = 255,
}
impl EndProductTypeEnum {
#[must_use]
pub const fn from_value(value: u8) -> Option<Self> {
match value {
0 => Some(Self::RollerShade),
1 => Some(Self::RomanShade),
2 => Some(Self::BalloonShade),
3 => Some(Self::WovenWood),
4 => Some(Self::PleatedShade),
5 => Some(Self::CellularShade),
6 => Some(Self::LayeredShade),
7 => Some(Self::LayeredShade2D),
8 => Some(Self::SheerShade),
9 => Some(Self::TiltOnlyInteriorBlind),
10 => Some(Self::InteriorBlind),
11 => Some(Self::VerticalBlindStripCurtain),
12 => Some(Self::InteriorVenetianBlind),
13 => Some(Self::ExteriorVenetianBlind),
14 => Some(Self::LateralLeftCurtain),
15 => Some(Self::LateralRightCurtain),
16 => Some(Self::CentralCurtain),
17 => Some(Self::RollerShutter),
18 => Some(Self::ExteriorVerticalScreen),
19 => Some(Self::AwningTerracePatio),
20 => Some(Self::AwningVerticalScreen),
21 => Some(Self::TiltOnlyPergola),
22 => Some(Self::SwingingShutter),
23 => Some(Self::SlidingShutter),
255 => Some(Self::Unknown),
_ => None,
}
}
#[must_use]
pub const fn value(self) -> u8 {
self as u8
}
}
impl ToTlv for EndProductTypeEnum {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
self.value().to_tlv(w, tag)
}
}
impl<'a> FromTlv<'a> for EndProductTypeEnum {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum TypeEnum {
RollerShade = 0,
RollerShade2Motor = 1,
RollerShadeExterior = 2,
RollerShadeExterior2Motor = 3,
Drapery = 4,
Awning = 5,
Shutter = 6,
TiltBlindTiltOnly = 7,
TiltBlindLiftAndTilt = 8,
ProjectorScreen = 9,
Unknown = 255,
}
impl TypeEnum {
#[must_use]
pub const fn from_value(value: u8) -> Option<Self> {
match value {
0 => Some(Self::RollerShade),
1 => Some(Self::RollerShade2Motor),
2 => Some(Self::RollerShadeExterior),
3 => Some(Self::RollerShadeExterior2Motor),
4 => Some(Self::Drapery),
5 => Some(Self::Awning),
6 => Some(Self::Shutter),
7 => Some(Self::TiltBlindTiltOnly),
8 => Some(Self::TiltBlindLiftAndTilt),
9 => Some(Self::ProjectorScreen),
255 => Some(Self::Unknown),
_ => None,
}
}
#[must_use]
pub const fn value(self) -> u8 {
self as u8
}
}
impl ToTlv for TypeEnum {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
self.value().to_tlv(w, tag)
}
}
impl<'a> FromTlv<'a> for TypeEnum {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
}
}
bitflags::bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct ConfigStatusBitmap: u8 {
const OPERATIONAL = 1 << 0;
const ONLINE_RESERVED = 1 << 1;
const LIFT_MOVEMENT_REVERSED = 1 << 2;
const LIFT_POSITION_AWARE = 1 << 3;
const TILT_POSITION_AWARE = 1 << 4;
const LIFT_ENCODER_CONTROLLED = 1 << 5;
const TILT_ENCODER_CONTROLLED = 1 << 6;
}
}
impl ToTlv for ConfigStatusBitmap {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
self.bits().to_tlv(w, tag)
}
}
impl<'a> FromTlv<'a> for ConfigStatusBitmap {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
let bits = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
}
}
bitflags::bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct ModeBitmap: u8 {
const MOTOR_DIRECTION_REVERSED = 1 << 0;
const CALIBRATION_MODE = 1 << 1;
const MAINTENANCE_MODE = 1 << 2;
const LED_FEEDBACK = 1 << 3;
}
}
impl ToTlv for ModeBitmap {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
self.bits().to_tlv(w, tag)
}
}
impl<'a> FromTlv<'a> for ModeBitmap {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
let bits = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
}
}
bitflags::bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct OperationalStatusBitmap: u8 {
}
}
impl ToTlv for OperationalStatusBitmap {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
self.bits().to_tlv(w, tag)
}
}
impl<'a> FromTlv<'a> for OperationalStatusBitmap {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
let bits = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
}
}
bitflags::bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct SafetyStatusBitmap: u16 {
const REMOTE_LOCKOUT = 1 << 0;
const TAMPER_DETECTION = 1 << 1;
const FAILED_COMMUNICATION = 1 << 2;
const POSITION_FAILURE = 1 << 3;
const THERMAL_PROTECTION = 1 << 4;
const OBSTACLE_DETECTED = 1 << 5;
const POWER = 1 << 6;
const STOP_INPUT = 1 << 7;
const MOTOR_JAMMED = 1 << 8;
const HARDWARE_FAILURE = 1 << 9;
const MANUAL_OPERATION = 1 << 10;
const PROTECTION = 1 << 11;
}
}
impl ToTlv for SafetyStatusBitmap {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
self.bits().to_tlv(w, tag)
}
}
impl<'a> FromTlv<'a> for SafetyStatusBitmap {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
let bits = <u16 as FromTlv<'a>>::from_tlv(reader, element)?;
Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct GoToLiftPercentageFields {
pub lift_percent100_ths_value: u16,
}
impl ToTlv for GoToLiftPercentageFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.lift_percent100_ths_value.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for GoToLiftPercentageFields {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut lift_percent100_ths_value = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => lift_percent100_ths_value = Some(<u16>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
lift_percent100_ths_value: lift_percent100_ths_value
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct GoToTiltPercentageFields {
pub tilt_percent100_ths_value: u16,
}
impl ToTlv for GoToTiltPercentageFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.tilt_percent100_ths_value.to_tlv(w, Tag::Context(0))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for GoToTiltPercentageFields {
fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
if element.value.container() != Some(ContainerKind::Structure) {
return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
}
let mut tilt_percent100_ths_value = None;
loop {
let Some(field) = reader.next_element()? else {
return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
};
if field.value == Value::EndOfContainer {
break;
}
match field.tag.context() {
Some(0) => tilt_percent100_ths_value = Some(<u16>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
tilt_percent100_ths_value: tilt_percent100_ths_value
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
pub const ATTRIBUTES: &[Attribute] = &[
Attribute {
id: 0x0000,
name: "Type",
kind: "TypeEnum",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::FIXED,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x0005,
name: "NumberOfActuationsLift",
kind: "uint16",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NON_VOLATILE,
reporting: Reporting::OnChange,
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Optional,
when: Condition::Feature(0),
}],
},
},
Attribute {
id: 0x0006,
name: "NumberOfActuationsTilt",
kind: "uint16",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NON_VOLATILE,
reporting: Reporting::OnChange,
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Optional,
when: Condition::Feature(1),
}],
},
},
Attribute {
id: 0x0007,
name: "ConfigStatus",
kind: "ConfigStatusBitmap",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NON_VOLATILE,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x0008,
name: "CurrentPositionLiftPercentage",
kind: "percent",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NULLABLE.union(AttributeQualities::NON_VOLATILE),
reporting: Reporting::OnChange,
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Optional,
when: Condition::All(&[Condition::Feature(0), Condition::Feature(2)]),
}],
},
},
Attribute {
id: 0x0009,
name: "CurrentPositionTiltPercentage",
kind: "percent",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NULLABLE.union(AttributeQualities::NON_VOLATILE),
reporting: Reporting::OnChange,
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Optional,
when: Condition::All(&[Condition::Feature(1), Condition::Feature(4)]),
}],
},
},
Attribute {
id: 0x000A,
name: "OperationalStatus",
kind: "OperationalStatusBitmap",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::empty(),
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x000B,
name: "TargetPositionLiftPercent100ths",
kind: "percent100ths",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NULLABLE,
reporting: Reporting::OnChange,
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::All(&[Condition::Feature(0), Condition::Feature(2)]),
}],
},
},
Attribute {
id: 0x000C,
name: "TargetPositionTiltPercent100ths",
kind: "percent100ths",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NULLABLE,
reporting: Reporting::OnChange,
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::All(&[Condition::Feature(1), Condition::Feature(4)]),
}],
},
},
Attribute {
id: 0x000D,
name: "EndProductType",
kind: "EndProductTypeEnum",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::FIXED,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x000E,
name: "CurrentPositionLiftPercent100ths",
kind: "percent100ths",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NULLABLE.union(AttributeQualities::NON_VOLATILE),
reporting: Reporting::OnChange,
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::All(&[Condition::Feature(0), Condition::Feature(2)]),
}],
},
},
Attribute {
id: 0x000F,
name: "CurrentPositionTiltPercent100ths",
kind: "percent100ths",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::NULLABLE.union(AttributeQualities::NON_VOLATILE),
reporting: Reporting::OnChange,
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Mandatory,
when: Condition::All(&[Condition::Feature(1), Condition::Feature(4)]),
}],
},
},
Attribute {
id: 0x0017,
name: "Mode",
kind: "ModeBitmap",
access: Access::read_write_with(Privilege::View, Privilege::Manage),
qualities: AttributeQualities::NON_VOLATILE,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x001A,
name: "SafetyStatus",
kind: "SafetyStatusBitmap",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::empty(),
reporting: Reporting::OnChange,
conform: Conform::OPTIONAL,
},
];
pub const COMMANDS: &[Command] = &[
Command {
id: 0x00,
name: "UpOrOpen",
to_server: true,
response: None,
access: Access::invoke(Privilege::Operate),
conform: Conform::MANDATORY,
},
Command {
id: 0x01,
name: "DownOrClose",
to_server: true,
response: None,
access: Access::invoke(Privilege::Operate),
conform: Conform::MANDATORY,
},
Command {
id: 0x02,
name: "StopMotion",
to_server: true,
response: None,
access: Access::invoke(Privilege::Operate),
conform: Conform::MANDATORY,
},
Command {
id: 0x05,
name: "GoToLiftPercentage",
to_server: true,
response: None,
access: Access::invoke(Privilege::Operate),
conform: Conform {
clauses: &[
Clause {
verdict: Conformance::Mandatory,
when: Condition::All(&[Condition::Feature(0), Condition::Feature(2)]),
},
Clause {
verdict: Conformance::Optional,
when: Condition::Feature(0),
},
],
},
},
Command {
id: 0x08,
name: "GoToTiltPercentage",
to_server: true,
response: None,
access: Access::invoke(Privilege::Operate),
conform: Conform {
clauses: &[
Clause {
verdict: Conformance::Mandatory,
when: Condition::All(&[Condition::Feature(1), Condition::Feature(4)]),
},
Clause {
verdict: Conformance::Optional,
when: Condition::Feature(1),
},
],
},
},
];
pub const EVENTS: &[Event] = &[];
pub const CLUSTER: Cluster = Cluster {
id: ID,
name: "Window Covering",
revision: REVISION,
pics: "WNCV",
derived_from: None,
features: FEATURES,
attributes: ATTRIBUTES,
commands: COMMANDS,
events: EVENTS,
};