matc/clusters/codec/
laundry_dryer_controls.rs

1//! Generated Matter TLV encoders and decoders for Laundry Dryer Controls Cluster
2//! Cluster ID: 0x004A
3//! 
4//! This file is automatically generated from LaundryDryerControls.xml
5
6use crate::tlv;
7use anyhow;
8use serde_json;
9
10
11// Attribute decoders
12
13/// Decode SupportedDrynessLevels attribute (0x0000)
14pub fn decode_supported_dryness_levels(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/// Decode SelectedDrynessLevel attribute (0x0001)
27pub fn decode_selected_dryness_level(inp: &tlv::TlvItemValue) -> anyhow::Result<Option<u8>> {
28    if let tlv::TlvItemValue::Int(v) = inp {
29        Ok(Some(*v as u8))
30    } else {
31        Ok(None)
32    }
33}
34
35
36// JSON dispatcher function
37
38/// Decode attribute value and return as JSON string
39/// 
40/// # Parameters
41/// * `cluster_id` - The cluster identifier
42/// * `attribute_id` - The attribute identifier
43/// * `tlv_value` - The TLV value to decode
44/// 
45/// # Returns
46/// JSON string representation of the decoded value or error
47pub fn decode_attribute_json(cluster_id: u32, attribute_id: u32, tlv_value: &crate::tlv::TlvItemValue) -> String {
48    // Verify this is the correct cluster
49    if cluster_id != 0x004A {
50        return format!("{{\"error\": \"Invalid cluster ID. Expected 0x004A, got {}\"}}", cluster_id);
51    }
52    
53    match attribute_id {
54        0x0000 => {
55            match decode_supported_dryness_levels(tlv_value) {
56                Ok(value) => serde_json::to_string(&value).unwrap_or_else(|_| "null".to_string()),
57                Err(e) => format!("{{\"error\": \"{}\"}}", e),
58            }
59        }
60        0x0001 => {
61            match decode_selected_dryness_level(tlv_value) {
62                Ok(value) => serde_json::to_string(&value).unwrap_or_else(|_| "null".to_string()),
63                Err(e) => format!("{{\"error\": \"{}\"}}", e),
64            }
65        }
66        _ => format!("{{\"error\": \"Unknown attribute ID: {}\"}}", attribute_id),
67    }
68}
69
70/// Get list of all attributes supported by this cluster
71/// 
72/// # Returns
73/// Vector of tuples containing (attribute_id, attribute_name)
74pub fn get_attribute_list() -> Vec<(u32, &'static str)> {
75    vec![
76        (0x0000, "SupportedDrynessLevels"),
77        (0x0001, "SelectedDrynessLevel"),
78    ]
79}
80