Skip to main content

matter_clusters/gen/
thermostat_user_interface_configuration.rs

1//! ThermostatUserInterfaceConfiguration cluster (0x0204).
2//! @generated by `cargo xtask codegen` — do not edit.
3
4#![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
17/// Cluster ID.
18pub const CLUSTER_ID: u32 = 0x0204;
19/// Cluster revision.
20pub const CLUSTER_REVISION: u16 = 2;
21
22/// Command IDs (requests and responses).
23pub mod command_id {}
24
25/// Attribute IDs (cluster-specific).
26pub mod attribute_id {
27    /// `TemperatureDisplayMode`.
28    pub const TEMPERATURE_DISPLAY_MODE: u32 = 0x0000;
29    /// `KeypadLockout`.
30    pub const KEYPAD_LOCKOUT: u32 = 0x0001;
31    /// `ScheduleProgrammingVisibility`.
32    pub const SCHEDULE_PROGRAMMING_VISIBILITY: u32 = 0x0002;
33}
34
35/// `KeypadLockoutEnum` (enum8).
36#[derive(Copy, Clone, Debug, PartialEq, Eq)]
37pub enum KeypadLockoutEnum {
38    /// NoLockout = 0.
39    NoLockout,
40    /// Lockout1 = 1.
41    Lockout1,
42    /// Lockout2 = 2.
43    Lockout2,
44    /// Lockout3 = 3.
45    Lockout3,
46    /// Lockout4 = 4.
47    Lockout4,
48    /// Lockout5 = 5.
49    Lockout5,
50    /// A value not known to this codegen revision.
51    Unknown(u8),
52}
53
54impl KeypadLockoutEnum {
55    /// Decode from its raw discriminant (unknown → `Unknown`).
56    #[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    /// The raw discriminant.
69    #[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/// `ScheduleProgrammingVisibilityEnum` (enum8).
84#[derive(Copy, Clone, Debug, PartialEq, Eq)]
85pub enum ScheduleProgrammingVisibilityEnum {
86    /// ScheduleProgrammingPermitted = 0.
87    ScheduleProgrammingPermitted,
88    /// ScheduleProgrammingDenied = 1.
89    ScheduleProgrammingDenied,
90    /// A value not known to this codegen revision.
91    Unknown(u8),
92}
93
94impl ScheduleProgrammingVisibilityEnum {
95    /// Decode from its raw discriminant (unknown → `Unknown`).
96    #[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    /// The raw discriminant.
105    #[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/// `TemperatureDisplayModeEnum` (enum8).
116#[derive(Copy, Clone, Debug, PartialEq, Eq)]
117pub enum TemperatureDisplayModeEnum {
118    /// Celsius = 0.
119    Celsius,
120    /// Fahrenheit = 1.
121    Fahrenheit,
122    /// A value not known to this codegen revision.
123    Unknown(u8),
124}
125
126impl TemperatureDisplayModeEnum {
127    /// Decode from its raw discriminant (unknown → `Unknown`).
128    #[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    /// The raw discriminant.
137    #[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
147/// Decode the `TemperatureDisplayMode` attribute value.
148///
149/// # Errors
150/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
151pub 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/// Encode the `TemperatureDisplayMode` attribute value as a standalone TLV element.
169#[must_use]
170#[allow(clippy::expect_used, clippy::missing_panics_doc)] // Vec-backed TlvWriter is infallible.
171pub 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
179/// Decode the `KeypadLockout` attribute value.
180///
181/// # Errors
182/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
183pub 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/// Encode the `KeypadLockout` attribute value as a standalone TLV element.
199#[must_use]
200#[allow(clippy::expect_used, clippy::missing_panics_doc)] // Vec-backed TlvWriter is infallible.
201pub 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
209/// Decode the `ScheduleProgrammingVisibility` attribute value.
210///
211/// # Errors
212/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
213pub 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/// Encode the `ScheduleProgrammingVisibility` attribute value as a standalone TLV element.
232#[must_use]
233#[allow(clippy::expect_used, clippy::missing_panics_doc)] // Vec-backed TlvWriter is infallible.
234pub 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}