Skip to main content

matter_kit/clusters/generated/
identify.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Identify — cluster 0x0003.
4//
5// Regenerate with `cargo xtask clusters --dm <checkout>/data_model/1.6`; `cargo xtask check`
6// is the CI gate that keeps this file honest. The XML itself is not vendored here — it
7// carries the CSA's own copyright notice and is not redistributable.
8
9//! Identify (cluster `0x0003`, revision 6).
10//!
11//! 4 identifiers, 0 feature bits, and the specification's own conformance for
12//! every element. `CLUSTER` is the whole table.
13
14#![allow(unused_imports)]
15
16use crate::dm::conformance::{Clause, Condition, Conform, Conformance};
17use crate::dm::meta::{EventPriority, Reporting};
18use crate::dm::spec::{Attribute, Cluster, Command, Event, Feature};
19use crate::dm::{Access, AccessQualities, AttributeQualities, Privilege};
20use crate::error::Result;
21use crate::im::{AttributeId, ClusterId, CommandId, EventId};
22use crate::tlv::{
23    ContainerKind, Element, FromTlv, Nullable, Tag, TlvList, TlvReader, TlvWriter, ToTlv, Value,
24};
25
26/// The cluster id.
27pub const ID: ClusterId = 0x0003;
28
29/// The highest revision the specification's history defines — what `ClusterRevision`
30/// must report (Core §7.13.1).
31pub const REVISION: u16 = 6;
32
33/// The PICS code, which a certification declaration names the cluster by.
34pub const PICS: &str = "I";
35
36/// This cluster defines no features, so its `FeatureMap` is always zero.
37pub const FEATURES: &[Feature] = &[];
38
39/// The attribute ids.
40pub mod attribute {
41    use crate::im::AttributeId;
42
43    /// `IdentifyTime`.
44    pub const IDENTIFY_TIME: AttributeId = 0x00;
45    /// `IdentifyType`.
46    pub const IDENTIFY_TYPE: AttributeId = 0x01;
47}
48
49/// The command ids.
50pub mod command {
51    use crate::im::CommandId;
52
53    /// `Identify`.
54    pub const IDENTIFY: CommandId = 0x00;
55    /// `TriggerEffect`.
56    pub const TRIGGER_EFFECT: CommandId = 0x40;
57}
58
59/// `EffectIdentifierEnum`.
60#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
61#[repr(u8)]
62pub enum EffectIdentifierEnum {
63    /// e.g., Light is turned on/off once.
64    Blink = 0,
65    /// e.g., Light is turned on/off over 1 second and repeated 15 times.
66    Breathe = 1,
67    /// e.g., Colored light turns green for 1 second; non-colored light flashes twice.
68    Okay = 2,
69    /// e.g., Colored light turns orange for 8 seconds; non-colored light switches to the maximum brightness for 0.5s and then minimum brightness for 7.5s.
70    ChannelChange = 11,
71    /// Complete the current effect sequence before terminating. e.g., if in the middle of a breathe effect (as above), first complete the current 1s breathe effect and then terminate the effect.
72    FinishEffect = 254,
73    /// Terminate the effect as soon as possible.
74    StopEffect = 255,
75}
76
77impl EffectIdentifierEnum {
78    /// Reads a wire value, or `None` for one this revision does not define.
79    #[must_use]
80    pub const fn from_value(value: u8) -> Option<Self> {
81        match value {
82            0 => Some(Self::Blink),
83            1 => Some(Self::Breathe),
84            2 => Some(Self::Okay),
85            11 => Some(Self::ChannelChange),
86            254 => Some(Self::FinishEffect),
87            255 => Some(Self::StopEffect),
88            _ => None,
89        }
90    }
91
92    /// Its wire value.
93    #[must_use]
94    pub const fn value(self) -> u8 {
95        self as u8
96    }
97}
98
99impl ToTlv for EffectIdentifierEnum {
100    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
101        self.value().to_tlv(w, tag)
102    }
103}
104
105impl<'a> FromTlv<'a> for EffectIdentifierEnum {
106    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
107        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
108        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
109    }
110}
111
112/// `EffectVariantEnum`.
113#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
114#[repr(u8)]
115pub enum EffectVariantEnum {
116    /// Indicates the default effect is used
117    Default = 0,
118}
119
120impl EffectVariantEnum {
121    /// Reads a wire value, or `None` for one this revision does not define.
122    #[must_use]
123    pub const fn from_value(value: u8) -> Option<Self> {
124        match value {
125            0 => Some(Self::Default),
126            _ => None,
127        }
128    }
129
130    /// Its wire value.
131    #[must_use]
132    pub const fn value(self) -> u8 {
133        self as u8
134    }
135}
136
137impl ToTlv for EffectVariantEnum {
138    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
139        self.value().to_tlv(w, tag)
140    }
141}
142
143impl<'a> FromTlv<'a> for EffectVariantEnum {
144    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
145        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
146        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
147    }
148}
149
150/// `IdentifyTypeEnum`.
151#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
152#[repr(u8)]
153pub enum IdentifyTypeEnum {
154    /// No presentation.
155    None = 0,
156    /// Light output of a lighting product.
157    LightOutput = 1,
158    /// Typically a small LED.
159    VisibleIndicator = 2,
160    /// `AudibleBeep`.
161    AudibleBeep = 3,
162    /// Presentation will be visible on display screen.
163    Display = 4,
164    /// Presentation will be conveyed by actuator functionality such as through a window blind operation or in-wall relay.
165    Actuator = 5,
166}
167
168impl IdentifyTypeEnum {
169    /// Reads a wire value, or `None` for one this revision does not define.
170    #[must_use]
171    pub const fn from_value(value: u8) -> Option<Self> {
172        match value {
173            0 => Some(Self::None),
174            1 => Some(Self::LightOutput),
175            2 => Some(Self::VisibleIndicator),
176            3 => Some(Self::AudibleBeep),
177            4 => Some(Self::Display),
178            5 => Some(Self::Actuator),
179            _ => None,
180        }
181    }
182
183    /// Its wire value.
184    #[must_use]
185    pub const fn value(self) -> u8 {
186        self as u8
187    }
188}
189
190impl ToTlv for IdentifyTypeEnum {
191    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
192        self.value().to_tlv(w, tag)
193    }
194}
195
196impl<'a> FromTlv<'a> for IdentifyTypeEnum {
197    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
198        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
199        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
200    }
201}
202
203/// The fields of `Identify` (command `0x00`).
204#[derive(Debug, Clone, Copy, PartialEq)]
205pub struct IdentifyFields {
206    /// `IdentifyTime`, field 0.
207    pub identify_time: u16,
208}
209
210impl ToTlv for IdentifyFields {
211    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
212        w.start_structure(tag)?;
213        self.identify_time.to_tlv(w, Tag::Context(0))?;
214        w.end_container()
215    }
216}
217
218impl<'a> FromTlv<'a> for IdentifyFields {
219    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
220        if element.value.container() != Some(ContainerKind::Structure) {
221            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
222        }
223        let mut identify_time = None;
224        loop {
225            let Some(field) = reader.next_element()? else {
226                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
227            };
228            if field.value == Value::EndOfContainer {
229                break;
230            }
231            match field.tag.context() {
232                Some(0) => identify_time = Some(<u16>::from_tlv(reader, &field)?),
233                // A field this revision does not define. §7.19.2: a receiver
234                // ignores what it does not know rather than refusing the whole
235                // structure, which is what lets a newer peer talk to an older one.
236                _ => reader.skip_value(&field)?,
237            }
238        }
239        Ok(Self {
240            identify_time: identify_time.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
241        })
242    }
243}
244
245/// The fields of `TriggerEffect` (command `0x40`).
246#[derive(Debug, Clone, Copy, PartialEq)]
247pub struct TriggerEffectFields {
248    /// `EffectIdentifier`, field 0.
249    pub effect_identifier: EffectIdentifierEnum,
250    /// `EffectVariant`, field 1.
251    pub effect_variant: EffectVariantEnum,
252}
253
254impl ToTlv for TriggerEffectFields {
255    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
256        w.start_structure(tag)?;
257        self.effect_identifier.to_tlv(w, Tag::Context(0))?;
258        self.effect_variant.to_tlv(w, Tag::Context(1))?;
259        w.end_container()
260    }
261}
262
263impl<'a> FromTlv<'a> for TriggerEffectFields {
264    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
265        if element.value.container() != Some(ContainerKind::Structure) {
266            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
267        }
268        let mut effect_identifier = None;
269        let mut effect_variant = None;
270        loop {
271            let Some(field) = reader.next_element()? else {
272                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
273            };
274            if field.value == Value::EndOfContainer {
275                break;
276            }
277            match field.tag.context() {
278                Some(0) => {
279                    effect_identifier = Some(<EffectIdentifierEnum>::from_tlv(reader, &field)?)
280                }
281                Some(1) => effect_variant = Some(<EffectVariantEnum>::from_tlv(reader, &field)?),
282                // A field this revision does not define. §7.19.2: a receiver
283                // ignores what it does not know rather than refusing the whole
284                // structure, which is what lets a newer peer talk to an older one.
285                _ => reader.skip_value(&field)?,
286            }
287        }
288        Ok(Self {
289            effect_identifier: effect_identifier
290                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
291            effect_variant: effect_variant
292                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
293        })
294    }
295}
296
297/// Every attribute the specification defines, with its conformance.
298pub const ATTRIBUTES: &[Attribute] = &[
299    Attribute {
300        id: 0x0000,
301        name: "IdentifyTime",
302        kind: "uint16",
303        access: Access::read_write_with(Privilege::View, Privilege::Operate),
304        qualities: AttributeQualities::empty(),
305        reporting: Reporting::Quieter,
306        conform: Conform::MANDATORY,
307    },
308    Attribute {
309        id: 0x0001,
310        name: "IdentifyType",
311        kind: "IdentifyTypeEnum",
312        access: Access::read_only(Privilege::View),
313        qualities: AttributeQualities::empty(),
314        reporting: Reporting::OnChange,
315        conform: Conform::MANDATORY,
316    },
317];
318
319/// Every command, with its conformance.
320pub const COMMANDS: &[Command] = &[
321    Command {
322        id: 0x00,
323        name: "Identify",
324        to_server: true,
325        response: None,
326        access: Access::invoke(Privilege::Manage),
327        conform: Conform::MANDATORY,
328    },
329    Command {
330        id: 0x40,
331        name: "TriggerEffect",
332        to_server: true,
333        response: None,
334        access: Access::invoke(Privilege::Manage),
335        conform: Conform::OPTIONAL,
336    },
337];
338
339/// Every event, with its conformance.
340pub const EVENTS: &[Event] = &[];
341
342/// The whole cluster, as the specification defines it.
343pub const CLUSTER: Cluster = Cluster {
344    id: ID,
345    name: "Identify",
346    revision: REVISION,
347    pics: "I",
348    derived_from: None,
349    features: FEATURES,
350    attributes: ATTRIBUTES,
351    commands: COMMANDS,
352    events: EVENTS,
353};