matter_kit/clusters/generated/
ecosystem_information.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 = 0x0750;
28
29pub const REVISION: u16 = 1;
32
33pub const PICS: &str = "ECOINFO";
35
36pub const FEATURES: &[Feature] = &[];
38
39pub mod attribute {
41 use crate::im::AttributeId;
42
43 pub const DEVICE_DIRECTORY: AttributeId = 0x00;
45 pub const LOCATION_DIRECTORY: AttributeId = 0x01;
47}
48
49#[derive(Debug, Clone, Copy, PartialEq)]
51pub struct DeviceTypeStruct {
52 pub device_type: u32,
54 pub revision: u16,
56}
57
58impl ToTlv for DeviceTypeStruct {
59 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
60 w.start_structure(tag)?;
61 self.device_type.to_tlv(w, Tag::Context(0))?;
62 self.revision.to_tlv(w, Tag::Context(1))?;
63 w.end_container()
64 }
65}
66
67impl<'a> FromTlv<'a> for DeviceTypeStruct {
68 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
69 if element.value.container() != Some(ContainerKind::Structure) {
70 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
71 }
72 let mut device_type = None;
73 let mut revision = None;
74 loop {
75 let Some(field) = reader.next_element()? else {
76 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
77 };
78 if field.value == Value::EndOfContainer {
79 break;
80 }
81 match field.tag.context() {
82 Some(0) => device_type = Some(<u32>::from_tlv(reader, &field)?),
83 Some(1) => revision = Some(<u16>::from_tlv(reader, &field)?),
84 _ => reader.skip_value(&field)?,
88 }
89 }
90 Ok(Self {
91 device_type: device_type.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
92 revision: revision.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
93 })
94 }
95}
96
97#[derive(Debug, Clone, Copy, PartialEq)]
99pub struct EcosystemDeviceStruct<'a> {
100 pub device_name: Option<&'a str>,
102 pub device_name_last_edit: Option<u64>,
104 pub bridged_endpoint: Option<u16>,
106 pub original_endpoint: Option<u16>,
108 pub device_types: TlvList<'a, DeviceTypeStruct>,
110 pub unique_location_i_ds: TlvList<'a, &'a str>,
112 pub unique_location_i_ds_last_edit: u64,
114 pub fabric_index: crate::msg::FabricIndex,
116}
117
118impl<'a> ToTlv for EcosystemDeviceStruct<'a> {
119 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
120 w.start_structure(tag)?;
121 if let Some(value) = &self.device_name {
122 value.to_tlv(w, Tag::Context(0))?;
123 }
124 if let Some(value) = &self.device_name_last_edit {
125 value.to_tlv(w, Tag::Context(1))?;
126 }
127 if let Some(value) = &self.bridged_endpoint {
128 value.to_tlv(w, Tag::Context(2))?;
129 }
130 if let Some(value) = &self.original_endpoint {
131 value.to_tlv(w, Tag::Context(3))?;
132 }
133 self.device_types.to_tlv(w, Tag::Context(4))?;
134 self.unique_location_i_ds.to_tlv(w, Tag::Context(5))?;
135 self.unique_location_i_ds_last_edit
136 .to_tlv(w, Tag::Context(6))?;
137 self.fabric_index.to_tlv(w, Tag::Context(254))?;
138 w.end_container()
139 }
140}
141
142impl<'a> FromTlv<'a> for EcosystemDeviceStruct<'a> {
143 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
144 if element.value.container() != Some(ContainerKind::Structure) {
145 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
146 }
147 let mut device_name = None;
148 let mut device_name_last_edit = None;
149 let mut bridged_endpoint = None;
150 let mut original_endpoint = None;
151 let mut device_types = None;
152 let mut unique_location_i_ds = None;
153 let mut unique_location_i_ds_last_edit = None;
154 let mut fabric_index = None;
155 loop {
156 let Some(field) = reader.next_element()? else {
157 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
158 };
159 if field.value == Value::EndOfContainer {
160 break;
161 }
162 match field.tag.context() {
163 Some(0) => device_name = Some(<&'a str>::from_tlv(reader, &field)?),
164 Some(1) => device_name_last_edit = Some(<u64>::from_tlv(reader, &field)?),
165 Some(2) => bridged_endpoint = Some(<u16>::from_tlv(reader, &field)?),
166 Some(3) => original_endpoint = Some(<u16>::from_tlv(reader, &field)?),
167 Some(4) => {
168 device_types = Some(<TlvList<'a, DeviceTypeStruct>>::from_tlv(reader, &field)?)
169 }
170 Some(5) => {
171 unique_location_i_ds = Some(<TlvList<'a, &'a str>>::from_tlv(reader, &field)?)
172 }
173 Some(6) => unique_location_i_ds_last_edit = Some(<u64>::from_tlv(reader, &field)?),
174 Some(254) => {
175 fabric_index = Some(<crate::msg::FabricIndex>::from_tlv(reader, &field)?)
176 }
177 _ => reader.skip_value(&field)?,
181 }
182 }
183 Ok(Self {
184 device_name,
185 device_name_last_edit,
186 bridged_endpoint,
187 original_endpoint,
188 device_types: device_types.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
189 unique_location_i_ds: unique_location_i_ds
190 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
191 unique_location_i_ds_last_edit: unique_location_i_ds_last_edit
192 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
193 fabric_index: fabric_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
194 })
195 }
196}
197
198#[derive(Debug, Clone, Copy, PartialEq)]
200pub struct EcosystemLocationStruct<'a> {
201 pub unique_location_id: &'a str,
203 pub location_descriptor: crate::clusters::generated::globals::LocationDescriptorStruct<'a>,
205 pub location_descriptor_last_edit: u64,
207 pub fabric_index: crate::msg::FabricIndex,
209}
210
211impl<'a> ToTlv for EcosystemLocationStruct<'a> {
212 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
213 w.start_structure(tag)?;
214 self.unique_location_id.to_tlv(w, Tag::Context(0))?;
215 self.location_descriptor.to_tlv(w, Tag::Context(1))?;
216 self.location_descriptor_last_edit
217 .to_tlv(w, Tag::Context(2))?;
218 self.fabric_index.to_tlv(w, Tag::Context(254))?;
219 w.end_container()
220 }
221}
222
223impl<'a> FromTlv<'a> for EcosystemLocationStruct<'a> {
224 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
225 if element.value.container() != Some(ContainerKind::Structure) {
226 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
227 }
228 let mut unique_location_id = None;
229 let mut location_descriptor = None;
230 let mut location_descriptor_last_edit = None;
231 let mut fabric_index = None;
232 loop {
233 let Some(field) = reader.next_element()? else {
234 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
235 };
236 if field.value == Value::EndOfContainer {
237 break;
238 }
239 match field.tag.context() {
240 Some(0) => unique_location_id = Some(<&'a str>::from_tlv(reader, &field)?),
241 Some(1) => location_descriptor = Some(
242 <crate::clusters::generated::globals::LocationDescriptorStruct<'a>>::from_tlv(
243 reader, &field,
244 )?,
245 ),
246 Some(2) => location_descriptor_last_edit = Some(<u64>::from_tlv(reader, &field)?),
247 Some(254) => {
248 fabric_index = Some(<crate::msg::FabricIndex>::from_tlv(reader, &field)?)
249 }
250 _ => reader.skip_value(&field)?,
254 }
255 }
256 Ok(Self {
257 unique_location_id: unique_location_id
258 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
259 location_descriptor: location_descriptor
260 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
261 location_descriptor_last_edit: location_descriptor_last_edit
262 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
263 fabric_index: fabric_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
264 })
265 }
266}
267
268pub const ATTRIBUTES: &[Attribute] = &[
270 Attribute {
271 id: 0x0000,
272 name: "DeviceDirectory",
273 kind: "list[EcosystemDeviceStruct]",
274 access: Access::read_only(Privilege::Manage).with_qualities(AccessQualities::FABRIC_SCOPED),
275 qualities: AttributeQualities::NON_VOLATILE,
276 reporting: Reporting::OnChange,
277 conform: Conform::MANDATORY,
278 },
279 Attribute {
280 id: 0x0001,
281 name: "LocationDirectory",
282 kind: "list[EcosystemLocationStruct]",
283 access: Access::read_only(Privilege::Manage).with_qualities(AccessQualities::FABRIC_SCOPED),
284 qualities: AttributeQualities::NON_VOLATILE,
285 reporting: Reporting::OnChange,
286 conform: Conform::MANDATORY,
287 },
288];
289
290pub const COMMANDS: &[Command] = &[];
292
293pub const EVENTS: &[Event] = &[];
295
296pub const CLUSTER: Cluster = Cluster {
298 id: ID,
299 name: "Ecosystem Information",
300 revision: REVISION,
301 pics: "ECOINFO",
302 derived_from: None,
303 features: FEATURES,
304 attributes: ATTRIBUTES,
305 commands: COMMANDS,
306 events: EVENTS,
307};