matc/clusters/codec/
wake_on_lan.rs

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