Skip to main content

matter_kit/clusters/generated/
on_off.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// On/Off — cluster 0x0006.
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//! On/Off (cluster `0x0006`, revision 6).
10//!
11//! 11 identifiers, 3 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 = 0x0006;
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 = "OO";
35
36/// The `FeatureMap` bits (Core §7.13.2).
37///
38/// A feature has conformance of its own: a device may not claim one the
39/// specification forbids it alongside another.
40pub mod feature {
41    /// Behavior that supports lighting applications.
42    ///
43    /// Code `LT`, bit 0.
44    pub const LIGHTING: u32 = 1 << 0;
45    /// Device has Dead Front behavior
46    ///
47    /// Code `DF`, bit 1.
48    pub const DEAD_FRONT_BEHAVIOR: u32 = 1 << 1;
49    /// Device supports the OffOnly Feature feature
50    ///
51    /// Code `OFFONLY`, bit 2.
52    pub const OFF_ONLY: u32 = 1 << 2;
53}
54
55/// Every feature bit, with its conformance.
56pub const FEATURES: &[Feature] = &[
57    Feature {
58        bit: 0,
59        code: "LT",
60        name: "Lighting",
61        conform: Conform {
62            clauses: &[Clause {
63                verdict: Conformance::Optional,
64                when: Condition::Not(&Condition::Feature(2)),
65            }],
66        },
67    },
68    Feature {
69        bit: 1,
70        code: "DF",
71        name: "DeadFrontBehavior",
72        conform: Conform {
73            clauses: &[Clause {
74                verdict: Conformance::Optional,
75                when: Condition::Not(&Condition::Feature(2)),
76            }],
77        },
78    },
79    Feature {
80        bit: 2,
81        code: "OFFONLY",
82        name: "OffOnly",
83        conform: Conform {
84            clauses: &[Clause {
85                verdict: Conformance::Optional,
86                when: Condition::Not(&Condition::Any(&[
87                    Condition::Feature(0),
88                    Condition::Feature(1),
89                ])),
90            }],
91        },
92    },
93];
94
95/// The attribute ids.
96pub mod attribute {
97    use crate::im::AttributeId;
98
99    /// `OnOff`.
100    pub const ON_OFF: AttributeId = 0x00;
101    /// `GlobalSceneControl`.
102    pub const GLOBAL_SCENE_CONTROL: AttributeId = 0x4000;
103    /// `OnTime`.
104    pub const ON_TIME: AttributeId = 0x4001;
105    /// `OffWaitTime`.
106    pub const OFF_WAIT_TIME: AttributeId = 0x4002;
107    /// `StartUpOnOff`.
108    pub const START_UP_ON_OFF: AttributeId = 0x4003;
109}
110
111/// The command ids.
112pub mod command {
113    use crate::im::CommandId;
114
115    /// `Off`.
116    pub const OFF: CommandId = 0x00;
117    /// `On`.
118    pub const ON: CommandId = 0x01;
119    /// `Toggle`.
120    pub const TOGGLE: CommandId = 0x02;
121    /// `OffWithEffect`.
122    pub const OFF_WITH_EFFECT: CommandId = 0x40;
123    /// `OnWithRecallGlobalScene`.
124    pub const ON_WITH_RECALL_GLOBAL_SCENE: CommandId = 0x41;
125    /// `OnWithTimedOff`.
126    pub const ON_WITH_TIMED_OFF: CommandId = 0x42;
127}
128
129/// `DelayedAllOffEffectVariantEnum`.
130#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
131#[repr(u8)]
132pub enum DelayedAllOffEffectVariantEnum {
133    /// Fade to off in 0.8 seconds
134    DelayedOffFastFade = 0,
135    /// No fade
136    NoFade = 1,
137    /// 50% dim down in 0.8 seconds then fade to off in 12 seconds
138    DelayedOffSlowFade = 2,
139}
140
141impl DelayedAllOffEffectVariantEnum {
142    /// Reads a wire value, or `None` for one this revision does not define.
143    #[must_use]
144    pub const fn from_value(value: u8) -> Option<Self> {
145        match value {
146            0 => Some(Self::DelayedOffFastFade),
147            1 => Some(Self::NoFade),
148            2 => Some(Self::DelayedOffSlowFade),
149            _ => None,
150        }
151    }
152
153    /// Its wire value.
154    #[must_use]
155    pub const fn value(self) -> u8 {
156        self as u8
157    }
158}
159
160impl ToTlv for DelayedAllOffEffectVariantEnum {
161    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
162        self.value().to_tlv(w, tag)
163    }
164}
165
166impl<'a> FromTlv<'a> for DelayedAllOffEffectVariantEnum {
167    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
168        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
169        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
170    }
171}
172
173/// `DyingLightEffectVariantEnum`.
174#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
175#[repr(u8)]
176pub enum DyingLightEffectVariantEnum {
177    /// 20% dim up in 0.5s then fade to off in 1 second
178    DyingLightFadeOff = 0,
179}
180
181impl DyingLightEffectVariantEnum {
182    /// Reads a wire value, or `None` for one this revision does not define.
183    #[must_use]
184    pub const fn from_value(value: u8) -> Option<Self> {
185        match value {
186            0 => Some(Self::DyingLightFadeOff),
187            _ => None,
188        }
189    }
190
191    /// Its wire value.
192    #[must_use]
193    pub const fn value(self) -> u8 {
194        self as u8
195    }
196}
197
198impl ToTlv for DyingLightEffectVariantEnum {
199    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
200        self.value().to_tlv(w, tag)
201    }
202}
203
204impl<'a> FromTlv<'a> for DyingLightEffectVariantEnum {
205    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
206        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
207        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
208    }
209}
210
211/// `EffectIdentifierEnum`.
212#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
213#[repr(u8)]
214pub enum EffectIdentifierEnum {
215    /// Delayed All Off
216    DelayedAllOff = 0,
217    /// Dying Light
218    DyingLight = 1,
219}
220
221impl EffectIdentifierEnum {
222    /// Reads a wire value, or `None` for one this revision does not define.
223    #[must_use]
224    pub const fn from_value(value: u8) -> Option<Self> {
225        match value {
226            0 => Some(Self::DelayedAllOff),
227            1 => Some(Self::DyingLight),
228            _ => None,
229        }
230    }
231
232    /// Its wire value.
233    #[must_use]
234    pub const fn value(self) -> u8 {
235        self as u8
236    }
237}
238
239impl ToTlv for EffectIdentifierEnum {
240    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
241        self.value().to_tlv(w, tag)
242    }
243}
244
245impl<'a> FromTlv<'a> for EffectIdentifierEnum {
246    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
247        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
248        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
249    }
250}
251
252/// `StartUpOnOffEnum`.
253#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
254#[repr(u8)]
255pub enum StartUpOnOffEnum {
256    /// Set the OnOff attribute to FALSE
257    Off = 0,
258    /// Set the OnOff attribute to TRUE
259    On = 1,
260    /// If the previous value of the OnOff attribute is equal to FALSE, set the OnOff attribute to TRUE. If the previous value of the OnOff attribute is equal to TRUE, set the OnOff attribute to FALSE (toggle).
261    Toggle = 2,
262}
263
264impl StartUpOnOffEnum {
265    /// Reads a wire value, or `None` for one this revision does not define.
266    #[must_use]
267    pub const fn from_value(value: u8) -> Option<Self> {
268        match value {
269            0 => Some(Self::Off),
270            1 => Some(Self::On),
271            2 => Some(Self::Toggle),
272            _ => None,
273        }
274    }
275
276    /// Its wire value.
277    #[must_use]
278    pub const fn value(self) -> u8 {
279        self as u8
280    }
281}
282
283impl ToTlv for StartUpOnOffEnum {
284    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
285        self.value().to_tlv(w, tag)
286    }
287}
288
289impl<'a> FromTlv<'a> for StartUpOnOffEnum {
290    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
291        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
292        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
293    }
294}
295
296bitflags::bitflags! {
297    /// `OnOffControlBitmap`.
298    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
299    pub struct OnOffControlBitmap: u8 {
300        /// Indicates a command is only accepted when in On state.
301        const ACCEPT_ONLY_WHEN_ON = 1 << 0;
302    }
303}
304
305impl ToTlv for OnOffControlBitmap {
306    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
307        self.bits().to_tlv(w, tag)
308    }
309}
310
311impl<'a> FromTlv<'a> for OnOffControlBitmap {
312    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
313        let bits = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
314        Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
315    }
316}
317
318/// The fields of `OffWithEffect` (command `0x40`).
319#[derive(Debug, Clone, Copy, PartialEq)]
320pub struct OffWithEffectFields {
321    /// `EffectIdentifier`, field 0.
322    pub effect_identifier: EffectIdentifierEnum,
323    /// `EffectVariant`, field 1.
324    pub effect_variant: u8,
325}
326
327impl ToTlv for OffWithEffectFields {
328    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
329        w.start_structure(tag)?;
330        self.effect_identifier.to_tlv(w, Tag::Context(0))?;
331        self.effect_variant.to_tlv(w, Tag::Context(1))?;
332        w.end_container()
333    }
334}
335
336impl<'a> FromTlv<'a> for OffWithEffectFields {
337    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
338        if element.value.container() != Some(ContainerKind::Structure) {
339            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
340        }
341        let mut effect_identifier = None;
342        let mut effect_variant = None;
343        loop {
344            let Some(field) = reader.next_element()? else {
345                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
346            };
347            if field.value == Value::EndOfContainer {
348                break;
349            }
350            match field.tag.context() {
351                Some(0) => {
352                    effect_identifier = Some(<EffectIdentifierEnum>::from_tlv(reader, &field)?)
353                }
354                Some(1) => effect_variant = Some(<u8>::from_tlv(reader, &field)?),
355                // A field this revision does not define. §7.19.2: a receiver
356                // ignores what it does not know rather than refusing the whole
357                // structure, which is what lets a newer peer talk to an older one.
358                _ => reader.skip_value(&field)?,
359            }
360        }
361        Ok(Self {
362            effect_identifier: effect_identifier
363                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
364            effect_variant: effect_variant
365                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
366        })
367    }
368}
369
370/// The fields of `OnWithTimedOff` (command `0x42`).
371#[derive(Debug, Clone, Copy, PartialEq)]
372pub struct OnWithTimedOffFields {
373    /// `OnOffControl`, field 0.
374    pub on_off_control: OnOffControlBitmap,
375    /// `OnTime`, field 1.
376    pub on_time: u16,
377    /// `OffWaitTime`, field 2.
378    pub off_wait_time: u16,
379}
380
381impl ToTlv for OnWithTimedOffFields {
382    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
383        w.start_structure(tag)?;
384        self.on_off_control.to_tlv(w, Tag::Context(0))?;
385        self.on_time.to_tlv(w, Tag::Context(1))?;
386        self.off_wait_time.to_tlv(w, Tag::Context(2))?;
387        w.end_container()
388    }
389}
390
391impl<'a> FromTlv<'a> for OnWithTimedOffFields {
392    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
393        if element.value.container() != Some(ContainerKind::Structure) {
394            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
395        }
396        let mut on_off_control = None;
397        let mut on_time = None;
398        let mut off_wait_time = None;
399        loop {
400            let Some(field) = reader.next_element()? else {
401                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
402            };
403            if field.value == Value::EndOfContainer {
404                break;
405            }
406            match field.tag.context() {
407                Some(0) => on_off_control = Some(<OnOffControlBitmap>::from_tlv(reader, &field)?),
408                Some(1) => on_time = Some(<u16>::from_tlv(reader, &field)?),
409                Some(2) => off_wait_time = Some(<u16>::from_tlv(reader, &field)?),
410                // A field this revision does not define. §7.19.2: a receiver
411                // ignores what it does not know rather than refusing the whole
412                // structure, which is what lets a newer peer talk to an older one.
413                _ => reader.skip_value(&field)?,
414            }
415        }
416        Ok(Self {
417            on_off_control: on_off_control
418                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
419            on_time: on_time.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
420            off_wait_time: off_wait_time.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
421        })
422    }
423}
424
425/// Every attribute the specification defines, with its conformance.
426pub const ATTRIBUTES: &[Attribute] = &[
427    Attribute {
428        id: 0x0000,
429        name: "OnOff",
430        kind: "bool",
431        access: Access::read_only(Privilege::View),
432        qualities: AttributeQualities::NON_VOLATILE.union(AttributeQualities::SCENE),
433        reporting: Reporting::OnChange,
434        conform: Conform::MANDATORY,
435    },
436    Attribute {
437        id: 0x4000,
438        name: "GlobalSceneControl",
439        kind: "bool",
440        access: Access::read_only(Privilege::View),
441        qualities: AttributeQualities::empty(),
442        reporting: Reporting::OnChange,
443        conform: Conform {
444            clauses: &[Clause {
445                verdict: Conformance::Mandatory,
446                when: Condition::Feature(0),
447            }],
448        },
449    },
450    Attribute {
451        id: 0x4001,
452        name: "OnTime",
453        kind: "uint16",
454        access: Access::read_write_with(Privilege::View, Privilege::Operate),
455        qualities: AttributeQualities::empty(),
456        reporting: Reporting::OnChange,
457        conform: Conform {
458            clauses: &[Clause {
459                verdict: Conformance::Mandatory,
460                when: Condition::Feature(0),
461            }],
462        },
463    },
464    Attribute {
465        id: 0x4002,
466        name: "OffWaitTime",
467        kind: "uint16",
468        access: Access::read_write_with(Privilege::View, Privilege::Operate),
469        qualities: AttributeQualities::empty(),
470        reporting: Reporting::OnChange,
471        conform: Conform {
472            clauses: &[Clause {
473                verdict: Conformance::Mandatory,
474                when: Condition::Feature(0),
475            }],
476        },
477    },
478    Attribute {
479        id: 0x4003,
480        name: "StartUpOnOff",
481        kind: "StartUpOnOffEnum",
482        access: Access::read_write_with(Privilege::View, Privilege::Manage),
483        qualities: AttributeQualities::NULLABLE.union(AttributeQualities::NON_VOLATILE),
484        reporting: Reporting::OnChange,
485        conform: Conform {
486            clauses: &[Clause {
487                verdict: Conformance::Mandatory,
488                when: Condition::Feature(0),
489            }],
490        },
491    },
492];
493
494/// Every command, with its conformance.
495pub const COMMANDS: &[Command] = &[
496    Command {
497        id: 0x00,
498        name: "Off",
499        to_server: true,
500        response: None,
501        access: Access::invoke(Privilege::Operate),
502        conform: Conform::MANDATORY,
503    },
504    Command {
505        id: 0x01,
506        name: "On",
507        to_server: true,
508        response: None,
509        access: Access::invoke(Privilege::Operate),
510        conform: Conform {
511            clauses: &[Clause {
512                verdict: Conformance::Mandatory,
513                when: Condition::Not(&Condition::Feature(2)),
514            }],
515        },
516    },
517    Command {
518        id: 0x02,
519        name: "Toggle",
520        to_server: true,
521        response: None,
522        access: Access::invoke(Privilege::Operate),
523        conform: Conform {
524            clauses: &[Clause {
525                verdict: Conformance::Mandatory,
526                when: Condition::Not(&Condition::Feature(2)),
527            }],
528        },
529    },
530    Command {
531        id: 0x40,
532        name: "OffWithEffect",
533        to_server: true,
534        response: None,
535        access: Access::invoke(Privilege::Operate),
536        conform: Conform {
537            clauses: &[Clause {
538                verdict: Conformance::Mandatory,
539                when: Condition::Feature(0),
540            }],
541        },
542    },
543    Command {
544        id: 0x41,
545        name: "OnWithRecallGlobalScene",
546        to_server: true,
547        response: None,
548        access: Access::invoke(Privilege::Operate),
549        conform: Conform {
550            clauses: &[Clause {
551                verdict: Conformance::Mandatory,
552                when: Condition::Feature(0),
553            }],
554        },
555    },
556    Command {
557        id: 0x42,
558        name: "OnWithTimedOff",
559        to_server: true,
560        response: None,
561        access: Access::invoke(Privilege::Operate),
562        conform: Conform {
563            clauses: &[Clause {
564                verdict: Conformance::Mandatory,
565                when: Condition::Feature(0),
566            }],
567        },
568    },
569];
570
571/// Every event, with its conformance.
572pub const EVENTS: &[Event] = &[];
573
574/// The whole cluster, as the specification defines it.
575pub const CLUSTER: Cluster = Cluster {
576    id: ID,
577    name: "On/Off",
578    revision: REVISION,
579    pics: "OO",
580    derived_from: None,
581    features: FEATURES,
582    attributes: ATTRIBUTES,
583    commands: COMMANDS,
584    events: EVENTS,
585};