matc/clusters/codec/
fixed_label_cluster.rs

1//! Matter TLV encoders and decoders for Fixed Label Cluster
2//! Cluster ID: 0x0040
3//!
4//! This file is automatically generated from FixedLabel-Cluster.xml
5
6#![allow(clippy::too_many_arguments)]
7
8use crate::tlv;
9use anyhow;
10use serde_json;
11
12
13// Attribute decoders
14
15/// Decode LabelList attribute (0x0000)
16pub fn decode_label_list(inp: &tlv::TlvItemValue) -> anyhow::Result<Vec<u8>> {
17    let mut res = Vec::new();
18    if let tlv::TlvItemValue::List(v) = inp {
19        for item in v {
20            if let tlv::TlvItemValue::Int(i) = &item.value {
21                res.push(*i as u8);
22            }
23        }
24    }
25    Ok(res)
26}
27
28
29// JSON dispatcher function
30
31/// Decode attribute value and return as JSON string
32///
33/// # Parameters
34/// * `cluster_id` - The cluster identifier
35/// * `attribute_id` - The attribute identifier
36/// * `tlv_value` - The TLV value to decode
37///
38/// # Returns
39/// JSON string representation of the decoded value or error
40pub fn decode_attribute_json(cluster_id: u32, attribute_id: u32, tlv_value: &crate::tlv::TlvItemValue) -> String {
41    // Verify this is the correct cluster
42    if cluster_id != 0x0040 {
43        return format!("{{\"error\": \"Invalid cluster ID. Expected 0x0040, got {}\"}}", cluster_id);
44    }
45
46    match attribute_id {
47        0x0000 => {
48            match decode_label_list(tlv_value) {
49                Ok(value) => serde_json::to_string(&value).unwrap_or_else(|_| "null".to_string()),
50                Err(e) => format!("{{\"error\": \"{}\"}}", e),
51            }
52        }
53        _ => format!("{{\"error\": \"Unknown attribute ID: {}\"}}", attribute_id),
54    }
55}
56
57/// Get list of all attributes supported by this cluster
58///
59/// # Returns
60/// Vector of tuples containing (attribute_id, attribute_name)
61pub fn get_attribute_list() -> Vec<(u32, &'static str)> {
62    vec![
63        (0x0000, "LabelList"),
64    ]
65}
66
67// Typed facade (invokes + reads)
68
69/// Read `LabelList` attribute from cluster `Fixed Label`.
70pub async fn read_label_list(conn: &crate::controller::Connection, endpoint: u16) -> anyhow::Result<Vec<u8>> {
71    let tlv = conn.read_request2(endpoint, crate::clusters::defs::CLUSTER_ID_FIXED_LABEL, crate::clusters::defs::CLUSTER_FIXED_LABEL_ATTR_ID_LABELLIST).await?;
72    decode_label_list(&tlv)
73}
74