#![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 = 0x0025;
pub const REVISION: u16 = 1;
pub const PICS: &str = "ACT";
pub const FEATURES: &[Feature] = &[];
pub mod attribute {
use crate::im::AttributeId;
pub const ACTION_LIST: AttributeId = 0x00;
pub const ENDPOINT_LISTS: AttributeId = 0x01;
pub const SETUP_URL: AttributeId = 0x02;
}
pub mod command {
use crate::im::CommandId;
pub const INSTANT_ACTION: CommandId = 0x00;
pub const INSTANT_ACTION_WITH_TRANSITION: CommandId = 0x01;
pub const START_ACTION: CommandId = 0x02;
pub const START_ACTION_WITH_DURATION: CommandId = 0x03;
pub const STOP_ACTION: CommandId = 0x04;
pub const PAUSE_ACTION: CommandId = 0x05;
pub const PAUSE_ACTION_WITH_DURATION: CommandId = 0x06;
pub const RESUME_ACTION: CommandId = 0x07;
pub const ENABLE_ACTION: CommandId = 0x08;
pub const ENABLE_ACTION_WITH_DURATION: CommandId = 0x09;
pub const DISABLE_ACTION: CommandId = 0x0A;
pub const DISABLE_ACTION_WITH_DURATION: CommandId = 0x0B;
}
pub mod event {
use crate::im::EventId;
pub const STATE_CHANGED: EventId = 0x00;
pub const ACTION_FAILED: EventId = 0x01;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum ActionErrorEnum {
Unknown = 0,
Interrupted = 1,
}
impl ActionErrorEnum {
#[must_use]
pub const fn from_value(value: u8) -> Option<Self> {
match value {
0 => Some(Self::Unknown),
1 => Some(Self::Interrupted),
_ => None,
}
}
#[must_use]
pub const fn value(self) -> u8 {
self as u8
}
}
impl ToTlv for ActionErrorEnum {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
self.value().to_tlv(w, tag)
}
}
impl<'a> FromTlv<'a> for ActionErrorEnum {
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 ActionStateEnum {
Inactive = 0,
Active = 1,
Paused = 2,
Disabled = 3,
}
impl ActionStateEnum {
#[must_use]
pub const fn from_value(value: u8) -> Option<Self> {
match value {
0 => Some(Self::Inactive),
1 => Some(Self::Active),
2 => Some(Self::Paused),
3 => Some(Self::Disabled),
_ => None,
}
}
#[must_use]
pub const fn value(self) -> u8 {
self as u8
}
}
impl ToTlv for ActionStateEnum {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
self.value().to_tlv(w, tag)
}
}
impl<'a> FromTlv<'a> for ActionStateEnum {
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 ActionTypeEnum {
Other = 0,
Scene = 1,
Sequence = 2,
Automation = 3,
Exception = 4,
Notification = 5,
Alarm = 6,
}
impl ActionTypeEnum {
#[must_use]
pub const fn from_value(value: u8) -> Option<Self> {
match value {
0 => Some(Self::Other),
1 => Some(Self::Scene),
2 => Some(Self::Sequence),
3 => Some(Self::Automation),
4 => Some(Self::Exception),
5 => Some(Self::Notification),
6 => Some(Self::Alarm),
_ => None,
}
}
#[must_use]
pub const fn value(self) -> u8 {
self as u8
}
}
impl ToTlv for ActionTypeEnum {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
self.value().to_tlv(w, tag)
}
}
impl<'a> FromTlv<'a> for ActionTypeEnum {
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 EndpointListTypeEnum {
Other = 0,
Room = 1,
Zone = 2,
}
impl EndpointListTypeEnum {
#[must_use]
pub const fn from_value(value: u8) -> Option<Self> {
match value {
0 => Some(Self::Other),
1 => Some(Self::Room),
2 => Some(Self::Zone),
_ => None,
}
}
#[must_use]
pub const fn value(self) -> u8 {
self as u8
}
}
impl ToTlv for EndpointListTypeEnum {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
self.value().to_tlv(w, tag)
}
}
impl<'a> FromTlv<'a> for EndpointListTypeEnum {
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 CommandBits: u16 {
const INSTANT_ACTION = 1 << 0;
const INSTANT_ACTION_WITH_TRANSITION = 1 << 1;
const START_ACTION = 1 << 2;
const START_ACTION_WITH_DURATION = 1 << 3;
const STOP_ACTION = 1 << 4;
const PAUSE_ACTION = 1 << 5;
const PAUSE_ACTION_WITH_DURATION = 1 << 6;
const RESUME_ACTION = 1 << 7;
const ENABLE_ACTION = 1 << 8;
const ENABLE_ACTION_WITH_DURATION = 1 << 9;
const DISABLE_ACTION = 1 << 10;
const DISABLE_ACTION_WITH_DURATION = 1 << 11;
}
}
impl ToTlv for CommandBits {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
self.bits().to_tlv(w, tag)
}
}
impl<'a> FromTlv<'a> for CommandBits {
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 ActionStruct<'a> {
pub action_id: u16,
pub name: &'a str,
pub type_: ActionTypeEnum,
pub endpoint_list_id: u16,
pub supported_commands: CommandBits,
pub state: ActionStateEnum,
}
impl<'a> ToTlv for ActionStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.action_id.to_tlv(w, Tag::Context(0))?;
self.name.to_tlv(w, Tag::Context(1))?;
self.type_.to_tlv(w, Tag::Context(2))?;
self.endpoint_list_id.to_tlv(w, Tag::Context(3))?;
self.supported_commands.to_tlv(w, Tag::Context(4))?;
self.state.to_tlv(w, Tag::Context(5))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for ActionStruct<'a> {
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 action_id = None;
let mut name = None;
let mut type_ = None;
let mut endpoint_list_id = None;
let mut supported_commands = None;
let mut state = 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) => action_id = Some(<u16>::from_tlv(reader, &field)?),
Some(1) => name = Some(<&'a str>::from_tlv(reader, &field)?),
Some(2) => type_ = Some(<ActionTypeEnum>::from_tlv(reader, &field)?),
Some(3) => endpoint_list_id = Some(<u16>::from_tlv(reader, &field)?),
Some(4) => supported_commands = Some(<CommandBits>::from_tlv(reader, &field)?),
Some(5) => state = Some(<ActionStateEnum>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
action_id: action_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
name: name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
type_: type_.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
endpoint_list_id: endpoint_list_id
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
supported_commands: supported_commands
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
state: state.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct EndpointListStruct<'a> {
pub endpoint_list_id: u16,
pub name: &'a str,
pub type_: EndpointListTypeEnum,
pub endpoints: TlvList<'a, u16>,
}
impl<'a> ToTlv for EndpointListStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.endpoint_list_id.to_tlv(w, Tag::Context(0))?;
self.name.to_tlv(w, Tag::Context(1))?;
self.type_.to_tlv(w, Tag::Context(2))?;
self.endpoints.to_tlv(w, Tag::Context(3))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for EndpointListStruct<'a> {
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 endpoint_list_id = None;
let mut name = None;
let mut type_ = None;
let mut endpoints = 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) => endpoint_list_id = Some(<u16>::from_tlv(reader, &field)?),
Some(1) => name = Some(<&'a str>::from_tlv(reader, &field)?),
Some(2) => type_ = Some(<EndpointListTypeEnum>::from_tlv(reader, &field)?),
Some(3) => endpoints = Some(<TlvList<'a, u16>>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
endpoint_list_id: endpoint_list_id
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
name: name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
type_: type_.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
endpoints: endpoints.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct InstantActionFields {
pub action_id: u16,
pub invoke_id: Option<u32>,
}
impl ToTlv for InstantActionFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.action_id.to_tlv(w, Tag::Context(0))?;
if let Some(value) = &self.invoke_id {
value.to_tlv(w, Tag::Context(1))?;
}
w.end_container()
}
}
impl<'a> FromTlv<'a> for InstantActionFields {
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 action_id = None;
let mut invoke_id = 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) => action_id = Some(<u16>::from_tlv(reader, &field)?),
Some(1) => invoke_id = Some(<u32>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
action_id: action_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
invoke_id,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct InstantActionWithTransitionFields {
pub action_id: u16,
pub invoke_id: Option<u32>,
pub transition_time: u16,
}
impl ToTlv for InstantActionWithTransitionFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.action_id.to_tlv(w, Tag::Context(0))?;
if let Some(value) = &self.invoke_id {
value.to_tlv(w, Tag::Context(1))?;
}
self.transition_time.to_tlv(w, Tag::Context(2))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for InstantActionWithTransitionFields {
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 action_id = None;
let mut invoke_id = None;
let mut transition_time = 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) => action_id = Some(<u16>::from_tlv(reader, &field)?),
Some(1) => invoke_id = Some(<u32>::from_tlv(reader, &field)?),
Some(2) => transition_time = Some(<u16>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
action_id: action_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
invoke_id,
transition_time: transition_time
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct StartActionFields {
pub action_id: u16,
pub invoke_id: Option<u32>,
}
impl ToTlv for StartActionFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.action_id.to_tlv(w, Tag::Context(0))?;
if let Some(value) = &self.invoke_id {
value.to_tlv(w, Tag::Context(1))?;
}
w.end_container()
}
}
impl<'a> FromTlv<'a> for StartActionFields {
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 action_id = None;
let mut invoke_id = 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) => action_id = Some(<u16>::from_tlv(reader, &field)?),
Some(1) => invoke_id = Some(<u32>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
action_id: action_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
invoke_id,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct StartActionWithDurationFields {
pub action_id: u16,
pub invoke_id: Option<u32>,
pub duration: u32,
}
impl ToTlv for StartActionWithDurationFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.action_id.to_tlv(w, Tag::Context(0))?;
if let Some(value) = &self.invoke_id {
value.to_tlv(w, Tag::Context(1))?;
}
self.duration.to_tlv(w, Tag::Context(2))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for StartActionWithDurationFields {
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 action_id = None;
let mut invoke_id = None;
let mut duration = 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) => action_id = Some(<u16>::from_tlv(reader, &field)?),
Some(1) => invoke_id = Some(<u32>::from_tlv(reader, &field)?),
Some(2) => duration = Some(<u32>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
action_id: action_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
invoke_id,
duration: duration.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct StopActionFields {
pub action_id: u16,
pub invoke_id: Option<u32>,
}
impl ToTlv for StopActionFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.action_id.to_tlv(w, Tag::Context(0))?;
if let Some(value) = &self.invoke_id {
value.to_tlv(w, Tag::Context(1))?;
}
w.end_container()
}
}
impl<'a> FromTlv<'a> for StopActionFields {
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 action_id = None;
let mut invoke_id = 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) => action_id = Some(<u16>::from_tlv(reader, &field)?),
Some(1) => invoke_id = Some(<u32>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
action_id: action_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
invoke_id,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct PauseActionFields {
pub action_id: u16,
pub invoke_id: Option<u32>,
}
impl ToTlv for PauseActionFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.action_id.to_tlv(w, Tag::Context(0))?;
if let Some(value) = &self.invoke_id {
value.to_tlv(w, Tag::Context(1))?;
}
w.end_container()
}
}
impl<'a> FromTlv<'a> for PauseActionFields {
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 action_id = None;
let mut invoke_id = 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) => action_id = Some(<u16>::from_tlv(reader, &field)?),
Some(1) => invoke_id = Some(<u32>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
action_id: action_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
invoke_id,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct PauseActionWithDurationFields {
pub action_id: u16,
pub invoke_id: Option<u32>,
pub duration: u32,
}
impl ToTlv for PauseActionWithDurationFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.action_id.to_tlv(w, Tag::Context(0))?;
if let Some(value) = &self.invoke_id {
value.to_tlv(w, Tag::Context(1))?;
}
self.duration.to_tlv(w, Tag::Context(2))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for PauseActionWithDurationFields {
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 action_id = None;
let mut invoke_id = None;
let mut duration = 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) => action_id = Some(<u16>::from_tlv(reader, &field)?),
Some(1) => invoke_id = Some(<u32>::from_tlv(reader, &field)?),
Some(2) => duration = Some(<u32>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
action_id: action_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
invoke_id,
duration: duration.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ResumeActionFields {
pub action_id: u16,
pub invoke_id: Option<u32>,
}
impl ToTlv for ResumeActionFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.action_id.to_tlv(w, Tag::Context(0))?;
if let Some(value) = &self.invoke_id {
value.to_tlv(w, Tag::Context(1))?;
}
w.end_container()
}
}
impl<'a> FromTlv<'a> for ResumeActionFields {
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 action_id = None;
let mut invoke_id = 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) => action_id = Some(<u16>::from_tlv(reader, &field)?),
Some(1) => invoke_id = Some(<u32>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
action_id: action_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
invoke_id,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct EnableActionFields {
pub action_id: u16,
pub invoke_id: Option<u32>,
}
impl ToTlv for EnableActionFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.action_id.to_tlv(w, Tag::Context(0))?;
if let Some(value) = &self.invoke_id {
value.to_tlv(w, Tag::Context(1))?;
}
w.end_container()
}
}
impl<'a> FromTlv<'a> for EnableActionFields {
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 action_id = None;
let mut invoke_id = 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) => action_id = Some(<u16>::from_tlv(reader, &field)?),
Some(1) => invoke_id = Some(<u32>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
action_id: action_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
invoke_id,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct EnableActionWithDurationFields {
pub action_id: u16,
pub invoke_id: Option<u32>,
pub duration: u32,
}
impl ToTlv for EnableActionWithDurationFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.action_id.to_tlv(w, Tag::Context(0))?;
if let Some(value) = &self.invoke_id {
value.to_tlv(w, Tag::Context(1))?;
}
self.duration.to_tlv(w, Tag::Context(2))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for EnableActionWithDurationFields {
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 action_id = None;
let mut invoke_id = None;
let mut duration = 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) => action_id = Some(<u16>::from_tlv(reader, &field)?),
Some(1) => invoke_id = Some(<u32>::from_tlv(reader, &field)?),
Some(2) => duration = Some(<u32>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
action_id: action_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
invoke_id,
duration: duration.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct DisableActionFields {
pub action_id: u16,
pub invoke_id: Option<u32>,
}
impl ToTlv for DisableActionFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.action_id.to_tlv(w, Tag::Context(0))?;
if let Some(value) = &self.invoke_id {
value.to_tlv(w, Tag::Context(1))?;
}
w.end_container()
}
}
impl<'a> FromTlv<'a> for DisableActionFields {
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 action_id = None;
let mut invoke_id = 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) => action_id = Some(<u16>::from_tlv(reader, &field)?),
Some(1) => invoke_id = Some(<u32>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
action_id: action_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
invoke_id,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct DisableActionWithDurationFields {
pub action_id: u16,
pub invoke_id: Option<u32>,
pub duration: u32,
}
impl ToTlv for DisableActionWithDurationFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.action_id.to_tlv(w, Tag::Context(0))?;
if let Some(value) = &self.invoke_id {
value.to_tlv(w, Tag::Context(1))?;
}
self.duration.to_tlv(w, Tag::Context(2))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for DisableActionWithDurationFields {
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 action_id = None;
let mut invoke_id = None;
let mut duration = 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) => action_id = Some(<u16>::from_tlv(reader, &field)?),
Some(1) => invoke_id = Some(<u32>::from_tlv(reader, &field)?),
Some(2) => duration = Some(<u32>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
action_id: action_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
invoke_id,
duration: duration.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
pub const ATTRIBUTES: &[Attribute] = &[
Attribute {
id: 0x0000,
name: "ActionList",
kind: "list[ActionStruct]",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::empty(),
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x0001,
name: "EndpointLists",
kind: "list[EndpointListStruct]",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::empty(),
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x0002,
name: "SetupURL",
kind: "string",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::empty(),
reporting: Reporting::OnChange,
conform: Conform::OPTIONAL,
},
];
pub const COMMANDS: &[Command] = &[
Command {
id: 0x00,
name: "InstantAction",
to_server: true,
response: None,
access: Access::invoke(Privilege::Operate),
conform: Conform::DESCRIBED,
},
Command {
id: 0x01,
name: "InstantActionWithTransition",
to_server: true,
response: None,
access: Access::invoke(Privilege::Operate),
conform: Conform::DESCRIBED,
},
Command {
id: 0x02,
name: "StartAction",
to_server: true,
response: None,
access: Access::invoke(Privilege::Operate),
conform: Conform::DESCRIBED,
},
Command {
id: 0x03,
name: "StartActionWithDuration",
to_server: true,
response: None,
access: Access::invoke(Privilege::Operate),
conform: Conform::DESCRIBED,
},
Command {
id: 0x04,
name: "StopAction",
to_server: true,
response: None,
access: Access::invoke(Privilege::Operate),
conform: Conform::DESCRIBED,
},
Command {
id: 0x05,
name: "PauseAction",
to_server: true,
response: None,
access: Access::invoke(Privilege::Operate),
conform: Conform::DESCRIBED,
},
Command {
id: 0x06,
name: "PauseActionWithDuration",
to_server: true,
response: None,
access: Access::invoke(Privilege::Operate),
conform: Conform::DESCRIBED,
},
Command {
id: 0x07,
name: "ResumeAction",
to_server: true,
response: None,
access: Access::invoke(Privilege::Operate),
conform: Conform::DESCRIBED,
},
Command {
id: 0x08,
name: "EnableAction",
to_server: true,
response: None,
access: Access::invoke(Privilege::Operate),
conform: Conform::DESCRIBED,
},
Command {
id: 0x09,
name: "EnableActionWithDuration",
to_server: true,
response: None,
access: Access::invoke(Privilege::Operate),
conform: Conform::DESCRIBED,
},
Command {
id: 0x0A,
name: "DisableAction",
to_server: true,
response: None,
access: Access::invoke(Privilege::Operate),
conform: Conform::DESCRIBED,
},
Command {
id: 0x0B,
name: "DisableActionWithDuration",
to_server: true,
response: None,
access: Access::invoke(Privilege::Operate),
conform: Conform::DESCRIBED,
},
];
pub const EVENTS: &[Event] = &[
Event {
id: 0x00,
name: "StateChanged",
priority: EventPriority::Info,
access: Access::read_only(Privilege::View),
conform: Conform::MANDATORY,
},
Event {
id: 0x01,
name: "ActionFailed",
priority: EventPriority::Info,
access: Access::read_only(Privilege::View),
conform: Conform::MANDATORY,
},
];
pub const CLUSTER: Cluster = Cluster {
id: ID,
name: "Actions",
revision: REVISION,
pics: "ACT",
derived_from: None,
features: FEATURES,
attributes: ATTRIBUTES,
commands: COMMANDS,
events: EVENTS,
};