#![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 = 0x0750;
pub const REVISION: u16 = 1;
pub const PICS: &str = "ECOINFO";
pub const FEATURES: &[Feature] = &[];
pub mod attribute {
use crate::im::AttributeId;
pub const DEVICE_DIRECTORY: AttributeId = 0x00;
pub const LOCATION_DIRECTORY: AttributeId = 0x01;
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct DeviceTypeStruct {
pub device_type: u32,
pub revision: u16,
}
impl ToTlv for DeviceTypeStruct {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.device_type.to_tlv(w, Tag::Context(0))?;
self.revision.to_tlv(w, Tag::Context(1))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for DeviceTypeStruct {
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 device_type = None;
let mut revision = 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) => device_type = Some(<u32>::from_tlv(reader, &field)?),
Some(1) => revision = Some(<u16>::from_tlv(reader, &field)?),
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
device_type: device_type.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
revision: revision.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct EcosystemDeviceStruct<'a> {
pub device_name: Option<&'a str>,
pub device_name_last_edit: Option<u64>,
pub bridged_endpoint: Option<u16>,
pub original_endpoint: Option<u16>,
pub device_types: TlvList<'a, DeviceTypeStruct>,
pub unique_location_i_ds: TlvList<'a, &'a str>,
pub unique_location_i_ds_last_edit: u64,
pub fabric_index: crate::msg::FabricIndex,
}
impl<'a> ToTlv for EcosystemDeviceStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
if let Some(value) = &self.device_name {
value.to_tlv(w, Tag::Context(0))?;
}
if let Some(value) = &self.device_name_last_edit {
value.to_tlv(w, Tag::Context(1))?;
}
if let Some(value) = &self.bridged_endpoint {
value.to_tlv(w, Tag::Context(2))?;
}
if let Some(value) = &self.original_endpoint {
value.to_tlv(w, Tag::Context(3))?;
}
self.device_types.to_tlv(w, Tag::Context(4))?;
self.unique_location_i_ds.to_tlv(w, Tag::Context(5))?;
self.unique_location_i_ds_last_edit
.to_tlv(w, Tag::Context(6))?;
self.fabric_index.to_tlv(w, Tag::Context(254))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for EcosystemDeviceStruct<'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 device_name = None;
let mut device_name_last_edit = None;
let mut bridged_endpoint = None;
let mut original_endpoint = None;
let mut device_types = None;
let mut unique_location_i_ds = None;
let mut unique_location_i_ds_last_edit = None;
let mut fabric_index = 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) => device_name = Some(<&'a str>::from_tlv(reader, &field)?),
Some(1) => device_name_last_edit = Some(<u64>::from_tlv(reader, &field)?),
Some(2) => bridged_endpoint = Some(<u16>::from_tlv(reader, &field)?),
Some(3) => original_endpoint = Some(<u16>::from_tlv(reader, &field)?),
Some(4) => {
device_types = Some(<TlvList<'a, DeviceTypeStruct>>::from_tlv(reader, &field)?)
}
Some(5) => {
unique_location_i_ds = Some(<TlvList<'a, &'a str>>::from_tlv(reader, &field)?)
}
Some(6) => unique_location_i_ds_last_edit = Some(<u64>::from_tlv(reader, &field)?),
Some(254) => {
fabric_index = Some(<crate::msg::FabricIndex>::from_tlv(reader, &field)?)
}
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
device_name,
device_name_last_edit,
bridged_endpoint,
original_endpoint,
device_types: device_types.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
unique_location_i_ds: unique_location_i_ds
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
unique_location_i_ds_last_edit: unique_location_i_ds_last_edit
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
fabric_index: fabric_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct EcosystemLocationStruct<'a> {
pub unique_location_id: &'a str,
pub location_descriptor: crate::clusters::generated::globals::LocationDescriptorStruct<'a>,
pub location_descriptor_last_edit: u64,
pub fabric_index: crate::msg::FabricIndex,
}
impl<'a> ToTlv for EcosystemLocationStruct<'a> {
fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
w.start_structure(tag)?;
self.unique_location_id.to_tlv(w, Tag::Context(0))?;
self.location_descriptor.to_tlv(w, Tag::Context(1))?;
self.location_descriptor_last_edit
.to_tlv(w, Tag::Context(2))?;
self.fabric_index.to_tlv(w, Tag::Context(254))?;
w.end_container()
}
}
impl<'a> FromTlv<'a> for EcosystemLocationStruct<'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 unique_location_id = None;
let mut location_descriptor = None;
let mut location_descriptor_last_edit = None;
let mut fabric_index = 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) => unique_location_id = Some(<&'a str>::from_tlv(reader, &field)?),
Some(1) => location_descriptor = Some(
<crate::clusters::generated::globals::LocationDescriptorStruct<'a>>::from_tlv(
reader, &field,
)?,
),
Some(2) => location_descriptor_last_edit = Some(<u64>::from_tlv(reader, &field)?),
Some(254) => {
fabric_index = Some(<crate::msg::FabricIndex>::from_tlv(reader, &field)?)
}
_ => reader.skip_value(&field)?,
}
}
Ok(Self {
unique_location_id: unique_location_id
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
location_descriptor: location_descriptor
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
location_descriptor_last_edit: location_descriptor_last_edit
.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
fabric_index: fabric_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
})
}
}
pub const ATTRIBUTES: &[Attribute] = &[
Attribute {
id: 0x0000,
name: "DeviceDirectory",
kind: "list[EcosystemDeviceStruct]",
access: Access::read_only(Privilege::Manage).with_qualities(AccessQualities::FABRIC_SCOPED),
qualities: AttributeQualities::NON_VOLATILE,
reporting: Reporting::OnChange,
conform: Conform::MANDATORY,
},
Attribute {
id: 0x0001,
name: "LocationDirectory",
kind: "list[EcosystemLocationStruct]",
access: Access::read_only(Privilege::Manage).with_qualities(AccessQualities::FABRIC_SCOPED),
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: "Ecosystem Information",
revision: REVISION,
pics: "ECOINFO",
derived_from: None,
features: FEATURES,
attributes: ATTRIBUTES,
commands: COMMANDS,
events: EVENTS,
};