matc/clusters/codec/
wake_on_lan.rs1use crate::tlv;
7use anyhow;
8use serde_json;
9
10
11pub 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
22pub 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
32pub fn decode_attribute_json(cluster_id: u32, attribute_id: u32, tlv_value: &crate::tlv::TlvItemValue) -> String {
44 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
66pub fn get_attribute_list() -> Vec<(u32, &'static str)> {
71 vec![
72 (0x0000, "MACAddress"),
73 (0x0001, "LinkLocalAddress"),
74 ]
75}
76