Skip to main content

matter_clusters/gen/
identify.rs

1//! Identify cluster (0x0003).
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 = 0x0003;
19/// Cluster revision.
20pub const CLUSTER_REVISION: u16 = 6;
21
22/// Command IDs (requests and responses).
23pub mod command_id {
24    /// `Identify` (request).
25    pub const IDENTIFY: u32 = 0x00;
26    /// `TriggerEffect` (request).
27    pub const TRIGGER_EFFECT: u32 = 0x40;
28}
29
30/// Attribute IDs (cluster-specific).
31pub mod attribute_id {
32    /// `IdentifyTime`.
33    pub const IDENTIFY_TIME: u32 = 0x0000;
34    /// `IdentifyType`.
35    pub const IDENTIFY_TYPE: u32 = 0x0001;
36}
37
38/// `EffectIdentifierEnum` (enum8).
39#[derive(Copy, Clone, Debug, PartialEq, Eq)]
40pub enum EffectIdentifierEnum {
41    /// Blink = 0.
42    Blink,
43    /// Breathe = 1.
44    Breathe,
45    /// Okay = 2.
46    Okay,
47    /// ChannelChange = 11.
48    ChannelChange,
49    /// FinishEffect = 254.
50    FinishEffect,
51    /// StopEffect = 255.
52    StopEffect,
53    /// A value not known to this codegen revision.
54    Unknown(u8),
55}
56
57impl EffectIdentifierEnum {
58    /// Decode from its raw discriminant (unknown → `Unknown`).
59    #[must_use]
60    pub fn from_raw(v: u8) -> Self {
61        match v {
62            0 => Self::Blink,
63            1 => Self::Breathe,
64            2 => Self::Okay,
65            11 => Self::ChannelChange,
66            254 => Self::FinishEffect,
67            255 => Self::StopEffect,
68            other => Self::Unknown(other),
69        }
70    }
71    /// The raw discriminant.
72    #[must_use]
73    pub fn to_raw(self) -> u8 {
74        match self {
75            Self::Blink => 0,
76            Self::Breathe => 1,
77            Self::Okay => 2,
78            Self::ChannelChange => 11,
79            Self::FinishEffect => 254,
80            Self::StopEffect => 255,
81            Self::Unknown(v) => v,
82        }
83    }
84}
85
86/// `EffectVariantEnum` (enum8).
87#[derive(Copy, Clone, Debug, PartialEq, Eq)]
88pub enum EffectVariantEnum {
89    /// Default = 0.
90    Default,
91    /// A value not known to this codegen revision.
92    Unknown(u8),
93}
94
95impl EffectVariantEnum {
96    /// Decode from its raw discriminant (unknown → `Unknown`).
97    #[must_use]
98    pub fn from_raw(v: u8) -> Self {
99        match v {
100            0 => Self::Default,
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::Default => 0,
109            Self::Unknown(v) => v,
110        }
111    }
112}
113
114/// `IdentifyTypeEnum` (enum8).
115#[derive(Copy, Clone, Debug, PartialEq, Eq)]
116pub enum IdentifyTypeEnum {
117    /// None = 0.
118    None,
119    /// LightOutput = 1.
120    LightOutput,
121    /// VisibleIndicator = 2.
122    VisibleIndicator,
123    /// AudibleBeep = 3.
124    AudibleBeep,
125    /// Display = 4.
126    Display,
127    /// Actuator = 5.
128    Actuator,
129    /// A value not known to this codegen revision.
130    Unknown(u8),
131}
132
133impl IdentifyTypeEnum {
134    /// Decode from its raw discriminant (unknown → `Unknown`).
135    #[must_use]
136    pub fn from_raw(v: u8) -> Self {
137        match v {
138            0 => Self::None,
139            1 => Self::LightOutput,
140            2 => Self::VisibleIndicator,
141            3 => Self::AudibleBeep,
142            4 => Self::Display,
143            5 => Self::Actuator,
144            other => Self::Unknown(other),
145        }
146    }
147    /// The raw discriminant.
148    #[must_use]
149    pub fn to_raw(self) -> u8 {
150        match self {
151            Self::None => 0,
152            Self::LightOutput => 1,
153            Self::VisibleIndicator => 2,
154            Self::AudibleBeep => 3,
155            Self::Display => 4,
156            Self::Actuator => 5,
157            Self::Unknown(v) => v,
158        }
159    }
160}
161
162/// Decode the `IdentifyTime` attribute value.
163///
164/// # Errors
165/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
166pub fn decode_identify_time(tlv: &[u8]) -> Result<u16, ClusterError> {
167    let mut r = TlvReader::new(tlv);
168    match r.next()? {
169        Some(Element::Scalar {
170            value: Value::Uint(v),
171            ..
172        }) => Ok(u16::try_from(v).map_err(|_| ClusterError::InvalidLength("IdentifyTime"))?),
173        _ => Err(ClusterError::UnexpectedType {
174            context: "IdentifyTime",
175        }),
176    }
177}
178
179/// Encode the `IdentifyTime` attribute value as a standalone TLV element.
180#[must_use]
181#[allow(clippy::expect_used, clippy::missing_panics_doc)] // Vec-backed TlvWriter is infallible.
182pub fn encode_identify_time(value: u16) -> Vec<u8> {
183    let mut buf = Vec::new();
184    let mut w = TlvWriter::new(&mut buf);
185    w.put_uint(Tag::Anonymous, u64::from(value))
186        .expect("infallible: vec writer");
187    buf
188}
189
190/// Decode the `IdentifyType` attribute value.
191///
192/// # Errors
193/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
194pub fn decode_identify_type(tlv: &[u8]) -> Result<IdentifyTypeEnum, ClusterError> {
195    let mut r = TlvReader::new(tlv);
196    match r.next()? {
197        Some(Element::Scalar {
198            value: Value::Uint(v),
199            ..
200        }) => Ok(IdentifyTypeEnum::from_raw(
201            u8::try_from(v).map_err(|_| ClusterError::InvalidLength("IdentifyType"))?,
202        )),
203        _ => Err(ClusterError::UnexpectedType {
204            context: "IdentifyType",
205        }),
206    }
207}
208
209/// Encode the `Identify` command request payload.
210#[must_use]
211#[allow(clippy::expect_used, clippy::missing_panics_doc)] // Vec-backed TlvWriter is infallible.
212pub fn encode_identify(identify_time: u16) -> Vec<u8> {
213    let mut buf = Vec::new();
214    let mut w = TlvWriter::new(&mut buf);
215    w.start_structure(Tag::Anonymous)
216        .expect("infallible: vec writer");
217    w.put_uint(Tag::Context(0), u64::from(identify_time))
218        .expect("infallible: vec writer");
219    w.end_container().expect("infallible: vec writer");
220    buf
221}
222
223/// Encode the `TriggerEffect` command request payload.
224#[must_use]
225#[allow(clippy::expect_used, clippy::missing_panics_doc)] // Vec-backed TlvWriter is infallible.
226pub fn encode_trigger_effect(
227    effect_identifier: EffectIdentifierEnum,
228    effect_variant: EffectVariantEnum,
229) -> Vec<u8> {
230    let mut buf = Vec::new();
231    let mut w = TlvWriter::new(&mut buf);
232    w.start_structure(Tag::Anonymous)
233        .expect("infallible: vec writer");
234    w.put_uint(Tag::Context(0), u64::from(effect_identifier.to_raw()))
235        .expect("infallible: vec writer");
236    w.put_uint(Tag::Context(1), u64::from(effect_variant.to_raw()))
237        .expect("infallible: vec writer");
238    w.end_container().expect("infallible: vec writer");
239    buf
240}