1#![allow(
5 clippy::all,
6 clippy::pedantic,
7 dead_code,
8 unreachable_pub,
9 unused_imports
10)]
11
12use crate::datatypes::SemanticTagStruct;
13use crate::error::ClusterError;
14use crate::types::Nullable;
15use matter_codec::{ContainerKind, Element, Tag, TlvReader, TlvWriter, Value};
16
17pub const CLUSTER_ID: u32 = 0x0204;
19pub const CLUSTER_REVISION: u16 = 2;
21
22pub mod command_id {}
24
25pub mod attribute_id {
27 pub const TEMPERATURE_DISPLAY_MODE: u32 = 0x0000;
29 pub const KEYPAD_LOCKOUT: u32 = 0x0001;
31 pub const SCHEDULE_PROGRAMMING_VISIBILITY: u32 = 0x0002;
33}
34
35#[derive(Copy, Clone, Debug, PartialEq, Eq)]
37pub enum KeypadLockoutEnum {
38 NoLockout,
40 Lockout1,
42 Lockout2,
44 Lockout3,
46 Lockout4,
48 Lockout5,
50 Unknown(u8),
52}
53
54impl KeypadLockoutEnum {
55 #[must_use]
57 pub fn from_raw(v: u8) -> Self {
58 match v {
59 0 => Self::NoLockout,
60 1 => Self::Lockout1,
61 2 => Self::Lockout2,
62 3 => Self::Lockout3,
63 4 => Self::Lockout4,
64 5 => Self::Lockout5,
65 other => Self::Unknown(other),
66 }
67 }
68 #[must_use]
70 pub fn to_raw(self) -> u8 {
71 match self {
72 Self::NoLockout => 0,
73 Self::Lockout1 => 1,
74 Self::Lockout2 => 2,
75 Self::Lockout3 => 3,
76 Self::Lockout4 => 4,
77 Self::Lockout5 => 5,
78 Self::Unknown(v) => v,
79 }
80 }
81}
82
83#[derive(Copy, Clone, Debug, PartialEq, Eq)]
85pub enum ScheduleProgrammingVisibilityEnum {
86 ScheduleProgrammingPermitted,
88 ScheduleProgrammingDenied,
90 Unknown(u8),
92}
93
94impl ScheduleProgrammingVisibilityEnum {
95 #[must_use]
97 pub fn from_raw(v: u8) -> Self {
98 match v {
99 0 => Self::ScheduleProgrammingPermitted,
100 1 => Self::ScheduleProgrammingDenied,
101 other => Self::Unknown(other),
102 }
103 }
104 #[must_use]
106 pub fn to_raw(self) -> u8 {
107 match self {
108 Self::ScheduleProgrammingPermitted => 0,
109 Self::ScheduleProgrammingDenied => 1,
110 Self::Unknown(v) => v,
111 }
112 }
113}
114
115#[derive(Copy, Clone, Debug, PartialEq, Eq)]
117pub enum TemperatureDisplayModeEnum {
118 Celsius,
120 Fahrenheit,
122 Unknown(u8),
124}
125
126impl TemperatureDisplayModeEnum {
127 #[must_use]
129 pub fn from_raw(v: u8) -> Self {
130 match v {
131 0 => Self::Celsius,
132 1 => Self::Fahrenheit,
133 other => Self::Unknown(other),
134 }
135 }
136 #[must_use]
138 pub fn to_raw(self) -> u8 {
139 match self {
140 Self::Celsius => 0,
141 Self::Fahrenheit => 1,
142 Self::Unknown(v) => v,
143 }
144 }
145}
146
147pub fn decode_temperature_display_mode(
152 tlv: &[u8],
153) -> Result<TemperatureDisplayModeEnum, ClusterError> {
154 let mut r = TlvReader::new(tlv);
155 match r.next()? {
156 Some(Element::Scalar {
157 value: Value::Uint(v),
158 ..
159 }) => Ok(TemperatureDisplayModeEnum::from_raw(
160 u8::try_from(v).map_err(|_| ClusterError::InvalidLength("TemperatureDisplayMode"))?,
161 )),
162 _ => Err(ClusterError::UnexpectedType {
163 context: "TemperatureDisplayMode",
164 }),
165 }
166}
167
168#[must_use]
170#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_temperature_display_mode(value: TemperatureDisplayModeEnum) -> Vec<u8> {
172 let mut buf = Vec::new();
173 let mut w = TlvWriter::new(&mut buf);
174 w.put_uint(Tag::Anonymous, u64::from(value.to_raw()))
175 .expect("infallible: vec writer");
176 buf
177}
178
179pub fn decode_keypad_lockout(tlv: &[u8]) -> Result<KeypadLockoutEnum, ClusterError> {
184 let mut r = TlvReader::new(tlv);
185 match r.next()? {
186 Some(Element::Scalar {
187 value: Value::Uint(v),
188 ..
189 }) => Ok(KeypadLockoutEnum::from_raw(
190 u8::try_from(v).map_err(|_| ClusterError::InvalidLength("KeypadLockout"))?,
191 )),
192 _ => Err(ClusterError::UnexpectedType {
193 context: "KeypadLockout",
194 }),
195 }
196}
197
198#[must_use]
200#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_keypad_lockout(value: KeypadLockoutEnum) -> Vec<u8> {
202 let mut buf = Vec::new();
203 let mut w = TlvWriter::new(&mut buf);
204 w.put_uint(Tag::Anonymous, u64::from(value.to_raw()))
205 .expect("infallible: vec writer");
206 buf
207}
208
209pub fn decode_schedule_programming_visibility(
214 tlv: &[u8],
215) -> Result<ScheduleProgrammingVisibilityEnum, ClusterError> {
216 let mut r = TlvReader::new(tlv);
217 match r.next()? {
218 Some(Element::Scalar {
219 value: Value::Uint(v),
220 ..
221 }) => Ok(ScheduleProgrammingVisibilityEnum::from_raw(
222 u8::try_from(v)
223 .map_err(|_| ClusterError::InvalidLength("ScheduleProgrammingVisibility"))?,
224 )),
225 _ => Err(ClusterError::UnexpectedType {
226 context: "ScheduleProgrammingVisibility",
227 }),
228 }
229}
230
231#[must_use]
233#[allow(clippy::expect_used, clippy::missing_panics_doc)] pub fn encode_schedule_programming_visibility(value: ScheduleProgrammingVisibilityEnum) -> Vec<u8> {
235 let mut buf = Vec::new();
236 let mut w = TlvWriter::new(&mut buf);
237 w.put_uint(Tag::Anonymous, u64::from(value.to_raw()))
238 .expect("infallible: vec writer");
239 buf
240}