#![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 = 0x0556;
pub const REVISION: u16 = 2;
pub const PICS: &str = "CHIME";
pub const FEATURES: &[Feature] = &[];
pub mod attribute {
use crate::im::AttributeId;
pub const INSTALLED_CHIME_SOUNDS: AttributeId = 0x00;
pub const SELECTED_CHIME: AttributeId = 0x01;
pub const ENABLED: AttributeId = 0x02;
}
pub mod command {
use crate::im::CommandId;
pub const PLAY_CHIME_SOUND: CommandId = 0x00;
}
pub mod event {
use crate::im::EventId;
pub const CHIME_STARTED_PLAYING: EventId = 0x00;
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ChimeSoundStruct<'a> {
pub chime_id: u8,
pub name: &'a str,
}
impl<'a> ToTlv for ChimeSoundStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.chime_id.to_tlv(w, Tag::Context(0))?;
self.name.to_tlv(w, Tag::Context(1))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for ChimeSoundStruct<'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 chime_id = None;
let mut name = 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) => chime_id = Some(<u8>::from_tlv(reader, &field)?),
Some(1) => name = Some(<&'a str>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
chime_id: chime_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
name: name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct PlayChimeSoundFields {
pub chime_id: Option<u8>,
}
impl ToTlv for PlayChimeSoundFields {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
if let Some(value) = &self.chime_id {
value.to_tlv(w, Tag::Context(0))?;
}
w.end_container()
}
}
impl<'a> FromTlv<'a> for PlayChimeSoundFields {
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 chime_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) => chime_id = Some(<u8>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self { chime_id })
}
}
pub const ATTRIBUTES: &[Attribute] = &[
Attribute {
id: 0x0000,
name: "InstalledChimeSounds",
kind: "list[ChimeSoundStruct]",
access: Access::read_only(Privilege::View),
qualities: AttributeQualities::empty(),
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x0001,
name: "SelectedChime",
kind: "uint8",
access: Access::read_write_with(Privilege::View, Privilege::Operate),
qualities: AttributeQualities::NON_VOLATILE,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x0002,
name: "Enabled",
kind: "bool",
access: Access::read_write_with(Privilege::View, Privilege::Operate),
qualities: AttributeQualities::NON_VOLATILE,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
];
pub const COMMANDS: &[Command] = &[Command {
id: 0x00,
name: "PlayChimeSound",
to_server: true,
response: None,
access: Access::invoke(Privilege::Operate),
conform: Conform::MANDATORY,
}];
pub const EVENTS: &[Event] = &[Event {
id: 0x00,
name: "ChimeStartedPlaying",
priority: EventPriority::Info,
access: Access::read_only(Privilege::View),
conform: Conform {
clauses: &[Clause {
verdict: Conformance::Described,
when: Condition::Named("comparison"),
}],
},
}];
pub const CLUSTER: Cluster = Cluster {
id: ID,
name: "Chime",
revision: REVISION,
pics: "CHIME",
derived_from: None,
features: FEATURES,
attributes: ATTRIBUTES,
commands: COMMANDS,
events: EVENTS,
};