1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//! Matter TLV encoders and decoders for Laundry Dryer Controls Cluster
//! Cluster ID: 0x004A
//!
//! This file is automatically generated from LaundryDryerControls.xml
use crate::tlv;
use anyhow;
use serde_json;
// Enum definitions
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[repr(u8)]
pub enum DrynessLevel {
/// Provides a low dryness level for the selected mode
Low = 0,
/// Provides the normal level of dryness for the selected mode
Normal = 1,
/// Provides an extra dryness level for the selected mode
Extra = 2,
/// Provides the max dryness level for the selected mode
Max = 3,
}
impl DrynessLevel {
/// Convert from u8 value
pub fn from_u8(value: u8) -> Option<Self> {
match value {
0 => Some(DrynessLevel::Low),
1 => Some(DrynessLevel::Normal),
2 => Some(DrynessLevel::Extra),
3 => Some(DrynessLevel::Max),
_ => None,
}
}
/// Convert to u8 value
pub fn to_u8(self) -> u8 {
self as u8
}
}
impl From<DrynessLevel> for u8 {
fn from(val: DrynessLevel) -> Self {
val as u8
}
}
// Attribute decoders
/// Decode SupportedDrynessLevels attribute (0x0000)
pub fn decode_supported_dryness_levels(inp: &tlv::TlvItemValue) -> anyhow::Result<Vec<DrynessLevel>> {
let mut res = Vec::new();
if let tlv::TlvItemValue::List(v) = inp {
for item in v {
if let tlv::TlvItemValue::Int(i) = &item.value {
if let Some(enum_val) = DrynessLevel::from_u8(*i as u8) {
res.push(enum_val);
}
}
}
}
Ok(res)
}
/// Decode SelectedDrynessLevel attribute (0x0001)
pub fn decode_selected_dryness_level(inp: &tlv::TlvItemValue) -> anyhow::Result<Option<DrynessLevel>> {
if let tlv::TlvItemValue::Int(v) = inp {
Ok(DrynessLevel::from_u8(*v as u8))
} else {
Ok(None)
}
}
// JSON dispatcher function
/// Decode attribute value and return as JSON string
///
/// # Parameters
/// * `cluster_id` - The cluster identifier
/// * `attribute_id` - The attribute identifier
/// * `tlv_value` - The TLV value to decode
///
/// # Returns
/// JSON string representation of the decoded value or error
pub fn decode_attribute_json(cluster_id: u32, attribute_id: u32, tlv_value: &crate::tlv::TlvItemValue) -> String {
// Verify this is the correct cluster
if cluster_id != 0x004A {
return format!("{{\"error\": \"Invalid cluster ID. Expected 0x004A, got {}\"}}", cluster_id);
}
match attribute_id {
0x0000 => {
match decode_supported_dryness_levels(tlv_value) {
Ok(value) => serde_json::to_string(&value).unwrap_or_else(|_| "null".to_string()),
Err(e) => format!("{{\"error\": \"{}\"}}", e),
}
}
0x0001 => {
match decode_selected_dryness_level(tlv_value) {
Ok(value) => serde_json::to_string(&value).unwrap_or_else(|_| "null".to_string()),
Err(e) => format!("{{\"error\": \"{}\"}}", e),
}
}
_ => format!("{{\"error\": \"Unknown attribute ID: {}\"}}", attribute_id),
}
}
/// Get list of all attributes supported by this cluster
///
/// # Returns
/// Vector of tuples containing (attribute_id, attribute_name)
pub fn get_attribute_list() -> Vec<(u32, &'static str)> {
vec![
(0x0000, "SupportedDrynessLevels"),
(0x0001, "SelectedDrynessLevel"),
]
}