matc/clusters/codec/
commissioner_control_cluster.rs1use crate::tlv;
7use anyhow;
8use serde_json;
9
10
11pub fn encode_request_commissioning_approval(request_id: u64, vendor_id: u16, product_id: u16, label: String) -> anyhow::Result<Vec<u8>> {
15 let tlv = tlv::TlvItemEnc {
16 tag: 0,
17 value: tlv::TlvItemValueEnc::StructInvisible(vec![
18 (0, tlv::TlvItemValueEnc::UInt64(request_id)).into(),
19 (1, tlv::TlvItemValueEnc::UInt16(vendor_id)).into(),
20 (2, tlv::TlvItemValueEnc::UInt16(product_id)).into(),
21 (3, tlv::TlvItemValueEnc::String(label)).into(),
22 ]),
23 };
24 Ok(tlv.encode()?)
25}
26
27pub fn encode_commission_node(request_id: u64, response_timeout_seconds: u16) -> anyhow::Result<Vec<u8>> {
29 let tlv = tlv::TlvItemEnc {
30 tag: 0,
31 value: tlv::TlvItemValueEnc::StructInvisible(vec![
32 (0, tlv::TlvItemValueEnc::UInt64(request_id)).into(),
33 (1, tlv::TlvItemValueEnc::UInt16(response_timeout_seconds)).into(),
34 ]),
35 };
36 Ok(tlv.encode()?)
37}
38
39pub fn decode_supported_device_categories(inp: &tlv::TlvItemValue) -> anyhow::Result<u8> {
43 if let tlv::TlvItemValue::Int(v) = inp {
44 Ok(*v as u8)
45 } else {
46 Err(anyhow::anyhow!("Expected Integer"))
47 }
48}
49
50
51pub fn decode_attribute_json(cluster_id: u32, attribute_id: u32, tlv_value: &crate::tlv::TlvItemValue) -> String {
63 if cluster_id != 0x0751 {
65 return format!("{{\"error\": \"Invalid cluster ID. Expected 0x0751, got {}\"}}", cluster_id);
66 }
67
68 match attribute_id {
69 0x0000 => {
70 match decode_supported_device_categories(tlv_value) {
71 Ok(value) => serde_json::to_string(&value).unwrap_or_else(|_| "null".to_string()),
72 Err(e) => format!("{{\"error\": \"{}\"}}", e),
73 }
74 }
75 _ => format!("{{\"error\": \"Unknown attribute ID: {}\"}}", attribute_id),
76 }
77}
78
79pub fn get_attribute_list() -> Vec<(u32, &'static str)> {
84 vec![
85 (0x0000, "SupportedDeviceCategories"),
86 ]
87}
88