matc/clusters/codec/
boolean_state.rs

1//! Generated Matter TLV encoders and decoders for Boolean State Cluster
2//! Cluster ID: 0x0045
3//! 
4//! This file is automatically generated from BooleanState.xml
5
6use crate::tlv;
7use anyhow;
8use serde_json;
9
10
11// Attribute decoders
12
13/// Decode StateValue attribute (0x0000)
14pub fn decode_state_value(inp: &tlv::TlvItemValue) -> anyhow::Result<bool> {
15    if let tlv::TlvItemValue::Bool(v) = inp {
16        Ok(*v)
17    } else {
18        Err(anyhow::anyhow!("Expected Bool"))
19    }
20}
21
22
23// JSON dispatcher function
24
25/// Decode attribute value and return as JSON string
26/// 
27/// # Parameters
28/// * `cluster_id` - The cluster identifier
29/// * `attribute_id` - The attribute identifier
30/// * `tlv_value` - The TLV value to decode
31/// 
32/// # Returns
33/// JSON string representation of the decoded value or error
34pub fn decode_attribute_json(cluster_id: u32, attribute_id: u32, tlv_value: &crate::tlv::TlvItemValue) -> String {
35    // Verify this is the correct cluster
36    if cluster_id != 0x0045 {
37        return format!("{{\"error\": \"Invalid cluster ID. Expected 0x0045, got {}\"}}", cluster_id);
38    }
39    
40    match attribute_id {
41        0x0000 => {
42            match decode_state_value(tlv_value) {
43                Ok(value) => serde_json::to_string(&value).unwrap_or_else(|_| "null".to_string()),
44                Err(e) => format!("{{\"error\": \"{}\"}}", e),
45            }
46        }
47        _ => format!("{{\"error\": \"Unknown attribute ID: {}\"}}", attribute_id),
48    }
49}
50
51/// Get list of all attributes supported by this cluster
52/// 
53/// # Returns
54/// Vector of tuples containing (attribute_id, attribute_name)
55pub fn get_attribute_list() -> Vec<(u32, &'static str)> {
56    vec![
57        (0x0000, "StateValue"),
58    ]
59}
60