matc/clusters/codec/
boolean_state.rs1use crate::tlv;
7use anyhow;
8use serde_json;
9
10
11pub 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
23pub fn decode_attribute_json(cluster_id: u32, attribute_id: u32, tlv_value: &crate::tlv::TlvItemValue) -> String {
35 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
51pub fn get_attribute_list() -> Vec<(u32, &'static str)> {
56 vec![
57 (0x0000, "StateValue"),
58 ]
59}
60