matc/clusters/codec/
fixed_label_cluster.rs1use crate::tlv;
7use anyhow;
8use serde_json;
9
10
11pub fn decode_label_list(inp: &tlv::TlvItemValue) -> anyhow::Result<Vec<u8>> {
15 let mut res = Vec::new();
16 if let tlv::TlvItemValue::List(v) = inp {
17 for item in v {
18 if let tlv::TlvItemValue::Int(i) = &item.value {
19 res.push(*i as u8);
20 }
21 }
22 }
23 Ok(res)
24}
25
26
27pub fn decode_attribute_json(cluster_id: u32, attribute_id: u32, tlv_value: &crate::tlv::TlvItemValue) -> String {
39 if cluster_id != 0x0040 {
41 return format!("{{\"error\": \"Invalid cluster ID. Expected 0x0040, got {}\"}}", cluster_id);
42 }
43
44 match attribute_id {
45 0x0000 => {
46 match decode_label_list(tlv_value) {
47 Ok(value) => serde_json::to_string(&value).unwrap_or_else(|_| "null".to_string()),
48 Err(e) => format!("{{\"error\": \"{}\"}}", e),
49 }
50 }
51 _ => format!("{{\"error\": \"Unknown attribute ID: {}\"}}", attribute_id),
52 }
53}
54
55pub fn get_attribute_list() -> Vec<(u32, &'static str)> {
60 vec![
61 (0x0000, "LabelList"),
62 ]
63}
64