Skip to main content

matter_kit/clusters/generated/
zone_management.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Zone Management — cluster 0x0550.
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//! Zone Management (cluster `0x0550`, revision 1).
10//!
11//! 15 identifiers, 4 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 = 0x0550;
28
29/// The highest revision the specification's history defines — what `ClusterRevision`
30/// must report (Core §7.13.1).
31pub const REVISION: u16 = 1;
32
33/// The PICS code, which a certification declaration names the cluster by.
34pub const PICS: &str = "ZONEMGMT";
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 Two Dimensional Cartesian Zones
42    ///
43    /// Code `TWODCART`, bit 0.
44    pub const TWO_DIMENSIONAL_CARTESIAN_ZONE: u32 = 1 << 0;
45    /// Supports a sensitivity value per Zone
46    ///
47    /// Code `PERZONESENS`, bit 1.
48    pub const PER_ZONE_SENSITIVITY: u32 = 1 << 1;
49    /// Supports user defined zones
50    ///
51    /// Code `USERDEFINED`, bit 2.
52    pub const USER_DEFINED: u32 = 1 << 2;
53    /// Supports user defined focus zones
54    ///
55    /// Code `FOCUSZONES`, bit 3.
56    pub const FOCUS_ZONES: u32 = 1 << 3;
57}
58
59/// Every feature bit, with its conformance.
60pub const FEATURES: &[Feature] = &[
61    Feature {
62        bit: 0,
63        code: "TWODCART",
64        name: "TwoDimensionalCartesianZone",
65        conform: Conform::OPTIONAL,
66    },
67    Feature {
68        bit: 1,
69        code: "PERZONESENS",
70        name: "PerZoneSensitivity",
71        conform: Conform {
72            clauses: &[Clause {
73                verdict: Conformance::Optional,
74                when: Condition::Feature(0),
75            }],
76        },
77    },
78    Feature {
79        bit: 2,
80        code: "USERDEFINED",
81        name: "UserDefined",
82        conform: Conform {
83            clauses: &[Clause {
84                verdict: Conformance::Optional,
85                when: Condition::Feature(0),
86            }],
87        },
88    },
89    Feature {
90        bit: 3,
91        code: "FOCUSZONES",
92        name: "FocusZones",
93        conform: Conform {
94            clauses: &[Clause {
95                verdict: Conformance::Optional,
96                when: Condition::Feature(2),
97            }],
98        },
99    },
100];
101
102/// The attribute ids.
103pub mod attribute {
104    use crate::im::AttributeId;
105
106    /// `MaxUserDefinedZones`.
107    pub const MAX_USER_DEFINED_ZONES: AttributeId = 0x00;
108    /// `MaxZones`.
109    pub const MAX_ZONES: AttributeId = 0x01;
110    /// `Zones`.
111    pub const ZONES: AttributeId = 0x02;
112    /// `Triggers`.
113    pub const TRIGGERS: AttributeId = 0x03;
114    /// `SensitivityMax`.
115    pub const SENSITIVITY_MAX: AttributeId = 0x04;
116    /// `Sensitivity`.
117    pub const SENSITIVITY: AttributeId = 0x05;
118    /// `TwoDCartesianMax`.
119    pub const TWO_D_CARTESIAN_MAX: AttributeId = 0x06;
120}
121
122/// The command ids.
123pub mod command {
124    use crate::im::CommandId;
125
126    /// `CreateTwoDCartesianZone`.
127    pub const CREATE_TWO_D_CARTESIAN_ZONE: CommandId = 0x00;
128    /// `CreateTwoDCartesianZoneResponse`.
129    pub const CREATE_TWO_D_CARTESIAN_ZONE_RESPONSE: CommandId = 0x01;
130    /// `UpdateTwoDCartesianZone`.
131    pub const UPDATE_TWO_D_CARTESIAN_ZONE: CommandId = 0x02;
132    /// `RemoveZone`.
133    pub const REMOVE_ZONE: CommandId = 0x03;
134    /// `CreateOrUpdateTrigger`.
135    pub const CREATE_OR_UPDATE_TRIGGER: CommandId = 0x04;
136    /// `RemoveTrigger`.
137    pub const REMOVE_TRIGGER: CommandId = 0x05;
138}
139
140/// The event ids.
141pub mod event {
142    use crate::im::EventId;
143
144    /// `ZoneTriggered`.
145    pub const ZONE_TRIGGERED: EventId = 0x00;
146    /// `ZoneStopped`.
147    pub const ZONE_STOPPED: EventId = 0x01;
148}
149
150/// `ZoneEventStoppedReasonEnum`.
151#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
152#[repr(u8)]
153pub enum ZoneEventStoppedReasonEnum {
154    /// Indicates that whatever triggered the Zone event has stopped being detected.
155    ActionStopped = 0,
156    /// Indicates that the max duration for detecting triggering activity has been reached.
157    Timeout = 1,
158}
159
160impl ZoneEventStoppedReasonEnum {
161    /// Reads a wire value, or `None` for one this revision does not define.
162    #[must_use]
163    pub const fn from_value(value: u8) -> Option<Self> {
164        match value {
165            0 => Some(Self::ActionStopped),
166            1 => Some(Self::Timeout),
167            _ => None,
168        }
169    }
170
171    /// Its wire value.
172    #[must_use]
173    pub const fn value(self) -> u8 {
174        self as u8
175    }
176}
177
178impl ToTlv for ZoneEventStoppedReasonEnum {
179    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
180        self.value().to_tlv(w, tag)
181    }
182}
183
184impl<'a> FromTlv<'a> for ZoneEventStoppedReasonEnum {
185    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
186        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
187        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
188    }
189}
190
191/// `ZoneEventTriggeredReasonEnum`.
192#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
193#[repr(u8)]
194pub enum ZoneEventTriggeredReasonEnum {
195    /// Zone event triggered because motion is detected
196    Motion = 0,
197}
198
199impl ZoneEventTriggeredReasonEnum {
200    /// Reads a wire value, or `None` for one this revision does not define.
201    #[must_use]
202    pub const fn from_value(value: u8) -> Option<Self> {
203        match value {
204            0 => Some(Self::Motion),
205            _ => None,
206        }
207    }
208
209    /// Its wire value.
210    #[must_use]
211    pub const fn value(self) -> u8 {
212        self as u8
213    }
214}
215
216impl ToTlv for ZoneEventTriggeredReasonEnum {
217    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
218        self.value().to_tlv(w, tag)
219    }
220}
221
222impl<'a> FromTlv<'a> for ZoneEventTriggeredReasonEnum {
223    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
224        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
225        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
226    }
227}
228
229/// `ZoneSourceEnum`.
230#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
231#[repr(u8)]
232pub enum ZoneSourceEnum {
233    /// Indicates a Manufacturer defined Zone.
234    Mfg = 0,
235    /// Indicates a User defined Zone.
236    User = 1,
237}
238
239impl ZoneSourceEnum {
240    /// Reads a wire value, or `None` for one this revision does not define.
241    #[must_use]
242    pub const fn from_value(value: u8) -> Option<Self> {
243        match value {
244            0 => Some(Self::Mfg),
245            1 => Some(Self::User),
246            _ => None,
247        }
248    }
249
250    /// Its wire value.
251    #[must_use]
252    pub const fn value(self) -> u8 {
253        self as u8
254    }
255}
256
257impl ToTlv for ZoneSourceEnum {
258    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
259        self.value().to_tlv(w, tag)
260    }
261}
262
263impl<'a> FromTlv<'a> for ZoneSourceEnum {
264    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
265        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
266        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
267    }
268}
269
270/// `ZoneTypeEnum`.
271#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
272#[repr(u8)]
273pub enum ZoneTypeEnum {
274    /// Indicates a Two Dimensional Cartesian Zone
275    TwoDCARTZone = 0,
276}
277
278impl ZoneTypeEnum {
279    /// Reads a wire value, or `None` for one this revision does not define.
280    #[must_use]
281    pub const fn from_value(value: u8) -> Option<Self> {
282        match value {
283            0 => Some(Self::TwoDCARTZone),
284            _ => None,
285        }
286    }
287
288    /// Its wire value.
289    #[must_use]
290    pub const fn value(self) -> u8 {
291        self as u8
292    }
293}
294
295impl ToTlv for ZoneTypeEnum {
296    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
297        self.value().to_tlv(w, tag)
298    }
299}
300
301impl<'a> FromTlv<'a> for ZoneTypeEnum {
302    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
303        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
304        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
305    }
306}
307
308/// `ZoneUseEnum`.
309#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
310#[repr(u8)]
311pub enum ZoneUseEnum {
312    /// Indicates Zone is intended to detect Motion
313    Motion = 0,
314    /// Indicates Zone is intended to protect privacy
315    Privacy = 1,
316    /// Indicates Zone provides a focus area
317    Focus = 2,
318}
319
320impl ZoneUseEnum {
321    /// Reads a wire value, or `None` for one this revision does not define.
322    #[must_use]
323    pub const fn from_value(value: u8) -> Option<Self> {
324        match value {
325            0 => Some(Self::Motion),
326            1 => Some(Self::Privacy),
327            2 => Some(Self::Focus),
328            _ => None,
329        }
330    }
331
332    /// Its wire value.
333    #[must_use]
334    pub const fn value(self) -> u8 {
335        self as u8
336    }
337}
338
339impl ToTlv for ZoneUseEnum {
340    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
341        self.value().to_tlv(w, tag)
342    }
343}
344
345impl<'a> FromTlv<'a> for ZoneUseEnum {
346    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
347        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
348        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
349    }
350}
351
352/// `TwoDCartesianVertexStruct`.
353#[derive(Debug, Clone, Copy, PartialEq)]
354pub struct TwoDCartesianVertexStruct {
355    /// `X`, field 0.
356    pub x: u16,
357    /// `Y`, field 1.
358    pub y: u16,
359}
360
361impl ToTlv for TwoDCartesianVertexStruct {
362    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
363        w.start_structure(tag)?;
364        self.x.to_tlv(w, Tag::Context(0))?;
365        self.y.to_tlv(w, Tag::Context(1))?;
366        w.end_container()
367    }
368}
369
370impl<'a> FromTlv<'a> for TwoDCartesianVertexStruct {
371    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
372        if element.value.container() != Some(ContainerKind::Structure) {
373            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
374        }
375        let mut x = None;
376        let mut y = None;
377        loop {
378            let Some(field) = reader.next_element()? else {
379                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
380            };
381            if field.value == Value::EndOfContainer {
382                break;
383            }
384            match field.tag.context() {
385                Some(0) => x = Some(<u16>::from_tlv(reader, &field)?),
386                Some(1) => y = Some(<u16>::from_tlv(reader, &field)?),
387                // A field this revision does not define. §7.19.2: a receiver
388                // ignores what it does not know rather than refusing the whole
389                // structure, which is what lets a newer peer talk to an older one.
390                _ => reader.skip_value(&field)?,
391            }
392        }
393        Ok(Self {
394            x: x.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
395            y: y.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
396        })
397    }
398}
399
400/// `TwoDCartesianZoneStruct`.
401#[derive(Debug, Clone, Copy, PartialEq)]
402pub struct TwoDCartesianZoneStruct<'a> {
403    /// `Name`, field 0.
404    pub name: &'a str,
405    /// `Use`, field 1.
406    pub use_: ZoneUseEnum,
407    /// `Vertices`, field 2.
408    pub vertices: TlvList<'a, TwoDCartesianVertexStruct>,
409    /// `Color`, field 3.
410    pub color: Option<&'a str>,
411}
412
413impl<'a> ToTlv for TwoDCartesianZoneStruct<'a> {
414    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
415        w.start_structure(tag)?;
416        self.name.to_tlv(w, Tag::Context(0))?;
417        self.use_.to_tlv(w, Tag::Context(1))?;
418        self.vertices.to_tlv(w, Tag::Context(2))?;
419        if let Some(value) = &self.color {
420            value.to_tlv(w, Tag::Context(3))?;
421        }
422        w.end_container()
423    }
424}
425
426impl<'a> FromTlv<'a> for TwoDCartesianZoneStruct<'a> {
427    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
428        if element.value.container() != Some(ContainerKind::Structure) {
429            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
430        }
431        let mut name = None;
432        let mut use_ = None;
433        let mut vertices = None;
434        let mut color = None;
435        loop {
436            let Some(field) = reader.next_element()? else {
437                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
438            };
439            if field.value == Value::EndOfContainer {
440                break;
441            }
442            match field.tag.context() {
443                Some(0) => name = Some(<&'a str>::from_tlv(reader, &field)?),
444                Some(1) => use_ = Some(<ZoneUseEnum>::from_tlv(reader, &field)?),
445                Some(2) => {
446                    vertices = Some(<TlvList<'a, TwoDCartesianVertexStruct>>::from_tlv(
447                        reader, &field,
448                    )?)
449                }
450                Some(3) => color = Some(<&'a str>::from_tlv(reader, &field)?),
451                // A field this revision does not define. §7.19.2: a receiver
452                // ignores what it does not know rather than refusing the whole
453                // structure, which is what lets a newer peer talk to an older one.
454                _ => reader.skip_value(&field)?,
455            }
456        }
457        Ok(Self {
458            name: name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
459            use_: use_.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
460            vertices: vertices.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
461            color,
462        })
463    }
464}
465
466/// `ZoneInformationStruct`.
467#[derive(Debug, Clone, Copy, PartialEq)]
468pub struct ZoneInformationStruct<'a> {
469    /// `ZoneID`, field 0.
470    pub zone_id: u16,
471    /// `ZoneType`, field 1.
472    pub zone_type: ZoneTypeEnum,
473    /// `ZoneSource`, field 2.
474    pub zone_source: ZoneSourceEnum,
475    /// `TwoDCartesianZone`, field 3.
476    pub two_d_cartesian_zone: Option<TwoDCartesianZoneStruct<'a>>,
477}
478
479impl<'a> ToTlv for ZoneInformationStruct<'a> {
480    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
481        w.start_structure(tag)?;
482        self.zone_id.to_tlv(w, Tag::Context(0))?;
483        self.zone_type.to_tlv(w, Tag::Context(1))?;
484        self.zone_source.to_tlv(w, Tag::Context(2))?;
485        if let Some(value) = &self.two_d_cartesian_zone {
486            value.to_tlv(w, Tag::Context(3))?;
487        }
488        w.end_container()
489    }
490}
491
492impl<'a> FromTlv<'a> for ZoneInformationStruct<'a> {
493    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
494        if element.value.container() != Some(ContainerKind::Structure) {
495            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
496        }
497        let mut zone_id = None;
498        let mut zone_type = None;
499        let mut zone_source = None;
500        let mut two_d_cartesian_zone = None;
501        loop {
502            let Some(field) = reader.next_element()? else {
503                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
504            };
505            if field.value == Value::EndOfContainer {
506                break;
507            }
508            match field.tag.context() {
509                Some(0) => zone_id = Some(<u16>::from_tlv(reader, &field)?),
510                Some(1) => zone_type = Some(<ZoneTypeEnum>::from_tlv(reader, &field)?),
511                Some(2) => zone_source = Some(<ZoneSourceEnum>::from_tlv(reader, &field)?),
512                Some(3) => {
513                    two_d_cartesian_zone =
514                        Some(<TwoDCartesianZoneStruct<'a>>::from_tlv(reader, &field)?)
515                }
516                // A field this revision does not define. §7.19.2: a receiver
517                // ignores what it does not know rather than refusing the whole
518                // structure, which is what lets a newer peer talk to an older one.
519                _ => reader.skip_value(&field)?,
520            }
521        }
522        Ok(Self {
523            zone_id: zone_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
524            zone_type: zone_type.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
525            zone_source: zone_source.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
526            two_d_cartesian_zone,
527        })
528    }
529}
530
531/// `ZoneTriggerControlStruct`.
532#[derive(Debug, Clone, Copy, PartialEq)]
533pub struct ZoneTriggerControlStruct {
534    /// `ZoneID`, field 0.
535    pub zone_id: u16,
536    /// `InitialDuration`, field 1.
537    pub initial_duration: u32,
538    /// `AugmentationDuration`, field 2.
539    pub augmentation_duration: u32,
540    /// `MaxDuration`, field 3.
541    pub max_duration: u32,
542    /// `BlindDuration`, field 4.
543    pub blind_duration: u32,
544    /// `Sensitivity`, field 5.
545    pub sensitivity: Option<u8>,
546}
547
548impl ToTlv for ZoneTriggerControlStruct {
549    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
550        w.start_structure(tag)?;
551        self.zone_id.to_tlv(w, Tag::Context(0))?;
552        self.initial_duration.to_tlv(w, Tag::Context(1))?;
553        self.augmentation_duration.to_tlv(w, Tag::Context(2))?;
554        self.max_duration.to_tlv(w, Tag::Context(3))?;
555        self.blind_duration.to_tlv(w, Tag::Context(4))?;
556        if let Some(value) = &self.sensitivity {
557            value.to_tlv(w, Tag::Context(5))?;
558        }
559        w.end_container()
560    }
561}
562
563impl<'a> FromTlv<'a> for ZoneTriggerControlStruct {
564    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
565        if element.value.container() != Some(ContainerKind::Structure) {
566            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
567        }
568        let mut zone_id = None;
569        let mut initial_duration = None;
570        let mut augmentation_duration = None;
571        let mut max_duration = None;
572        let mut blind_duration = None;
573        let mut sensitivity = None;
574        loop {
575            let Some(field) = reader.next_element()? else {
576                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
577            };
578            if field.value == Value::EndOfContainer {
579                break;
580            }
581            match field.tag.context() {
582                Some(0) => zone_id = Some(<u16>::from_tlv(reader, &field)?),
583                Some(1) => initial_duration = Some(<u32>::from_tlv(reader, &field)?),
584                Some(2) => augmentation_duration = Some(<u32>::from_tlv(reader, &field)?),
585                Some(3) => max_duration = Some(<u32>::from_tlv(reader, &field)?),
586                Some(4) => blind_duration = Some(<u32>::from_tlv(reader, &field)?),
587                Some(5) => sensitivity = Some(<u8>::from_tlv(reader, &field)?),
588                // A field this revision does not define. §7.19.2: a receiver
589                // ignores what it does not know rather than refusing the whole
590                // structure, which is what lets a newer peer talk to an older one.
591                _ => reader.skip_value(&field)?,
592            }
593        }
594        Ok(Self {
595            zone_id: zone_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
596            initial_duration: initial_duration
597                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
598            augmentation_duration: augmentation_duration
599                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
600            max_duration: max_duration.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
601            blind_duration: blind_duration
602                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
603            sensitivity,
604        })
605    }
606}
607
608/// The fields of `CreateTwoDCartesianZone` (command `0x00`).
609#[derive(Debug, Clone, Copy, PartialEq)]
610pub struct CreateTwoDCartesianZoneFields<'a> {
611    /// `Zone`, field 0.
612    pub zone: TwoDCartesianZoneStruct<'a>,
613}
614
615impl<'a> ToTlv for CreateTwoDCartesianZoneFields<'a> {
616    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
617        w.start_structure(tag)?;
618        self.zone.to_tlv(w, Tag::Context(0))?;
619        w.end_container()
620    }
621}
622
623impl<'a> FromTlv<'a> for CreateTwoDCartesianZoneFields<'a> {
624    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
625        if element.value.container() != Some(ContainerKind::Structure) {
626            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
627        }
628        let mut zone = None;
629        loop {
630            let Some(field) = reader.next_element()? else {
631                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
632            };
633            if field.value == Value::EndOfContainer {
634                break;
635            }
636            match field.tag.context() {
637                Some(0) => zone = Some(<TwoDCartesianZoneStruct<'a>>::from_tlv(reader, &field)?),
638                // A field this revision does not define. §7.19.2: a receiver
639                // ignores what it does not know rather than refusing the whole
640                // structure, which is what lets a newer peer talk to an older one.
641                _ => reader.skip_value(&field)?,
642            }
643        }
644        Ok(Self {
645            zone: zone.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
646        })
647    }
648}
649
650/// The fields of `CreateTwoDCartesianZoneResponse` (command `0x01`).
651#[derive(Debug, Clone, Copy, PartialEq)]
652pub struct CreateTwoDCartesianZoneResponseFields {
653    /// `ZoneID`, field 0.
654    pub zone_id: u16,
655}
656
657impl ToTlv for CreateTwoDCartesianZoneResponseFields {
658    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
659        w.start_structure(tag)?;
660        self.zone_id.to_tlv(w, Tag::Context(0))?;
661        w.end_container()
662    }
663}
664
665impl<'a> FromTlv<'a> for CreateTwoDCartesianZoneResponseFields {
666    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
667        if element.value.container() != Some(ContainerKind::Structure) {
668            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
669        }
670        let mut zone_id = None;
671        loop {
672            let Some(field) = reader.next_element()? else {
673                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
674            };
675            if field.value == Value::EndOfContainer {
676                break;
677            }
678            match field.tag.context() {
679                Some(0) => zone_id = Some(<u16>::from_tlv(reader, &field)?),
680                // A field this revision does not define. §7.19.2: a receiver
681                // ignores what it does not know rather than refusing the whole
682                // structure, which is what lets a newer peer talk to an older one.
683                _ => reader.skip_value(&field)?,
684            }
685        }
686        Ok(Self {
687            zone_id: zone_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
688        })
689    }
690}
691
692/// The fields of `UpdateTwoDCartesianZone` (command `0x02`).
693#[derive(Debug, Clone, Copy, PartialEq)]
694pub struct UpdateTwoDCartesianZoneFields<'a> {
695    /// `ZoneID`, field 0.
696    pub zone_id: u16,
697    /// `Zone`, field 1.
698    pub zone: TwoDCartesianZoneStruct<'a>,
699}
700
701impl<'a> ToTlv for UpdateTwoDCartesianZoneFields<'a> {
702    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
703        w.start_structure(tag)?;
704        self.zone_id.to_tlv(w, Tag::Context(0))?;
705        self.zone.to_tlv(w, Tag::Context(1))?;
706        w.end_container()
707    }
708}
709
710impl<'a> FromTlv<'a> for UpdateTwoDCartesianZoneFields<'a> {
711    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
712        if element.value.container() != Some(ContainerKind::Structure) {
713            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
714        }
715        let mut zone_id = None;
716        let mut zone = None;
717        loop {
718            let Some(field) = reader.next_element()? else {
719                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
720            };
721            if field.value == Value::EndOfContainer {
722                break;
723            }
724            match field.tag.context() {
725                Some(0) => zone_id = Some(<u16>::from_tlv(reader, &field)?),
726                Some(1) => zone = Some(<TwoDCartesianZoneStruct<'a>>::from_tlv(reader, &field)?),
727                // A field this revision does not define. §7.19.2: a receiver
728                // ignores what it does not know rather than refusing the whole
729                // structure, which is what lets a newer peer talk to an older one.
730                _ => reader.skip_value(&field)?,
731            }
732        }
733        Ok(Self {
734            zone_id: zone_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
735            zone: zone.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
736        })
737    }
738}
739
740/// The fields of `RemoveZone` (command `0x03`).
741#[derive(Debug, Clone, Copy, PartialEq)]
742pub struct RemoveZoneFields {
743    /// `ZoneID`, field 0.
744    pub zone_id: u16,
745}
746
747impl ToTlv for RemoveZoneFields {
748    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
749        w.start_structure(tag)?;
750        self.zone_id.to_tlv(w, Tag::Context(0))?;
751        w.end_container()
752    }
753}
754
755impl<'a> FromTlv<'a> for RemoveZoneFields {
756    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
757        if element.value.container() != Some(ContainerKind::Structure) {
758            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
759        }
760        let mut zone_id = None;
761        loop {
762            let Some(field) = reader.next_element()? else {
763                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
764            };
765            if field.value == Value::EndOfContainer {
766                break;
767            }
768            match field.tag.context() {
769                Some(0) => zone_id = Some(<u16>::from_tlv(reader, &field)?),
770                // A field this revision does not define. §7.19.2: a receiver
771                // ignores what it does not know rather than refusing the whole
772                // structure, which is what lets a newer peer talk to an older one.
773                _ => reader.skip_value(&field)?,
774            }
775        }
776        Ok(Self {
777            zone_id: zone_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
778        })
779    }
780}
781
782/// The fields of `CreateOrUpdateTrigger` (command `0x04`).
783#[derive(Debug, Clone, Copy, PartialEq)]
784pub struct CreateOrUpdateTriggerFields {
785    /// `Trigger`, field 0.
786    pub trigger: ZoneTriggerControlStruct,
787}
788
789impl ToTlv for CreateOrUpdateTriggerFields {
790    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
791        w.start_structure(tag)?;
792        self.trigger.to_tlv(w, Tag::Context(0))?;
793        w.end_container()
794    }
795}
796
797impl<'a> FromTlv<'a> for CreateOrUpdateTriggerFields {
798    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
799        if element.value.container() != Some(ContainerKind::Structure) {
800            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
801        }
802        let mut trigger = None;
803        loop {
804            let Some(field) = reader.next_element()? else {
805                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
806            };
807            if field.value == Value::EndOfContainer {
808                break;
809            }
810            match field.tag.context() {
811                Some(0) => trigger = Some(<ZoneTriggerControlStruct>::from_tlv(reader, &field)?),
812                // A field this revision does not define. §7.19.2: a receiver
813                // ignores what it does not know rather than refusing the whole
814                // structure, which is what lets a newer peer talk to an older one.
815                _ => reader.skip_value(&field)?,
816            }
817        }
818        Ok(Self {
819            trigger: trigger.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
820        })
821    }
822}
823
824/// The fields of `RemoveTrigger` (command `0x05`).
825#[derive(Debug, Clone, Copy, PartialEq)]
826pub struct RemoveTriggerFields {
827    /// `ZoneID`, field 0.
828    pub zone_id: u16,
829}
830
831impl ToTlv for RemoveTriggerFields {
832    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
833        w.start_structure(tag)?;
834        self.zone_id.to_tlv(w, Tag::Context(0))?;
835        w.end_container()
836    }
837}
838
839impl<'a> FromTlv<'a> for RemoveTriggerFields {
840    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
841        if element.value.container() != Some(ContainerKind::Structure) {
842            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
843        }
844        let mut zone_id = None;
845        loop {
846            let Some(field) = reader.next_element()? else {
847                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
848            };
849            if field.value == Value::EndOfContainer {
850                break;
851            }
852            match field.tag.context() {
853                Some(0) => zone_id = Some(<u16>::from_tlv(reader, &field)?),
854                // A field this revision does not define. §7.19.2: a receiver
855                // ignores what it does not know rather than refusing the whole
856                // structure, which is what lets a newer peer talk to an older one.
857                _ => reader.skip_value(&field)?,
858            }
859        }
860        Ok(Self {
861            zone_id: zone_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
862        })
863    }
864}
865
866/// Every attribute the specification defines, with its conformance.
867pub const ATTRIBUTES: &[Attribute] = &[
868    Attribute {
869        id: 0x0000,
870        name: "MaxUserDefinedZones",
871        kind: "uint8",
872        access: Access::read_only(Privilege::View),
873        qualities: AttributeQualities::FIXED,
874        reporting: Reporting::OnChange,
875        conform: Conform {
876            clauses: &[Clause {
877                verdict: Conformance::Mandatory,
878                when: Condition::Feature(2),
879            }],
880        },
881    },
882    Attribute {
883        id: 0x0001,
884        name: "MaxZones",
885        kind: "uint8",
886        access: Access::read_only(Privilege::View),
887        qualities: AttributeQualities::FIXED,
888        reporting: Reporting::OnChange,
889        conform: Conform::MANDATORY,
890    },
891    Attribute {
892        id: 0x0002,
893        name: "Zones",
894        kind: "list[ZoneInformationStruct]",
895        access: Access::read_only(Privilege::View),
896        qualities: AttributeQualities::NON_VOLATILE,
897        reporting: Reporting::OnChange,
898        conform: Conform::MANDATORY,
899    },
900    Attribute {
901        id: 0x0003,
902        name: "Triggers",
903        kind: "list[ZoneTriggerControlStruct]",
904        access: Access::read_only(Privilege::View),
905        qualities: AttributeQualities::NON_VOLATILE,
906        reporting: Reporting::OnChange,
907        conform: Conform::MANDATORY,
908    },
909    Attribute {
910        id: 0x0004,
911        name: "SensitivityMax",
912        kind: "uint8",
913        access: Access::read_only(Privilege::View),
914        qualities: AttributeQualities::FIXED,
915        reporting: Reporting::OnChange,
916        conform: Conform::MANDATORY,
917    },
918    Attribute {
919        id: 0x0005,
920        name: "Sensitivity",
921        kind: "uint8",
922        access: Access::read_write_with(Privilege::View, Privilege::Operate),
923        qualities: AttributeQualities::NON_VOLATILE,
924        reporting: Reporting::OnChange,
925        conform: Conform {
926            clauses: &[Clause {
927                verdict: Conformance::Mandatory,
928                when: Condition::Not(&Condition::Feature(1)),
929            }],
930        },
931    },
932    Attribute {
933        id: 0x0006,
934        name: "TwoDCartesianMax",
935        kind: "TwoDCartesianVertexStruct",
936        access: Access::read_only(Privilege::View),
937        qualities: AttributeQualities::FIXED,
938        reporting: Reporting::OnChange,
939        conform: Conform {
940            clauses: &[Clause {
941                verdict: Conformance::Mandatory,
942                when: Condition::Feature(0),
943            }],
944        },
945    },
946];
947
948/// Every command, with its conformance.
949pub const COMMANDS: &[Command] = &[
950    Command {
951        id: 0x00,
952        name: "CreateTwoDCartesianZone",
953        to_server: true,
954        response: Some(0x01),
955        access: Access::invoke(Privilege::Manage),
956        conform: Conform {
957            clauses: &[Clause {
958                verdict: Conformance::Mandatory,
959                when: Condition::All(&[Condition::Feature(0), Condition::Feature(2)]),
960            }],
961        },
962    },
963    Command {
964        id: 0x01,
965        name: "CreateTwoDCartesianZoneResponse",
966        to_server: false,
967        response: None,
968        access: Access::invoke(Privilege::Operate),
969        conform: Conform {
970            clauses: &[Clause {
971                verdict: Conformance::Mandatory,
972                when: Condition::All(&[Condition::Feature(0), Condition::Feature(2)]),
973            }],
974        },
975    },
976    Command {
977        id: 0x02,
978        name: "UpdateTwoDCartesianZone",
979        to_server: true,
980        response: None,
981        access: Access::invoke(Privilege::Manage),
982        conform: Conform {
983            clauses: &[Clause {
984                verdict: Conformance::Mandatory,
985                when: Condition::All(&[Condition::Feature(0), Condition::Feature(2)]),
986            }],
987        },
988    },
989    Command {
990        id: 0x03,
991        name: "RemoveZone",
992        to_server: true,
993        response: None,
994        access: Access::invoke(Privilege::Manage),
995        conform: Conform {
996            clauses: &[Clause {
997                verdict: Conformance::Mandatory,
998                when: Condition::Feature(2),
999            }],
1000        },
1001    },
1002    Command {
1003        id: 0x04,
1004        name: "CreateOrUpdateTrigger",
1005        to_server: true,
1006        response: None,
1007        access: Access::invoke(Privilege::Manage),
1008        conform: Conform::MANDATORY,
1009    },
1010    Command {
1011        id: 0x05,
1012        name: "RemoveTrigger",
1013        to_server: true,
1014        response: None,
1015        access: Access::invoke(Privilege::Manage),
1016        conform: Conform::MANDATORY,
1017    },
1018];
1019
1020/// Every event, with its conformance.
1021pub const EVENTS: &[Event] = &[
1022    Event {
1023        id: 0x00,
1024        name: "ZoneTriggered",
1025        priority: EventPriority::Info,
1026        access: Access::read_only(Privilege::View),
1027        conform: Conform::MANDATORY,
1028    },
1029    Event {
1030        id: 0x01,
1031        name: "ZoneStopped",
1032        priority: EventPriority::Info,
1033        access: Access::read_only(Privilege::View),
1034        conform: Conform::MANDATORY,
1035    },
1036];
1037
1038/// The whole cluster, as the specification defines it.
1039pub const CLUSTER: Cluster = Cluster {
1040    id: ID,
1041    name: "Zone Management",
1042    revision: REVISION,
1043    pics: "ZONEMGMT",
1044    derived_from: None,
1045    features: FEATURES,
1046    attributes: ATTRIBUTES,
1047    commands: COMMANDS,
1048    events: EVENTS,
1049};