Skip to main content

matter_kit/clusters/generated/
boolean_state_configuration.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Boolean State Configuration — cluster 0x0080.
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//! Boolean State Configuration (cluster `0x0080`, revision 2).
10//!
11//! 12 identifiers, 5 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 = 0x0080;
28
29/// The highest revision the specification's history defines — what `ClusterRevision`
30/// must report (Core §7.13.1).
31pub const REVISION: u16 = 2;
32
33/// The PICS code, which a certification declaration names the cluster by.
34pub const PICS: &str = "BOOLCFG";
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    /// Supports visual alarms
42    ///
43    /// Code `VIS`, bit 0.
44    pub const VISUAL: u32 = 1 << 0;
45    /// Supports audible alarms
46    ///
47    /// Code `AUD`, bit 1.
48    pub const AUDIBLE: u32 = 1 << 1;
49    /// Supports ability to suppress or acknowledge alarms
50    ///
51    /// Code `SPRS`, bit 2.
52    pub const ALARM_SUPPRESS: u32 = 1 << 2;
53    /// Supports ability to set sensor sensitivity
54    ///
55    /// Code `SENSLVL`, bit 3.
56    pub const SENSITIVITY_LEVEL: u32 = 1 << 3;
57    /// Supports reporting fault events
58    ///
59    /// Code `FAULTEV`, bit 4.
60    pub const FAULT_EVENTS: u32 = 1 << 4;
61}
62
63/// Every feature bit, with its conformance.
64pub const FEATURES: &[Feature] = &[
65    Feature {
66        bit: 0,
67        code: "VIS",
68        name: "Visual",
69        conform: Conform::OPTIONAL,
70    },
71    Feature {
72        bit: 1,
73        code: "AUD",
74        name: "Audible",
75        conform: Conform::OPTIONAL,
76    },
77    Feature {
78        bit: 2,
79        code: "SPRS",
80        name: "AlarmSuppress",
81        conform: Conform {
82            clauses: &[Clause {
83                verdict: Conformance::Optional,
84                when: Condition::Any(&[Condition::Feature(0), Condition::Feature(1)]),
85            }],
86        },
87    },
88    Feature {
89        bit: 3,
90        code: "SENSLVL",
91        name: "SensitivityLevel",
92        conform: Conform::OPTIONAL,
93    },
94    Feature {
95        bit: 4,
96        code: "FAULTEV",
97        name: "FaultEvents",
98        conform: Conform {
99            clauses: &[Clause {
100                verdict: Conformance::Described,
101                when: Condition::Named("comparison"),
102            }],
103        },
104    },
105];
106
107/// The attribute ids.
108pub mod attribute {
109    use crate::im::AttributeId;
110
111    /// `CurrentSensitivityLevel`.
112    pub const CURRENT_SENSITIVITY_LEVEL: AttributeId = 0x00;
113    /// `SupportedSensitivityLevels`.
114    pub const SUPPORTED_SENSITIVITY_LEVELS: AttributeId = 0x01;
115    /// `DefaultSensitivityLevel`.
116    pub const DEFAULT_SENSITIVITY_LEVEL: AttributeId = 0x02;
117    /// `AlarmsActive`.
118    pub const ALARMS_ACTIVE: AttributeId = 0x03;
119    /// `AlarmsSuppressed`.
120    pub const ALARMS_SUPPRESSED: AttributeId = 0x04;
121    /// `AlarmsEnabled`.
122    pub const ALARMS_ENABLED: AttributeId = 0x05;
123    /// `AlarmsSupported`.
124    pub const ALARMS_SUPPORTED: AttributeId = 0x06;
125    /// `SensorFault`.
126    pub const SENSOR_FAULT: AttributeId = 0x07;
127}
128
129/// The command ids.
130pub mod command {
131    use crate::im::CommandId;
132
133    /// `SuppressAlarm`.
134    pub const SUPPRESS_ALARM: CommandId = 0x00;
135    /// `EnableDisableAlarm`.
136    pub const ENABLE_DISABLE_ALARM: CommandId = 0x01;
137}
138
139/// The event ids.
140pub mod event {
141    use crate::im::EventId;
142
143    /// `AlarmsStateChanged`.
144    pub const ALARMS_STATE_CHANGED: EventId = 0x00;
145    /// `SensorFault`.
146    pub const SENSOR_FAULT: EventId = 0x01;
147}
148
149bitflags::bitflags! {
150    /// `AlarmModeBitmap`.
151    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
152    pub struct AlarmModeBitmap: u8 {
153        /// Visual alarming
154        const VISUAL = 1 << 0;
155        /// Audible alarming
156        const AUDIBLE = 1 << 1;
157    }
158}
159
160impl ToTlv for AlarmModeBitmap {
161    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
162        self.bits().to_tlv(w, tag)
163    }
164}
165
166impl<'a> FromTlv<'a> for AlarmModeBitmap {
167    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
168        let bits = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
169        Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
170    }
171}
172
173bitflags::bitflags! {
174    /// `SensorFaultBitmap`.
175    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
176    pub struct SensorFaultBitmap: u8 {
177        /// Unspecified fault detected
178        const GENERAL_FAULT = 1 << 0;
179    }
180}
181
182impl ToTlv for SensorFaultBitmap {
183    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
184        self.bits().to_tlv(w, tag)
185    }
186}
187
188impl<'a> FromTlv<'a> for SensorFaultBitmap {
189    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
190        let bits = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
191        Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
192    }
193}
194
195/// The fields of `SuppressAlarm` (command `0x00`).
196#[derive(Debug, Clone, Copy, PartialEq)]
197pub struct SuppressAlarmFields {
198    /// `AlarmsToSuppress`, field 0.
199    pub alarms_to_suppress: AlarmModeBitmap,
200}
201
202impl ToTlv for SuppressAlarmFields {
203    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
204        w.start_structure(tag)?;
205        self.alarms_to_suppress.to_tlv(w, Tag::Context(0))?;
206        w.end_container()
207    }
208}
209
210impl<'a> FromTlv<'a> for SuppressAlarmFields {
211    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
212        if element.value.container() != Some(ContainerKind::Structure) {
213            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
214        }
215        let mut alarms_to_suppress = None;
216        loop {
217            let Some(field) = reader.next_element()? else {
218                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
219            };
220            if field.value == Value::EndOfContainer {
221                break;
222            }
223            match field.tag.context() {
224                Some(0) => alarms_to_suppress = Some(<AlarmModeBitmap>::from_tlv(reader, &field)?),
225                // A field this revision does not define. §7.19.2: a receiver
226                // ignores what it does not know rather than refusing the whole
227                // structure, which is what lets a newer peer talk to an older one.
228                _ => reader.skip_value(&field)?,
229            }
230        }
231        Ok(Self {
232            alarms_to_suppress: alarms_to_suppress
233                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
234        })
235    }
236}
237
238/// The fields of `EnableDisableAlarm` (command `0x01`).
239#[derive(Debug, Clone, Copy, PartialEq)]
240pub struct EnableDisableAlarmFields {
241    /// `AlarmsToEnableDisable`, field 0.
242    pub alarms_to_enable_disable: AlarmModeBitmap,
243}
244
245impl ToTlv for EnableDisableAlarmFields {
246    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
247        w.start_structure(tag)?;
248        self.alarms_to_enable_disable.to_tlv(w, Tag::Context(0))?;
249        w.end_container()
250    }
251}
252
253impl<'a> FromTlv<'a> for EnableDisableAlarmFields {
254    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
255        if element.value.container() != Some(ContainerKind::Structure) {
256            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
257        }
258        let mut alarms_to_enable_disable = None;
259        loop {
260            let Some(field) = reader.next_element()? else {
261                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
262            };
263            if field.value == Value::EndOfContainer {
264                break;
265            }
266            match field.tag.context() {
267                Some(0) => {
268                    alarms_to_enable_disable = Some(<AlarmModeBitmap>::from_tlv(reader, &field)?)
269                }
270                // A field this revision does not define. §7.19.2: a receiver
271                // ignores what it does not know rather than refusing the whole
272                // structure, which is what lets a newer peer talk to an older one.
273                _ => reader.skip_value(&field)?,
274            }
275        }
276        Ok(Self {
277            alarms_to_enable_disable: alarms_to_enable_disable
278                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
279        })
280    }
281}
282
283/// Every attribute the specification defines, with its conformance.
284pub const ATTRIBUTES: &[Attribute] = &[
285    Attribute {
286        id: 0x0000,
287        name: "CurrentSensitivityLevel",
288        kind: "uint8",
289        access: Access::read_write_with(Privilege::View, Privilege::Operate),
290        qualities: AttributeQualities::NON_VOLATILE,
291        reporting: Reporting::OnChange,
292        conform: Conform {
293            clauses: &[Clause {
294                verdict: Conformance::Mandatory,
295                when: Condition::Feature(3),
296            }],
297        },
298    },
299    Attribute {
300        id: 0x0001,
301        name: "SupportedSensitivityLevels",
302        kind: "uint8",
303        access: Access::read_only(Privilege::View),
304        qualities: AttributeQualities::FIXED,
305        reporting: Reporting::OnChange,
306        conform: Conform {
307            clauses: &[Clause {
308                verdict: Conformance::Mandatory,
309                when: Condition::Feature(3),
310            }],
311        },
312    },
313    Attribute {
314        id: 0x0002,
315        name: "DefaultSensitivityLevel",
316        kind: "uint8",
317        access: Access::read_only(Privilege::View),
318        qualities: AttributeQualities::FIXED,
319        reporting: Reporting::OnChange,
320        conform: Conform {
321            clauses: &[Clause {
322                verdict: Conformance::Optional,
323                when: Condition::Feature(3),
324            }],
325        },
326    },
327    Attribute {
328        id: 0x0003,
329        name: "AlarmsActive",
330        kind: "AlarmModeBitmap",
331        access: Access::read_only(Privilege::View),
332        qualities: AttributeQualities::empty(),
333        reporting: Reporting::OnChange,
334        conform: Conform {
335            clauses: &[Clause {
336                verdict: Conformance::Mandatory,
337                when: Condition::Any(&[Condition::Feature(0), Condition::Feature(1)]),
338            }],
339        },
340    },
341    Attribute {
342        id: 0x0004,
343        name: "AlarmsSuppressed",
344        kind: "AlarmModeBitmap",
345        access: Access::read_only(Privilege::View),
346        qualities: AttributeQualities::empty(),
347        reporting: Reporting::OnChange,
348        conform: Conform {
349            clauses: &[Clause {
350                verdict: Conformance::Mandatory,
351                when: Condition::Feature(2),
352            }],
353        },
354    },
355    Attribute {
356        id: 0x0005,
357        name: "AlarmsEnabled",
358        kind: "AlarmModeBitmap",
359        access: Access::read_only(Privilege::View),
360        qualities: AttributeQualities::NON_VOLATILE,
361        reporting: Reporting::OnChange,
362        conform: Conform {
363            clauses: &[Clause {
364                verdict: Conformance::Optional,
365                when: Condition::Any(&[Condition::Feature(0), Condition::Feature(1)]),
366            }],
367        },
368    },
369    Attribute {
370        id: 0x0006,
371        name: "AlarmsSupported",
372        kind: "AlarmModeBitmap",
373        access: Access::read_only(Privilege::View),
374        qualities: AttributeQualities::FIXED,
375        reporting: Reporting::OnChange,
376        conform: Conform {
377            clauses: &[Clause {
378                verdict: Conformance::Mandatory,
379                when: Condition::Any(&[Condition::Feature(0), Condition::Feature(1)]),
380            }],
381        },
382    },
383    Attribute {
384        id: 0x0007,
385        name: "SensorFault",
386        kind: "SensorFaultBitmap",
387        access: Access::read_only(Privilege::View),
388        qualities: AttributeQualities::empty(),
389        reporting: Reporting::OnChange,
390        conform: Conform::OPTIONAL,
391    },
392];
393
394/// Every command, with its conformance.
395pub const COMMANDS: &[Command] = &[
396    Command {
397        id: 0x00,
398        name: "SuppressAlarm",
399        to_server: true,
400        response: None,
401        access: Access::invoke(Privilege::Operate),
402        conform: Conform {
403            clauses: &[Clause {
404                verdict: Conformance::Mandatory,
405                when: Condition::Feature(2),
406            }],
407        },
408    },
409    Command {
410        id: 0x01,
411        name: "EnableDisableAlarm",
412        to_server: true,
413        response: None,
414        access: Access::invoke(Privilege::Operate),
415        conform: Conform {
416            clauses: &[Clause {
417                verdict: Conformance::Mandatory,
418                when: Condition::Any(&[Condition::Feature(0), Condition::Feature(1)]),
419            }],
420        },
421    },
422];
423
424/// Every event, with its conformance.
425pub const EVENTS: &[Event] = &[
426    Event {
427        id: 0x00,
428        name: "AlarmsStateChanged",
429        priority: EventPriority::Info,
430        access: Access::read_only(Privilege::View),
431        conform: Conform {
432            clauses: &[Clause {
433                verdict: Conformance::Mandatory,
434                when: Condition::Any(&[Condition::Feature(0), Condition::Feature(1)]),
435            }],
436        },
437    },
438    Event {
439        id: 0x01,
440        name: "SensorFault",
441        priority: EventPriority::Info,
442        access: Access::read_only(Privilege::View),
443        conform: Conform {
444            clauses: &[
445                Clause {
446                    verdict: Conformance::Mandatory,
447                    when: Condition::Feature(4),
448                },
449                Clause {
450                    verdict: Conformance::Optional,
451                    when: Condition::Always,
452                },
453            ],
454        },
455    },
456];
457
458/// The whole cluster, as the specification defines it.
459pub const CLUSTER: Cluster = Cluster {
460    id: ID,
461    name: "Boolean State Configuration",
462    revision: REVISION,
463    pics: "BOOLCFG",
464    derived_from: None,
465    features: FEATURES,
466    attributes: ATTRIBUTES,
467    commands: COMMANDS,
468    events: EVENTS,
469};