#![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 = 0x0041;
pub const REVISION: u16 = 1;
pub const PICS: &str = "ULABEL";
pub const FEATURES: &[Feature] = &[];
pub mod attribute {
use crate::im::AttributeId;
pub const LABEL_LIST: AttributeId = 0x00;
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct LabelStruct<'a> {
pub label: &'a str,
pub value: &'a str,
}
impl<'a> ToTlv for LabelStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.label.to_tlv(w, Tag::Context(0))?;
self.value.to_tlv(w, Tag::Context(1))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for LabelStruct<'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 label = None;
let mut 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) => label = Some(<&'a str>::from_tlv(reader, &field)?),
Some(1) => value = Some(<&'a str>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
label: label.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
value: value.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
pub const ATTRIBUTES: &[Attribute] = &[Attribute {
id: 0x0000,
name: "LabelList",
kind: "list[LabelStruct]",
access: Access::read_write_with(Privilege::View, Privilege::Manage),
qualities: AttributeQualities::NON_VOLATILE,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
}];
pub const COMMANDS: &[Command] = &[];
pub const EVENTS: &[Event] = &[];
pub const CLUSTER: Cluster = Cluster {
id: ID,
name: "User Label",
revision: REVISION,
pics: "ULABEL",
derived_from: Some("Label"),
features: FEATURES,
attributes: ATTRIBUTES,
commands: COMMANDS,
events: EVENTS,
};