matter-kit 0.3.0

Matter (CSA smart-home standard) protocol implementation in Rust: no_std, no-alloc, executor-agnostic
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
//
// Window Covering — cluster 0x0102.
//
// Regenerate with `cargo xtask clusters --dm <checkout>/data_model/1.6`; `cargo xtask check`
// is the CI gate that keeps this file honest. The XML itself is not vendored here — it
// carries the CSA's own copyright notice and is not redistributable.

//! Window Covering (cluster `0x0102`, revision 8).
//!
//! 19 identifiers, 4 feature bits, and the specification's own conformance for
//! every element. `CLUSTER` is the whole table.

#![allow(unused_imports)]

use crate::dm::conformance::{Clause, Condition, Conform, Conformance};
use crate::dm::meta::{EventPriority, Reporting};
use crate::dm::spec::{Attribute, Cluster, Command, Event, Feature};
use crate::dm::{Access, AccessQualities, AttributeQualities, Privilege};
use crate::error::Result;
use crate::im::{AttributeId, ClusterId, CommandId, EventId};
use crate::tlv::{
    ContainerKind, Element, FromTlv, Nullable, Tag, TlvList, TlvReader, TlvWriter, ToTlv, Value,
};

/// The cluster id.
pub const ID: ClusterId = 0x0102;

/// The highest revision the specification's history defines — what `ClusterRevision`
/// must report (Core §7.13.1).
pub const REVISION: u16 = 8;

/// The PICS code, which a certification declaration names the cluster by.
pub const PICS: &str = "WNCV";

/// The `FeatureMap` bits (Core §7.13.2).
///
/// A feature has conformance of its own: a device may not claim one the
/// specification forbids it alongside another.
pub mod feature {
    /// Lift control and behavior for lifting/sliding window coverings
    ///
    /// Code `LF`, bit 0.
    pub const LIFT: u32 = 1 << 0;
    /// Tilt control and behavior for tilting window coverings
    ///
    /// Code `TL`, bit 1.
    pub const TILT: u32 = 1 << 1;
    /// Position aware lift control is supported.
    ///
    /// Code `PA_LF`, bit 2.
    pub const POSITION_AWARE_LIFT: u32 = 1 << 2;
    /// Position aware tilt control is supported.
    ///
    /// Code `PA_TL`, bit 4.
    pub const POSITION_AWARE_TILT: u32 = 1 << 4;
}

/// Every feature bit, with its conformance.
pub const FEATURES: &[Feature] = &[
    Feature {
        bit: 0,
        code: "LF",
        name: "Lift",
        conform: Conform::OPTIONAL,
    },
    Feature {
        bit: 1,
        code: "TL",
        name: "Tilt",
        conform: Conform::OPTIONAL,
    },
    Feature {
        bit: 2,
        code: "PA_LF",
        name: "PositionAwareLift",
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Optional,
                when: Condition::Feature(0),
            }],
        },
    },
    Feature {
        bit: 4,
        code: "PA_TL",
        name: "PositionAwareTilt",
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Optional,
                when: Condition::Feature(1),
            }],
        },
    },
];

/// The attribute ids.
pub mod attribute {
    use crate::im::AttributeId;

    /// `Type`.
    pub const TYPE: AttributeId = 0x00;
    /// `NumberOfActuationsLift`.
    pub const NUMBER_OF_ACTUATIONS_LIFT: AttributeId = 0x05;
    /// `NumberOfActuationsTilt`.
    pub const NUMBER_OF_ACTUATIONS_TILT: AttributeId = 0x06;
    /// `ConfigStatus`.
    pub const CONFIG_STATUS: AttributeId = 0x07;
    /// `CurrentPositionLiftPercentage`.
    pub const CURRENT_POSITION_LIFT_PERCENTAGE: AttributeId = 0x08;
    /// `CurrentPositionTiltPercentage`.
    pub const CURRENT_POSITION_TILT_PERCENTAGE: AttributeId = 0x09;
    /// `OperationalStatus`.
    pub const OPERATIONAL_STATUS: AttributeId = 0x0A;
    /// `TargetPositionLiftPercent100ths`.
    pub const TARGET_POSITION_LIFT_PERCENT100_THS: AttributeId = 0x0B;
    /// `TargetPositionTiltPercent100ths`.
    pub const TARGET_POSITION_TILT_PERCENT100_THS: AttributeId = 0x0C;
    /// `EndProductType`.
    pub const END_PRODUCT_TYPE: AttributeId = 0x0D;
    /// `CurrentPositionLiftPercent100ths`.
    pub const CURRENT_POSITION_LIFT_PERCENT100_THS: AttributeId = 0x0E;
    /// `CurrentPositionTiltPercent100ths`.
    pub const CURRENT_POSITION_TILT_PERCENT100_THS: AttributeId = 0x0F;
    /// `Mode`.
    pub const MODE: AttributeId = 0x17;
    /// `SafetyStatus`.
    pub const SAFETY_STATUS: AttributeId = 0x1A;
}

/// The command ids.
pub mod command {
    use crate::im::CommandId;

    /// `UpOrOpen`.
    pub const UP_OR_OPEN: CommandId = 0x00;
    /// `DownOrClose`.
    pub const DOWN_OR_CLOSE: CommandId = 0x01;
    /// `StopMotion`.
    pub const STOP_MOTION: CommandId = 0x02;
    /// `GoToLiftPercentage`.
    pub const GO_TO_LIFT_PERCENTAGE: CommandId = 0x05;
    /// `GoToTiltPercentage`.
    pub const GO_TO_TILT_PERCENTAGE: CommandId = 0x08;
}

/// `EndProductTypeEnum`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum EndProductTypeEnum {
    /// Simple Roller Shade
    RollerShade = 0,
    /// Roman Shade
    RomanShade = 1,
    /// Balloon Shade
    BalloonShade = 2,
    /// Woven Wood
    WovenWood = 3,
    /// Pleated Shade
    PleatedShade = 4,
    /// Cellular Shade
    CellularShade = 5,
    /// Layered Shade
    LayeredShade = 6,
    /// Layered Shade 2D
    LayeredShade2D = 7,
    /// Sheer Shade
    SheerShade = 8,
    /// Tilt Only Interior Blind
    TiltOnlyInteriorBlind = 9,
    /// Interior Blind
    InteriorBlind = 10,
    /// Vertical Blind, Strip Curtain
    VerticalBlindStripCurtain = 11,
    /// Interior Venetian Blind
    InteriorVenetianBlind = 12,
    /// Exterior Venetian Blind
    ExteriorVenetianBlind = 13,
    /// Lateral Left Curtain
    LateralLeftCurtain = 14,
    /// Lateral Right Curtain
    LateralRightCurtain = 15,
    /// Central Curtain
    CentralCurtain = 16,
    /// Roller Shutter
    RollerShutter = 17,
    /// Exterior Vertical Screen
    ExteriorVerticalScreen = 18,
    /// Awning Terrace (Patio)
    AwningTerracePatio = 19,
    /// Awning Vertical Screen
    AwningVerticalScreen = 20,
    /// Tilt Only Pergola
    TiltOnlyPergola = 21,
    /// Swinging Shutter
    SwingingShutter = 22,
    /// Sliding Shutter
    SlidingShutter = 23,
    /// Unknown
    Unknown = 255,
}

impl EndProductTypeEnum {
    /// Reads a wire value, or `None` for one this revision does not define.
    #[must_use]
    pub const fn from_value(value: u8) -> Option<Self> {
        match value {
            0 => Some(Self::RollerShade),
            1 => Some(Self::RomanShade),
            2 => Some(Self::BalloonShade),
            3 => Some(Self::WovenWood),
            4 => Some(Self::PleatedShade),
            5 => Some(Self::CellularShade),
            6 => Some(Self::LayeredShade),
            7 => Some(Self::LayeredShade2D),
            8 => Some(Self::SheerShade),
            9 => Some(Self::TiltOnlyInteriorBlind),
            10 => Some(Self::InteriorBlind),
            11 => Some(Self::VerticalBlindStripCurtain),
            12 => Some(Self::InteriorVenetianBlind),
            13 => Some(Self::ExteriorVenetianBlind),
            14 => Some(Self::LateralLeftCurtain),
            15 => Some(Self::LateralRightCurtain),
            16 => Some(Self::CentralCurtain),
            17 => Some(Self::RollerShutter),
            18 => Some(Self::ExteriorVerticalScreen),
            19 => Some(Self::AwningTerracePatio),
            20 => Some(Self::AwningVerticalScreen),
            21 => Some(Self::TiltOnlyPergola),
            22 => Some(Self::SwingingShutter),
            23 => Some(Self::SlidingShutter),
            255 => Some(Self::Unknown),
            _ => None,
        }
    }

    /// Its wire value.
    #[must_use]
    pub const fn value(self) -> u8 {
        self as u8
    }
}

impl ToTlv for EndProductTypeEnum {
    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
        self.value().to_tlv(w, tag)
    }
}

impl<'a> FromTlv<'a> for EndProductTypeEnum {
    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
    }
}

/// `TypeEnum`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum TypeEnum {
    /// RollerShade
    RollerShade = 0,
    /// RollerShade - 2 Motor
    RollerShade2Motor = 1,
    /// RollerShade - Exterior
    RollerShadeExterior = 2,
    /// RollerShade - Exterior - 2 Motor
    RollerShadeExterior2Motor = 3,
    /// Drapery (curtain)
    Drapery = 4,
    /// Awning
    Awning = 5,
    /// Shutter
    Shutter = 6,
    /// Tilt Blind - Tilt Only
    TiltBlindTiltOnly = 7,
    /// Tilt Blind - Lift & Tilt
    TiltBlindLiftAndTilt = 8,
    /// Projector Screen
    ProjectorScreen = 9,
    /// Unknown
    Unknown = 255,
}

impl TypeEnum {
    /// Reads a wire value, or `None` for one this revision does not define.
    #[must_use]
    pub const fn from_value(value: u8) -> Option<Self> {
        match value {
            0 => Some(Self::RollerShade),
            1 => Some(Self::RollerShade2Motor),
            2 => Some(Self::RollerShadeExterior),
            3 => Some(Self::RollerShadeExterior2Motor),
            4 => Some(Self::Drapery),
            5 => Some(Self::Awning),
            6 => Some(Self::Shutter),
            7 => Some(Self::TiltBlindTiltOnly),
            8 => Some(Self::TiltBlindLiftAndTilt),
            9 => Some(Self::ProjectorScreen),
            255 => Some(Self::Unknown),
            _ => None,
        }
    }

    /// Its wire value.
    #[must_use]
    pub const fn value(self) -> u8 {
        self as u8
    }
}

impl ToTlv for TypeEnum {
    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
        self.value().to_tlv(w, tag)
    }
}

impl<'a> FromTlv<'a> for TypeEnum {
    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
    }
}

bitflags::bitflags! {
    /// `ConfigStatusBitmap`.
    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
    pub struct ConfigStatusBitmap: u8 {
        /// Device is operational.
        const OPERATIONAL = 1 << 0;
        /// `OnlineReserved`, bit 1.
        const ONLINE_RESERVED = 1 << 1;
        /// The lift movement is reversed.
        const LIFT_MOVEMENT_REVERSED = 1 << 2;
        /// Supports the PositionAwareLift feature (PA_LF).
        const LIFT_POSITION_AWARE = 1 << 3;
        /// Supports the PositionAwareTilt feature (PA_TL).
        const TILT_POSITION_AWARE = 1 << 4;
        /// Uses an encoder for lift.
        const LIFT_ENCODER_CONTROLLED = 1 << 5;
        /// Uses an encoder for tilt.
        const TILT_ENCODER_CONTROLLED = 1 << 6;
    }
}

impl ToTlv for ConfigStatusBitmap {
    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
        self.bits().to_tlv(w, tag)
    }
}

impl<'a> FromTlv<'a> for ConfigStatusBitmap {
    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
        let bits = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
        Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
    }
}

bitflags::bitflags! {
    /// `ModeBitmap`.
    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
    pub struct ModeBitmap: u8 {
        /// Reverse the lift direction.
        const MOTOR_DIRECTION_REVERSED = 1 << 0;
        /// Perform a calibration.
        const CALIBRATION_MODE = 1 << 1;
        /// Freeze all motions for maintenance.
        const MAINTENANCE_MODE = 1 << 2;
        /// Control the LEDs feedback.
        const LED_FEEDBACK = 1 << 3;
    }
}

impl ToTlv for ModeBitmap {
    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
        self.bits().to_tlv(w, tag)
    }
}

impl<'a> FromTlv<'a> for ModeBitmap {
    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
        let bits = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
        Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
    }
}

bitflags::bitflags! {
    /// `OperationalStatusBitmap`.
    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
    pub struct OperationalStatusBitmap: u8 {
    }
}

impl ToTlv for OperationalStatusBitmap {
    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
        self.bits().to_tlv(w, tag)
    }
}

impl<'a> FromTlv<'a> for OperationalStatusBitmap {
    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
        let bits = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
        Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
    }
}

bitflags::bitflags! {
    /// `SafetyStatusBitmap`.
    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
    pub struct SafetyStatusBitmap: u16 {
        /// Movement commands are ignored (locked out). e.g. not granted authorization, outside some time/date range.
        const REMOTE_LOCKOUT = 1 << 0;
        /// Tampering detected on sensors or any other safety equipment. Ex: a device has been forcedly moved without its actuator(s).
        const TAMPER_DETECTION = 1 << 1;
        /// Communication failure to sensors or other safety equipment.
        const FAILED_COMMUNICATION = 1 << 2;
        /// Device has failed to reach the desired position. e.g. with position aware device, time expired before TargetPosition is reached.
        const POSITION_FAILURE = 1 << 3;
        /// Motor(s) and/or electric circuit thermal protection activated.
        const THERMAL_PROTECTION = 1 << 4;
        /// An obstacle is preventing actuator movement.
        const OBSTACLE_DETECTED = 1 << 5;
        /// Device has power related issue or limitation e.g. device is running w/ the help of a backup battery or power might not be fully available at the moment.
        const POWER = 1 << 6;
        /// Local safety sensor (not a direct obstacle) is preventing movements (e.g. Safety EU Standard EN60335).
        const STOP_INPUT = 1 << 7;
        /// Mechanical problem related to the motor(s) detected.
        const MOTOR_JAMMED = 1 << 8;
        /// PCB, fuse and other electrics problems.
        const HARDWARE_FAILURE = 1 << 9;
        /// Actuator is manually operated and is preventing actuator movement (e.g. actuator is disengaged/decoupled).
        const MANUAL_OPERATION = 1 << 10;
        /// Protection is activated.
        const PROTECTION = 1 << 11;
    }
}

impl ToTlv for SafetyStatusBitmap {
    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
        self.bits().to_tlv(w, tag)
    }
}

impl<'a> FromTlv<'a> for SafetyStatusBitmap {
    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
        let bits = <u16 as FromTlv<'a>>::from_tlv(reader, element)?;
        Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
    }
}

/// The fields of `GoToLiftPercentage` (command `0x05`).
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct GoToLiftPercentageFields {
    /// `LiftPercent100thsValue`, field 0.
    pub lift_percent100_ths_value: u16,
}

impl ToTlv for GoToLiftPercentageFields {
    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
        w.start_structure(tag)?;
        self.lift_percent100_ths_value.to_tlv(w, Tag::Context(0))?;
        w.end_container()
    }
}

impl<'a> FromTlv<'a> for GoToLiftPercentageFields {
    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
        if element.value.container() != Some(ContainerKind::Structure) {
            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
        }
        let mut lift_percent100_ths_value = None;
        loop {
            let Some(field) = reader.next_element()? else {
                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
            };
            if field.value == Value::EndOfContainer {
                break;
            }
            match field.tag.context() {
                Some(0) => lift_percent100_ths_value = Some(<u16>::from_tlv(reader, &field)?),
                // A field this revision does not define. §7.19.2: a receiver
                // ignores what it does not know rather than refusing the whole
                // structure, which is what lets a newer peer talk to an older one.
                _ => reader.skip_value(&field)?,
            }
        }
        Ok(Self {
            lift_percent100_ths_value: lift_percent100_ths_value
                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
        })
    }
}

/// The fields of `GoToTiltPercentage` (command `0x08`).
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct GoToTiltPercentageFields {
    /// `TiltPercent100thsValue`, field 0.
    pub tilt_percent100_ths_value: u16,
}

impl ToTlv for GoToTiltPercentageFields {
    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
        w.start_structure(tag)?;
        self.tilt_percent100_ths_value.to_tlv(w, Tag::Context(0))?;
        w.end_container()
    }
}

impl<'a> FromTlv<'a> for GoToTiltPercentageFields {
    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
        if element.value.container() != Some(ContainerKind::Structure) {
            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
        }
        let mut tilt_percent100_ths_value = None;
        loop {
            let Some(field) = reader.next_element()? else {
                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
            };
            if field.value == Value::EndOfContainer {
                break;
            }
            match field.tag.context() {
                Some(0) => tilt_percent100_ths_value = Some(<u16>::from_tlv(reader, &field)?),
                // A field this revision does not define. §7.19.2: a receiver
                // ignores what it does not know rather than refusing the whole
                // structure, which is what lets a newer peer talk to an older one.
                _ => reader.skip_value(&field)?,
            }
        }
        Ok(Self {
            tilt_percent100_ths_value: tilt_percent100_ths_value
                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
        })
    }
}

/// Every attribute the specification defines, with its conformance.
pub const ATTRIBUTES: &[Attribute] = &[
    Attribute {
        id: 0x0000,
        name: "Type",
        kind: "TypeEnum",
        access: Access::read_only(Privilege::View),
        qualities: AttributeQualities::FIXED,
        reporting: Reporting::OnChange,
        conform: Conform::MANDATORY,
    },
    Attribute {
        id: 0x0005,
        name: "NumberOfActuationsLift",
        kind: "uint16",
        access: Access::read_only(Privilege::View),
        qualities: AttributeQualities::NON_VOLATILE,
        reporting: Reporting::OnChange,
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Optional,
                when: Condition::Feature(0),
            }],
        },
    },
    Attribute {
        id: 0x0006,
        name: "NumberOfActuationsTilt",
        kind: "uint16",
        access: Access::read_only(Privilege::View),
        qualities: AttributeQualities::NON_VOLATILE,
        reporting: Reporting::OnChange,
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Optional,
                when: Condition::Feature(1),
            }],
        },
    },
    Attribute {
        id: 0x0007,
        name: "ConfigStatus",
        kind: "ConfigStatusBitmap",
        access: Access::read_only(Privilege::View),
        qualities: AttributeQualities::NON_VOLATILE,
        reporting: Reporting::OnChange,
        conform: Conform::MANDATORY,
    },
    Attribute {
        id: 0x0008,
        name: "CurrentPositionLiftPercentage",
        kind: "percent",
        access: Access::read_only(Privilege::View),
        qualities: AttributeQualities::NULLABLE.union(AttributeQualities::NON_VOLATILE),
        reporting: Reporting::OnChange,
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Optional,
                when: Condition::All(&[Condition::Feature(0), Condition::Feature(2)]),
            }],
        },
    },
    Attribute {
        id: 0x0009,
        name: "CurrentPositionTiltPercentage",
        kind: "percent",
        access: Access::read_only(Privilege::View),
        qualities: AttributeQualities::NULLABLE.union(AttributeQualities::NON_VOLATILE),
        reporting: Reporting::OnChange,
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Optional,
                when: Condition::All(&[Condition::Feature(1), Condition::Feature(4)]),
            }],
        },
    },
    Attribute {
        id: 0x000A,
        name: "OperationalStatus",
        kind: "OperationalStatusBitmap",
        access: Access::read_only(Privilege::View),
        qualities: AttributeQualities::empty(),
        reporting: Reporting::OnChange,
        conform: Conform::MANDATORY,
    },
    Attribute {
        id: 0x000B,
        name: "TargetPositionLiftPercent100ths",
        kind: "percent100ths",
        access: Access::read_only(Privilege::View),
        qualities: AttributeQualities::NULLABLE,
        reporting: Reporting::OnChange,
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Mandatory,
                when: Condition::All(&[Condition::Feature(0), Condition::Feature(2)]),
            }],
        },
    },
    Attribute {
        id: 0x000C,
        name: "TargetPositionTiltPercent100ths",
        kind: "percent100ths",
        access: Access::read_only(Privilege::View),
        qualities: AttributeQualities::NULLABLE,
        reporting: Reporting::OnChange,
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Mandatory,
                when: Condition::All(&[Condition::Feature(1), Condition::Feature(4)]),
            }],
        },
    },
    Attribute {
        id: 0x000D,
        name: "EndProductType",
        kind: "EndProductTypeEnum",
        access: Access::read_only(Privilege::View),
        qualities: AttributeQualities::FIXED,
        reporting: Reporting::OnChange,
        conform: Conform::MANDATORY,
    },
    Attribute {
        id: 0x000E,
        name: "CurrentPositionLiftPercent100ths",
        kind: "percent100ths",
        access: Access::read_only(Privilege::View),
        qualities: AttributeQualities::NULLABLE.union(AttributeQualities::NON_VOLATILE),
        reporting: Reporting::OnChange,
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Mandatory,
                when: Condition::All(&[Condition::Feature(0), Condition::Feature(2)]),
            }],
        },
    },
    Attribute {
        id: 0x000F,
        name: "CurrentPositionTiltPercent100ths",
        kind: "percent100ths",
        access: Access::read_only(Privilege::View),
        qualities: AttributeQualities::NULLABLE.union(AttributeQualities::NON_VOLATILE),
        reporting: Reporting::OnChange,
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Mandatory,
                when: Condition::All(&[Condition::Feature(1), Condition::Feature(4)]),
            }],
        },
    },
    Attribute {
        id: 0x0017,
        name: "Mode",
        kind: "ModeBitmap",
        access: Access::read_write_with(Privilege::View, Privilege::Manage),
        qualities: AttributeQualities::NON_VOLATILE,
        reporting: Reporting::OnChange,
        conform: Conform::MANDATORY,
    },
    Attribute {
        id: 0x001A,
        name: "SafetyStatus",
        kind: "SafetyStatusBitmap",
        access: Access::read_only(Privilege::View),
        qualities: AttributeQualities::empty(),
        reporting: Reporting::OnChange,
        conform: Conform::OPTIONAL,
    },
];

/// Every command, with its conformance.
pub const COMMANDS: &[Command] = &[
    Command {
        id: 0x00,
        name: "UpOrOpen",
        to_server: true,
        response: None,
        access: Access::invoke(Privilege::Operate),
        conform: Conform::MANDATORY,
    },
    Command {
        id: 0x01,
        name: "DownOrClose",
        to_server: true,
        response: None,
        access: Access::invoke(Privilege::Operate),
        conform: Conform::MANDATORY,
    },
    Command {
        id: 0x02,
        name: "StopMotion",
        to_server: true,
        response: None,
        access: Access::invoke(Privilege::Operate),
        conform: Conform::MANDATORY,
    },
    Command {
        id: 0x05,
        name: "GoToLiftPercentage",
        to_server: true,
        response: None,
        access: Access::invoke(Privilege::Operate),
        conform: Conform {
            clauses: &[
                Clause {
                    verdict: Conformance::Mandatory,
                    when: Condition::All(&[Condition::Feature(0), Condition::Feature(2)]),
                },
                Clause {
                    verdict: Conformance::Optional,
                    when: Condition::Feature(0),
                },
            ],
        },
    },
    Command {
        id: 0x08,
        name: "GoToTiltPercentage",
        to_server: true,
        response: None,
        access: Access::invoke(Privilege::Operate),
        conform: Conform {
            clauses: &[
                Clause {
                    verdict: Conformance::Mandatory,
                    when: Condition::All(&[Condition::Feature(1), Condition::Feature(4)]),
                },
                Clause {
                    verdict: Conformance::Optional,
                    when: Condition::Feature(1),
                },
            ],
        },
    },
];

/// Every event, with its conformance.
pub const EVENTS: &[Event] = &[];

/// The whole cluster, as the specification defines it.
pub const CLUSTER: Cluster = Cluster {
    id: ID,
    name: "Window Covering",
    revision: REVISION,
    pics: "WNCV",
    derived_from: None,
    features: FEATURES,
    attributes: ATTRIBUTES,
    commands: COMMANDS,
    events: EVENTS,
};