matter_kit/clusters/generated/
user_label.rs1#![allow(unused_imports)]
15
16use crate::dm::conformance::{Clause, Condition, Conform, Conformance};
17use crate::dm::meta::{EventPriority, Reporting};
18use crate::dm::spec::{Attribute, Cluster, Command, Event, Feature};
19use crate::dm::{Access, AccessQualities, AttributeQualities, Privilege};
20use crate::error::Result;
21use crate::im::{AttributeId, ClusterId, CommandId, EventId};
22use crate::tlv::{
23 ContainerKind, Element, FromTlv, Nullable, Tag, TlvList, TlvReader, TlvWriter, ToTlv, Value,
24};
25
26pub const ID: ClusterId = 0x0041;
28
29pub const REVISION: u16 = 1;
32
33pub const PICS: &str = "ULABEL";
35
36pub const FEATURES: &[Feature] = &[];
38
39pub mod attribute {
41 use crate::im::AttributeId;
42
43 pub const LABEL_LIST: AttributeId = 0x00;
45}
46
47#[derive(Debug, Clone, Copy, PartialEq)]
49pub struct LabelStruct<'a> {
50 pub label: &'a str,
52 pub value: &'a str,
54}
55
56impl<'a> ToTlv for LabelStruct<'a> {
57 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
58 w.start_structure(tag)?;
59 self.label.to_tlv(w, Tag::Context(0))?;
60 self.value.to_tlv(w, Tag::Context(1))?;
61 w.end_container()
62 }
63}
64
65impl<'a> FromTlv<'a> for LabelStruct<'a> {
66 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
67 if element.value.container() != Some(ContainerKind::Structure) {
68 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
69 }
70 let mut label = None;
71 let mut value = None;
72 loop {
73 let Some(field) = reader.next_element()? else {
74 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
75 };
76 if field.value == Value::EndOfContainer {
77 break;
78 }
79 match field.tag.context() {
80 Some(0) => label = Some(<&'a str>::from_tlv(reader, &field)?),
81 Some(1) => value = Some(<&'a str>::from_tlv(reader, &field)?),
82 _ => reader.skip_value(&field)?,
86 }
87 }
88 Ok(Self {
89 label: label.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
90 value: value.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
91 })
92 }
93}
94
95pub const ATTRIBUTES: &[Attribute] = &[Attribute {
97 id: 0x0000,
98 name: "LabelList",
99 kind: "list[LabelStruct]",
100 access: Access::read_write_with(Privilege::View, Privilege::Manage),
101 qualities: AttributeQualities::NON_VOLATILE,
102 reporting: Reporting::OnChange,
103 conform: Conform::MANDATORY,
104}];
105
106pub const COMMANDS: &[Command] = &[];
108
109pub const EVENTS: &[Event] = &[];
111
112pub const CLUSTER: Cluster = Cluster {
114 id: ID,
115 name: "User Label",
116 revision: REVISION,
117 pics: "ULABEL",
118 derived_from: Some("Label"),
119 features: FEATURES,
120 attributes: ATTRIBUTES,
121 commands: COMMANDS,
122 events: EVENTS,
123};