Skip to main content

matter_kit/clusters/generated/
closure_dimension.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Closure Dimension — cluster 0x0105.
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//! Closure Dimension (cluster `0x0105`, revision 1).
10//!
11//! 14 identifiers, 8 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 = 0x0105;
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 = "CLDIM";
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 Positioning in the range from 0.00% to 100.00%
42    ///
43    /// Code `PS`, bit 0.
44    pub const POSITIONING: u32 = 1 << 0;
45    /// Supports a latch to secure the closure to a position or state
46    ///
47    /// Code `LT`, bit 1.
48    pub const MOTION_LATCHING: u32 = 1 << 1;
49    /// Specifies the relevant unit and range for this dimension (mm, degrees etc.)
50    ///
51    /// Code `UT`, bit 2.
52    pub const UNIT: u32 = 1 << 2;
53    /// Supports limitation of the operating range
54    ///
55    /// Code `LM`, bit 3.
56    pub const LIMITATION: u32 = 1 << 3;
57    /// Supports speed motion throttling.
58    ///
59    /// Code `SP`, bit 4.
60    pub const SPEED: u32 = 1 << 4;
61    /// Drives a translation motion
62    ///
63    /// Code `TR`, bit 5.
64    pub const TRANSLATION: u32 = 1 << 5;
65    /// Drives a rotation motion
66    ///
67    /// Code `RO`, bit 6.
68    pub const ROTATION: u32 = 1 << 6;
69    /// Modulates a particular flow level (light, air, privacy ...)
70    ///
71    /// Code `MD`, bit 7.
72    pub const MODULATION: u32 = 1 << 7;
73}
74
75/// Every feature bit, with its conformance.
76pub const FEATURES: &[Feature] = &[
77    Feature {
78        bit: 0,
79        code: "PS",
80        name: "Positioning",
81        conform: Conform::OPTIONAL,
82    },
83    Feature {
84        bit: 1,
85        code: "LT",
86        name: "MotionLatching",
87        conform: Conform::OPTIONAL,
88    },
89    Feature {
90        bit: 2,
91        code: "UT",
92        name: "Unit",
93        conform: Conform {
94            clauses: &[Clause {
95                verdict: Conformance::Optional,
96                when: Condition::Feature(0),
97            }],
98        },
99    },
100    Feature {
101        bit: 3,
102        code: "LM",
103        name: "Limitation",
104        conform: Conform {
105            clauses: &[Clause {
106                verdict: Conformance::Optional,
107                when: Condition::Feature(0),
108            }],
109        },
110    },
111    Feature {
112        bit: 4,
113        code: "SP",
114        name: "Speed",
115        conform: Conform {
116            clauses: &[Clause {
117                verdict: Conformance::Optional,
118                when: Condition::Feature(0),
119            }],
120        },
121    },
122    Feature {
123        bit: 5,
124        code: "TR",
125        name: "Translation",
126        conform: Conform {
127            clauses: &[Clause {
128                verdict: Conformance::Optional,
129                when: Condition::Feature(0),
130            }],
131        },
132    },
133    Feature {
134        bit: 6,
135        code: "RO",
136        name: "Rotation",
137        conform: Conform {
138            clauses: &[Clause {
139                verdict: Conformance::Optional,
140                when: Condition::Feature(0),
141            }],
142        },
143    },
144    Feature {
145        bit: 7,
146        code: "MD",
147        name: "Modulation",
148        conform: Conform {
149            clauses: &[Clause {
150                verdict: Conformance::Optional,
151                when: Condition::Feature(0),
152            }],
153        },
154    },
155];
156
157/// The attribute ids.
158pub mod attribute {
159    use crate::im::AttributeId;
160
161    /// `CurrentState`.
162    pub const CURRENT_STATE: AttributeId = 0x00;
163    /// `TargetState`.
164    pub const TARGET_STATE: AttributeId = 0x01;
165    /// `Resolution`.
166    pub const RESOLUTION: AttributeId = 0x02;
167    /// `StepValue`.
168    pub const STEP_VALUE: AttributeId = 0x03;
169    /// `Unit`.
170    pub const UNIT: AttributeId = 0x04;
171    /// `UnitRange`.
172    pub const UNIT_RANGE: AttributeId = 0x05;
173    /// `LimitRange`.
174    pub const LIMIT_RANGE: AttributeId = 0x06;
175    /// `TranslationDirection`.
176    pub const TRANSLATION_DIRECTION: AttributeId = 0x07;
177    /// `RotationAxis`.
178    pub const ROTATION_AXIS: AttributeId = 0x08;
179    /// `Overflow`.
180    pub const OVERFLOW: AttributeId = 0x09;
181    /// `ModulationType`.
182    pub const MODULATION_TYPE: AttributeId = 0x0A;
183    /// `LatchControlModes`.
184    pub const LATCH_CONTROL_MODES: AttributeId = 0x0B;
185}
186
187/// The command ids.
188pub mod command {
189    use crate::im::CommandId;
190
191    /// `SetTarget`.
192    pub const SET_TARGET: CommandId = 0x00;
193    /// `Step`.
194    pub const STEP: CommandId = 0x01;
195}
196
197/// `ClosureUnitEnum`.
198#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
199#[repr(u8)]
200pub enum ClosureUnitEnum {
201    /// Millimeter used as unit
202    Millimeter = 0,
203    /// Degree used as unit
204    Degree = 1,
205}
206
207impl ClosureUnitEnum {
208    /// Reads a wire value, or `None` for one this revision does not define.
209    #[must_use]
210    pub const fn from_value(value: u8) -> Option<Self> {
211        match value {
212            0 => Some(Self::Millimeter),
213            1 => Some(Self::Degree),
214            _ => None,
215        }
216    }
217
218    /// Its wire value.
219    #[must_use]
220    pub const fn value(self) -> u8 {
221        self as u8
222    }
223}
224
225impl ToTlv for ClosureUnitEnum {
226    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
227        self.value().to_tlv(w, tag)
228    }
229}
230
231impl<'a> FromTlv<'a> for ClosureUnitEnum {
232    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
233        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
234        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
235    }
236}
237
238/// `ModulationTypeEnum`.
239#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
240#[repr(u8)]
241pub enum ModulationTypeEnum {
242    /// Orientation of the slats
243    SlatsOrientation = 0,
244    /// Aperture of the slats
245    SlatsOpenwork = 1,
246    /// Alignment of blind stripes (Zebra)
247    StripesAlignment = 2,
248    /// Opacity of a surface
249    Opacity = 3,
250    /// Ventilation control
251    Ventilation = 4,
252}
253
254impl ModulationTypeEnum {
255    /// Reads a wire value, or `None` for one this revision does not define.
256    #[must_use]
257    pub const fn from_value(value: u8) -> Option<Self> {
258        match value {
259            0 => Some(Self::SlatsOrientation),
260            1 => Some(Self::SlatsOpenwork),
261            2 => Some(Self::StripesAlignment),
262            3 => Some(Self::Opacity),
263            4 => Some(Self::Ventilation),
264            _ => None,
265        }
266    }
267
268    /// Its wire value.
269    #[must_use]
270    pub const fn value(self) -> u8 {
271        self as u8
272    }
273}
274
275impl ToTlv for ModulationTypeEnum {
276    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
277        self.value().to_tlv(w, tag)
278    }
279}
280
281impl<'a> FromTlv<'a> for ModulationTypeEnum {
282    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
283        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
284        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
285    }
286}
287
288/// `OverflowEnum`.
289#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
290#[repr(u8)]
291pub enum OverflowEnum {
292    /// No overflow
293    NoOverflow = 0,
294    /// Inside overflow
295    Inside = 1,
296    /// Outside overflow
297    Outside = 2,
298    /// Top inside overflow
299    TopInside = 3,
300    /// Top outside overflow
301    TopOutside = 4,
302    /// Bottom inside overflow
303    BottomInside = 5,
304    /// Bottom outside overflow
305    BottomOutside = 6,
306    /// Left inside overflow
307    LeftInside = 7,
308    /// Left outside overflow
309    LeftOutside = 8,
310    /// Right inside overflow
311    RightInside = 9,
312    /// Right outside overflow
313    RightOutside = 10,
314}
315
316impl OverflowEnum {
317    /// Reads a wire value, or `None` for one this revision does not define.
318    #[must_use]
319    pub const fn from_value(value: u8) -> Option<Self> {
320        match value {
321            0 => Some(Self::NoOverflow),
322            1 => Some(Self::Inside),
323            2 => Some(Self::Outside),
324            3 => Some(Self::TopInside),
325            4 => Some(Self::TopOutside),
326            5 => Some(Self::BottomInside),
327            6 => Some(Self::BottomOutside),
328            7 => Some(Self::LeftInside),
329            8 => Some(Self::LeftOutside),
330            9 => Some(Self::RightInside),
331            10 => Some(Self::RightOutside),
332            _ => None,
333        }
334    }
335
336    /// Its wire value.
337    #[must_use]
338    pub const fn value(self) -> u8 {
339        self as u8
340    }
341}
342
343impl ToTlv for OverflowEnum {
344    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
345        self.value().to_tlv(w, tag)
346    }
347}
348
349impl<'a> FromTlv<'a> for OverflowEnum {
350    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
351        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
352        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
353    }
354}
355
356/// `RotationAxisEnum`.
357#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
358#[repr(u8)]
359pub enum RotationAxisEnum {
360    /// The panel rotates around a vertical axis located on the left side of the panel
361    Left = 0,
362    /// The panel rotates around a vertical axis located in the center of the panel
363    CenteredVertical = 1,
364    /// The panels rotates around vertical axes located on the left and right sides of the panel
365    LeftAndRight = 2,
366    /// The panel rotates around a vertical axis located on the right side of the panel
367    Right = 3,
368    /// The panel rotates around a horizontal axis located on the top of the panel
369    Top = 4,
370    /// The panel rotates around a horizontal axis located in the center of the panel
371    CenteredHorizontal = 5,
372    /// The panels rotates around horizontal axes located on the top and bottom of the panel
373    TopAndBottom = 6,
374    /// The panel rotates around a horizontal axis located on the bottom of the panel
375    Bottom = 7,
376    /// The barrier tilts around an axis located at the left end of the barrier
377    LeftBarrier = 8,
378    /// The dual barriers tilt around axes located at each side of the composite barrier
379    LeftAndRightBarriers = 9,
380    /// The barrier tilts around an axis located at the right end of the barrier
381    RightBarrier = 10,
382}
383
384impl RotationAxisEnum {
385    /// Reads a wire value, or `None` for one this revision does not define.
386    #[must_use]
387    pub const fn from_value(value: u8) -> Option<Self> {
388        match value {
389            0 => Some(Self::Left),
390            1 => Some(Self::CenteredVertical),
391            2 => Some(Self::LeftAndRight),
392            3 => Some(Self::Right),
393            4 => Some(Self::Top),
394            5 => Some(Self::CenteredHorizontal),
395            6 => Some(Self::TopAndBottom),
396            7 => Some(Self::Bottom),
397            8 => Some(Self::LeftBarrier),
398            9 => Some(Self::LeftAndRightBarriers),
399            10 => Some(Self::RightBarrier),
400            _ => None,
401        }
402    }
403
404    /// Its wire value.
405    #[must_use]
406    pub const fn value(self) -> u8 {
407        self as u8
408    }
409}
410
411impl ToTlv for RotationAxisEnum {
412    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
413        self.value().to_tlv(w, tag)
414    }
415}
416
417impl<'a> FromTlv<'a> for RotationAxisEnum {
418    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
419        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
420        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
421    }
422}
423
424/// `StepDirectionEnum`.
425#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
426#[repr(u8)]
427pub enum StepDirectionEnum {
428    /// Decrease towards 0.00%
429    Decrease = 0,
430    /// Increase towards 100.00%
431    Increase = 1,
432}
433
434impl StepDirectionEnum {
435    /// Reads a wire value, or `None` for one this revision does not define.
436    #[must_use]
437    pub const fn from_value(value: u8) -> Option<Self> {
438        match value {
439            0 => Some(Self::Decrease),
440            1 => Some(Self::Increase),
441            _ => None,
442        }
443    }
444
445    /// Its wire value.
446    #[must_use]
447    pub const fn value(self) -> u8 {
448        self as u8
449    }
450}
451
452impl ToTlv for StepDirectionEnum {
453    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
454        self.value().to_tlv(w, tag)
455    }
456}
457
458impl<'a> FromTlv<'a> for StepDirectionEnum {
459    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
460        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
461        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
462    }
463}
464
465/// `TranslationDirectionEnum`.
466#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
467#[repr(u8)]
468pub enum TranslationDirectionEnum {
469    /// Downward translation
470    Downward = 0,
471    /// Upward translation
472    Upward = 1,
473    /// Vertical mask translation
474    VerticalMask = 2,
475    /// Vertical symmetry translation
476    VerticalSymmetry = 3,
477    /// Leftward translation
478    Leftward = 4,
479    /// Rightward translation
480    Rightward = 5,
481    /// Horizontal mask translation
482    HorizontalMask = 6,
483    /// Horizontal symmetry translation
484    HorizontalSymmetry = 7,
485    /// Forward translation
486    Forward = 8,
487    /// Backward translation
488    Backward = 9,
489    /// Depth mask translation
490    DepthMask = 10,
491    /// Depth symmetry translation
492    DepthSymmetry = 11,
493}
494
495impl TranslationDirectionEnum {
496    /// Reads a wire value, or `None` for one this revision does not define.
497    #[must_use]
498    pub const fn from_value(value: u8) -> Option<Self> {
499        match value {
500            0 => Some(Self::Downward),
501            1 => Some(Self::Upward),
502            2 => Some(Self::VerticalMask),
503            3 => Some(Self::VerticalSymmetry),
504            4 => Some(Self::Leftward),
505            5 => Some(Self::Rightward),
506            6 => Some(Self::HorizontalMask),
507            7 => Some(Self::HorizontalSymmetry),
508            8 => Some(Self::Forward),
509            9 => Some(Self::Backward),
510            10 => Some(Self::DepthMask),
511            11 => Some(Self::DepthSymmetry),
512            _ => None,
513        }
514    }
515
516    /// Its wire value.
517    #[must_use]
518    pub const fn value(self) -> u8 {
519        self as u8
520    }
521}
522
523impl ToTlv for TranslationDirectionEnum {
524    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
525        self.value().to_tlv(w, tag)
526    }
527}
528
529impl<'a> FromTlv<'a> for TranslationDirectionEnum {
530    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
531        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
532        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
533    }
534}
535
536bitflags::bitflags! {
537    /// `LatchControlModesBitmap`.
538    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
539    pub struct LatchControlModesBitmap: u8 {
540        /// Remote latching capability
541        const REMOTE_LATCHING = 1 << 0;
542        /// Remote unlatching capability
543        const REMOTE_UNLATCHING = 1 << 1;
544    }
545}
546
547impl ToTlv for LatchControlModesBitmap {
548    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
549        self.bits().to_tlv(w, tag)
550    }
551}
552
553impl<'a> FromTlv<'a> for LatchControlModesBitmap {
554    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
555        let bits = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
556        Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
557    }
558}
559
560/// `DimensionStateStruct`.
561#[derive(Debug, Clone, Copy, PartialEq)]
562pub struct DimensionStateStruct {
563    /// `Position`, field 0.
564    pub position: Option<Nullable<u16>>,
565    /// `Latch`, field 1.
566    pub latch: Option<Nullable<bool>>,
567    /// `Speed`, field 2.
568    pub speed: Option<crate::clusters::generated::globals::ThreeLevelAutoEnum>,
569}
570
571impl ToTlv for DimensionStateStruct {
572    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
573        w.start_structure(tag)?;
574        if let Some(value) = &self.position {
575            value.to_tlv(w, Tag::Context(0))?;
576        }
577        if let Some(value) = &self.latch {
578            value.to_tlv(w, Tag::Context(1))?;
579        }
580        if let Some(value) = &self.speed {
581            value.to_tlv(w, Tag::Context(2))?;
582        }
583        w.end_container()
584    }
585}
586
587impl<'a> FromTlv<'a> for DimensionStateStruct {
588    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
589        if element.value.container() != Some(ContainerKind::Structure) {
590            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
591        }
592        let mut position = None;
593        let mut latch = None;
594        let mut speed = None;
595        loop {
596            let Some(field) = reader.next_element()? else {
597                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
598            };
599            if field.value == Value::EndOfContainer {
600                break;
601            }
602            match field.tag.context() {
603                Some(0) => position = Some(<Nullable<u16>>::from_tlv(reader, &field)?),
604                Some(1) => latch = Some(<Nullable<bool>>::from_tlv(reader, &field)?),
605                Some(2) => {
606                    speed = Some(
607                        <crate::clusters::generated::globals::ThreeLevelAutoEnum>::from_tlv(
608                            reader, &field,
609                        )?,
610                    )
611                }
612                // A field this revision does not define. §7.19.2: a receiver
613                // ignores what it does not know rather than refusing the whole
614                // structure, which is what lets a newer peer talk to an older one.
615                _ => reader.skip_value(&field)?,
616            }
617        }
618        Ok(Self {
619            position,
620            latch,
621            speed,
622        })
623    }
624}
625
626/// `RangePercent100thsStruct`.
627#[derive(Debug, Clone, Copy, PartialEq)]
628pub struct RangePercent100ThsStruct {
629    /// `Min`, field 0.
630    pub min: u16,
631    /// `Max`, field 1.
632    pub max: u16,
633}
634
635impl ToTlv for RangePercent100ThsStruct {
636    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
637        w.start_structure(tag)?;
638        self.min.to_tlv(w, Tag::Context(0))?;
639        self.max.to_tlv(w, Tag::Context(1))?;
640        w.end_container()
641    }
642}
643
644impl<'a> FromTlv<'a> for RangePercent100ThsStruct {
645    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
646        if element.value.container() != Some(ContainerKind::Structure) {
647            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
648        }
649        let mut min = None;
650        let mut max = None;
651        loop {
652            let Some(field) = reader.next_element()? else {
653                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
654            };
655            if field.value == Value::EndOfContainer {
656                break;
657            }
658            match field.tag.context() {
659                Some(0) => min = Some(<u16>::from_tlv(reader, &field)?),
660                Some(1) => max = Some(<u16>::from_tlv(reader, &field)?),
661                // A field this revision does not define. §7.19.2: a receiver
662                // ignores what it does not know rather than refusing the whole
663                // structure, which is what lets a newer peer talk to an older one.
664                _ => reader.skip_value(&field)?,
665            }
666        }
667        Ok(Self {
668            min: min.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
669            max: max.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
670        })
671    }
672}
673
674/// `UnitRangeStruct`.
675#[derive(Debug, Clone, Copy, PartialEq)]
676pub struct UnitRangeStruct {
677    /// `Min`, field 0.
678    pub min: i16,
679    /// `Max`, field 1.
680    pub max: i16,
681}
682
683impl ToTlv for UnitRangeStruct {
684    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
685        w.start_structure(tag)?;
686        self.min.to_tlv(w, Tag::Context(0))?;
687        self.max.to_tlv(w, Tag::Context(1))?;
688        w.end_container()
689    }
690}
691
692impl<'a> FromTlv<'a> for UnitRangeStruct {
693    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
694        if element.value.container() != Some(ContainerKind::Structure) {
695            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
696        }
697        let mut min = None;
698        let mut max = None;
699        loop {
700            let Some(field) = reader.next_element()? else {
701                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
702            };
703            if field.value == Value::EndOfContainer {
704                break;
705            }
706            match field.tag.context() {
707                Some(0) => min = Some(<i16>::from_tlv(reader, &field)?),
708                Some(1) => max = Some(<i16>::from_tlv(reader, &field)?),
709                // A field this revision does not define. §7.19.2: a receiver
710                // ignores what it does not know rather than refusing the whole
711                // structure, which is what lets a newer peer talk to an older one.
712                _ => reader.skip_value(&field)?,
713            }
714        }
715        Ok(Self {
716            min: min.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
717            max: max.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
718        })
719    }
720}
721
722/// The fields of `SetTarget` (command `0x00`).
723#[derive(Debug, Clone, Copy, PartialEq)]
724pub struct SetTargetFields {
725    /// `Position`, field 0.
726    pub position: Option<u16>,
727    /// `Latch`, field 1.
728    pub latch: Option<bool>,
729    /// `Speed`, field 2.
730    pub speed: Option<crate::clusters::generated::globals::ThreeLevelAutoEnum>,
731}
732
733impl ToTlv for SetTargetFields {
734    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
735        w.start_structure(tag)?;
736        if let Some(value) = &self.position {
737            value.to_tlv(w, Tag::Context(0))?;
738        }
739        if let Some(value) = &self.latch {
740            value.to_tlv(w, Tag::Context(1))?;
741        }
742        if let Some(value) = &self.speed {
743            value.to_tlv(w, Tag::Context(2))?;
744        }
745        w.end_container()
746    }
747}
748
749impl<'a> FromTlv<'a> for SetTargetFields {
750    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
751        if element.value.container() != Some(ContainerKind::Structure) {
752            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
753        }
754        let mut position = None;
755        let mut latch = None;
756        let mut speed = None;
757        loop {
758            let Some(field) = reader.next_element()? else {
759                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
760            };
761            if field.value == Value::EndOfContainer {
762                break;
763            }
764            match field.tag.context() {
765                Some(0) => position = Some(<u16>::from_tlv(reader, &field)?),
766                Some(1) => latch = Some(<bool>::from_tlv(reader, &field)?),
767                Some(2) => {
768                    speed = Some(
769                        <crate::clusters::generated::globals::ThreeLevelAutoEnum>::from_tlv(
770                            reader, &field,
771                        )?,
772                    )
773                }
774                // A field this revision does not define. §7.19.2: a receiver
775                // ignores what it does not know rather than refusing the whole
776                // structure, which is what lets a newer peer talk to an older one.
777                _ => reader.skip_value(&field)?,
778            }
779        }
780        Ok(Self {
781            position,
782            latch,
783            speed,
784        })
785    }
786}
787
788/// The fields of `Step` (command `0x01`).
789#[derive(Debug, Clone, Copy, PartialEq)]
790pub struct StepFields {
791    /// `Direction`, field 0.
792    pub direction: StepDirectionEnum,
793    /// `NumberOfSteps`, field 1.
794    pub number_of_steps: u16,
795    /// `Speed`, field 2.
796    pub speed: Option<crate::clusters::generated::globals::ThreeLevelAutoEnum>,
797}
798
799impl ToTlv for StepFields {
800    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
801        w.start_structure(tag)?;
802        self.direction.to_tlv(w, Tag::Context(0))?;
803        self.number_of_steps.to_tlv(w, Tag::Context(1))?;
804        if let Some(value) = &self.speed {
805            value.to_tlv(w, Tag::Context(2))?;
806        }
807        w.end_container()
808    }
809}
810
811impl<'a> FromTlv<'a> for StepFields {
812    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
813        if element.value.container() != Some(ContainerKind::Structure) {
814            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
815        }
816        let mut direction = None;
817        let mut number_of_steps = None;
818        let mut speed = None;
819        loop {
820            let Some(field) = reader.next_element()? else {
821                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
822            };
823            if field.value == Value::EndOfContainer {
824                break;
825            }
826            match field.tag.context() {
827                Some(0) => direction = Some(<StepDirectionEnum>::from_tlv(reader, &field)?),
828                Some(1) => number_of_steps = Some(<u16>::from_tlv(reader, &field)?),
829                Some(2) => {
830                    speed = Some(
831                        <crate::clusters::generated::globals::ThreeLevelAutoEnum>::from_tlv(
832                            reader, &field,
833                        )?,
834                    )
835                }
836                // A field this revision does not define. §7.19.2: a receiver
837                // ignores what it does not know rather than refusing the whole
838                // structure, which is what lets a newer peer talk to an older one.
839                _ => reader.skip_value(&field)?,
840            }
841        }
842        Ok(Self {
843            direction: direction.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
844            number_of_steps: number_of_steps
845                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
846            speed,
847        })
848    }
849}
850
851/// Every attribute the specification defines, with its conformance.
852pub const ATTRIBUTES: &[Attribute] = &[
853    Attribute {
854        id: 0x0000,
855        name: "CurrentState",
856        kind: "DimensionStateStruct",
857        access: Access::read_only(Privilege::View),
858        qualities: AttributeQualities::NULLABLE,
859        reporting: Reporting::Quieter,
860        conform: Conform::MANDATORY,
861    },
862    Attribute {
863        id: 0x0001,
864        name: "TargetState",
865        kind: "DimensionStateStruct",
866        access: Access::read_only(Privilege::View),
867        qualities: AttributeQualities::NULLABLE,
868        reporting: Reporting::OnChange,
869        conform: Conform::MANDATORY,
870    },
871    Attribute {
872        id: 0x0002,
873        name: "Resolution",
874        kind: "percent100ths",
875        access: Access::read_only(Privilege::View),
876        qualities: AttributeQualities::FIXED,
877        reporting: Reporting::OnChange,
878        conform: Conform {
879            clauses: &[Clause {
880                verdict: Conformance::Mandatory,
881                when: Condition::Feature(0),
882            }],
883        },
884    },
885    Attribute {
886        id: 0x0003,
887        name: "StepValue",
888        kind: "percent100ths",
889        access: Access::read_only(Privilege::View),
890        qualities: AttributeQualities::FIXED,
891        reporting: Reporting::OnChange,
892        conform: Conform {
893            clauses: &[Clause {
894                verdict: Conformance::Mandatory,
895                when: Condition::Feature(0),
896            }],
897        },
898    },
899    Attribute {
900        id: 0x0004,
901        name: "Unit",
902        kind: "ClosureUnitEnum",
903        access: Access::read_only(Privilege::View),
904        qualities: AttributeQualities::FIXED,
905        reporting: Reporting::OnChange,
906        conform: Conform {
907            clauses: &[Clause {
908                verdict: Conformance::Mandatory,
909                when: Condition::Feature(2),
910            }],
911        },
912    },
913    Attribute {
914        id: 0x0005,
915        name: "UnitRange",
916        kind: "UnitRangeStruct",
917        access: Access::read_only(Privilege::View),
918        qualities: AttributeQualities::NULLABLE,
919        reporting: Reporting::OnChange,
920        conform: Conform {
921            clauses: &[Clause {
922                verdict: Conformance::Mandatory,
923                when: Condition::Feature(2),
924            }],
925        },
926    },
927    Attribute {
928        id: 0x0006,
929        name: "LimitRange",
930        kind: "RangePercent100thsStruct",
931        access: Access::read_only(Privilege::View),
932        qualities: AttributeQualities::empty(),
933        reporting: Reporting::OnChange,
934        conform: Conform {
935            clauses: &[Clause {
936                verdict: Conformance::Mandatory,
937                when: Condition::Feature(3),
938            }],
939        },
940    },
941    Attribute {
942        id: 0x0007,
943        name: "TranslationDirection",
944        kind: "TranslationDirectionEnum",
945        access: Access::read_only(Privilege::View),
946        qualities: AttributeQualities::FIXED,
947        reporting: Reporting::OnChange,
948        conform: Conform {
949            clauses: &[Clause {
950                verdict: Conformance::Mandatory,
951                when: Condition::Feature(5),
952            }],
953        },
954    },
955    Attribute {
956        id: 0x0008,
957        name: "RotationAxis",
958        kind: "RotationAxisEnum",
959        access: Access::read_only(Privilege::View),
960        qualities: AttributeQualities::FIXED,
961        reporting: Reporting::OnChange,
962        conform: Conform {
963            clauses: &[Clause {
964                verdict: Conformance::Mandatory,
965                when: Condition::Feature(6),
966            }],
967        },
968    },
969    Attribute {
970        id: 0x0009,
971        name: "Overflow",
972        kind: "OverflowEnum",
973        access: Access::read_only(Privilege::View),
974        qualities: AttributeQualities::FIXED,
975        reporting: Reporting::OnChange,
976        conform: Conform {
977            clauses: &[Clause {
978                verdict: Conformance::Mandatory,
979                when: Condition::Feature(6),
980            }],
981        },
982    },
983    Attribute {
984        id: 0x000A,
985        name: "ModulationType",
986        kind: "ModulationTypeEnum",
987        access: Access::read_only(Privilege::View),
988        qualities: AttributeQualities::FIXED,
989        reporting: Reporting::OnChange,
990        conform: Conform {
991            clauses: &[Clause {
992                verdict: Conformance::Mandatory,
993                when: Condition::Feature(7),
994            }],
995        },
996    },
997    Attribute {
998        id: 0x000B,
999        name: "LatchControlModes",
1000        kind: "LatchControlModesBitmap",
1001        access: Access::read_only(Privilege::View),
1002        qualities: AttributeQualities::FIXED,
1003        reporting: Reporting::OnChange,
1004        conform: Conform {
1005            clauses: &[Clause {
1006                verdict: Conformance::Mandatory,
1007                when: Condition::Feature(1),
1008            }],
1009        },
1010    },
1011];
1012
1013/// Every command, with its conformance.
1014pub const COMMANDS: &[Command] = &[
1015    Command {
1016        id: 0x00,
1017        name: "SetTarget",
1018        to_server: true,
1019        response: None,
1020        access: Access::invoke(Privilege::Operate).with_qualities(AccessQualities::TIMED),
1021        conform: Conform::MANDATORY,
1022    },
1023    Command {
1024        id: 0x01,
1025        name: "Step",
1026        to_server: true,
1027        response: None,
1028        access: Access::invoke(Privilege::Operate).with_qualities(AccessQualities::TIMED),
1029        conform: Conform {
1030            clauses: &[Clause {
1031                verdict: Conformance::Mandatory,
1032                when: Condition::Feature(0),
1033            }],
1034        },
1035    },
1036];
1037
1038/// Every event, with its conformance.
1039pub const EVENTS: &[Event] = &[];
1040
1041/// The whole cluster, as the specification defines it.
1042pub const CLUSTER: Cluster = Cluster {
1043    id: ID,
1044    name: "Closure Dimension",
1045    revision: REVISION,
1046    pics: "CLDIM",
1047    derived_from: None,
1048    features: FEATURES,
1049    attributes: ATTRIBUTES,
1050    commands: COMMANDS,
1051    events: EVENTS,
1052};