matter-clusters 0.3.0

Matter protocol cluster definitions (generated from the spec).
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
//! OccupancySensing cluster (0x0406).
//! @generated by `cargo xtask codegen` — do not edit.

#![allow(
    clippy::all,
    clippy::pedantic,
    dead_code,
    unreachable_pub,
    unused_imports
)]

use crate::datatypes::SemanticTagStruct;
use crate::error::ClusterError;
use crate::types::Nullable;
use matter_codec::{ContainerKind, Element, Tag, TlvReader, TlvWriter, Value};

/// Cluster ID.
pub const CLUSTER_ID: u32 = 0x0406;
/// Cluster revision.
pub const CLUSTER_REVISION: u16 = 6;

/// Command IDs (requests and responses).
pub mod command_id {}

/// Attribute IDs (cluster-specific).
pub mod attribute_id {
    /// `Occupancy`.
    pub const OCCUPANCY: u32 = 0x0000;
    /// `OccupancySensorType`.
    pub const OCCUPANCY_SENSOR_TYPE: u32 = 0x0001;
    /// `OccupancySensorTypeBitmap`.
    pub const OCCUPANCY_SENSOR_TYPE_BITMAP: u32 = 0x0002;
    /// `HoldTime`.
    pub const HOLD_TIME: u32 = 0x0003;
    /// `HoldTimeLimits`.
    pub const HOLD_TIME_LIMITS: u32 = 0x0004;
    /// `PirOccupiedToUnoccupiedDelay`.
    pub const PIR_OCCUPIED_TO_UNOCCUPIED_DELAY: u32 = 0x0010;
    /// `PirUnoccupiedToOccupiedDelay`.
    pub const PIR_UNOCCUPIED_TO_OCCUPIED_DELAY: u32 = 0x0011;
    /// `PirUnoccupiedToOccupiedThreshold`.
    pub const PIR_UNOCCUPIED_TO_OCCUPIED_THRESHOLD: u32 = 0x0012;
    /// `UltrasonicOccupiedToUnoccupiedDelay`.
    pub const ULTRASONIC_OCCUPIED_TO_UNOCCUPIED_DELAY: u32 = 0x0020;
    /// `UltrasonicUnoccupiedToOccupiedDelay`.
    pub const ULTRASONIC_UNOCCUPIED_TO_OCCUPIED_DELAY: u32 = 0x0021;
    /// `UltrasonicUnoccupiedToOccupiedThreshold`.
    pub const ULTRASONIC_UNOCCUPIED_TO_OCCUPIED_THRESHOLD: u32 = 0x0022;
    /// `PhysicalContactOccupiedToUnoccupiedDelay`.
    pub const PHYSICAL_CONTACT_OCCUPIED_TO_UNOCCUPIED_DELAY: u32 = 0x0030;
    /// `PhysicalContactUnoccupiedToOccupiedDelay`.
    pub const PHYSICAL_CONTACT_UNOCCUPIED_TO_OCCUPIED_DELAY: u32 = 0x0031;
    /// `PhysicalContactUnoccupiedToOccupiedThreshold`.
    pub const PHYSICAL_CONTACT_UNOCCUPIED_TO_OCCUPIED_THRESHOLD: u32 = 0x0032;
}

bitflags::bitflags! {
    /// `OccupancySensing` feature bits (FeatureMap).
    #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
    pub struct Feature: u32 {
        /// Other (OTHER).
        const OTHER = 1 << 0;
        /// PassiveInfrared (PIR).
        const PIR = 1 << 1;
        /// Ultrasonic (US).
        const US = 1 << 2;
        /// PhysicalContact (PHY).
        const PHY = 1 << 3;
        /// ActiveInfrared (AIR).
        const AIR = 1 << 4;
        /// Radar (RAD).
        const RAD = 1 << 5;
        /// RfSensing (RFS).
        const RFS = 1 << 6;
        /// Vision (VIS).
        const VIS = 1 << 7;
    }
}

/// `HoldTimeLimitsStruct` struct.
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub struct HoldTimeLimitsStruct {
    /// Field HoldTimeMin (tag 0).
    pub hold_time_min: u16,
    /// Field HoldTimeMax (tag 1).
    pub hold_time_max: u16,
    /// Field HoldTimeDefault (tag 2).
    pub hold_time_default: u16,
}

bitflags::bitflags! {
    /// `OccupancyBitmap` (map8).
    #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
    pub struct OccupancyBitmap: u8 {
        /// Occupied.
        const OCCUPIED = 1 << 0;
    }
}

bitflags::bitflags! {
    /// `OccupancySensorTypeBitmap` (map8).
    #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
    pub struct OccupancySensorTypeBitmap: u8 {
        /// Pir.
        const PIR = 1 << 0;
        /// Ultrasonic.
        const ULTRASONIC = 1 << 1;
        /// PhysicalContact.
        const PHYSICAL_CONTACT = 1 << 2;
    }
}

/// `OccupancySensorTypeEnum` (enum8).
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum OccupancySensorTypeEnum {
    /// Pir = 0.
    Pir,
    /// Ultrasonic = 1.
    Ultrasonic,
    /// PirAndUltrasonic = 2.
    PirAndUltrasonic,
    /// PhysicalContact = 3.
    PhysicalContact,
    /// A value not known to this codegen revision.
    Unknown(u8),
}

impl OccupancySensorTypeEnum {
    /// Decode from its raw discriminant (unknown → `Unknown`).
    #[must_use]
    pub fn from_raw(v: u8) -> Self {
        match v {
            0 => Self::Pir,
            1 => Self::Ultrasonic,
            2 => Self::PirAndUltrasonic,
            3 => Self::PhysicalContact,
            other => Self::Unknown(other),
        }
    }
    /// The raw discriminant.
    #[must_use]
    pub fn to_raw(self) -> u8 {
        match self {
            Self::Pir => 0,
            Self::Ultrasonic => 1,
            Self::PirAndUltrasonic => 2,
            Self::PhysicalContact => 3,
            Self::Unknown(v) => v,
        }
    }
}

impl HoldTimeLimitsStruct {
    /// Decode the fields of an already-opened anonymous structure
    /// (reader positioned after the struct start; consumes to its end).
    ///
    /// # Errors
    /// Returns [`ClusterError`] on a malformed structure or missing required field.
    pub fn decode_from(r: &mut TlvReader<'_>) -> Result<Self, ClusterError> {
        let mut f_hold_time_min: Option<u16> = None;
        let mut f_hold_time_max: Option<u16> = None;
        let mut f_hold_time_default: Option<u16> = None;
        loop {
            match r.next()? {
                Some(Element::ContainerEnd) => break,
                Some(Element::Scalar {
                    tag: Tag::Context(0),
                    value: Value::Uint(v),
                }) => {
                    f_hold_time_min = Some(
                        u16::try_from(v).map_err(|_| ClusterError::InvalidLength("HoldTimeMin"))?,
                    )
                }
                Some(Element::Scalar {
                    tag: Tag::Context(1),
                    value: Value::Uint(v),
                }) => {
                    f_hold_time_max = Some(
                        u16::try_from(v).map_err(|_| ClusterError::InvalidLength("HoldTimeMax"))?,
                    )
                }
                Some(Element::Scalar {
                    tag: Tag::Context(2),
                    value: Value::Uint(v),
                }) => {
                    f_hold_time_default = Some(
                        u16::try_from(v)
                            .map_err(|_| ClusterError::InvalidLength("HoldTimeDefault"))?,
                    )
                }
                None => return Err(ClusterError::Tlv(matter_codec::Error::UnclosedContainer)),
                Some(Element::ContainerStart { .. }) => r.skip_container()?,
                Some(_) => {} // unknown/future scalar — skip
            }
        }
        Ok(Self {
            hold_time_min: f_hold_time_min.ok_or(ClusterError::MissingField("HoldTimeMin"))?,
            hold_time_max: f_hold_time_max.ok_or(ClusterError::MissingField("HoldTimeMax"))?,
            hold_time_default: f_hold_time_default
                .ok_or(ClusterError::MissingField("HoldTimeDefault"))?,
        })
    }
    /// Decode from a standalone anonymous TLV structure.
    ///
    /// # Errors
    /// Returns [`ClusterError`] if the bytes are not an anonymous structure or a field is malformed.
    pub fn decode(tlv: &[u8]) -> Result<Self, ClusterError> {
        let mut r = TlvReader::new(tlv);
        match r.next()? {
            Some(Element::ContainerStart {
                kind: ContainerKind::Structure,
                ..
            }) => {}
            _ => {
                return Err(ClusterError::UnexpectedType {
                    context: "HoldTimeLimitsStruct",
                })
            }
        }
        Self::decode_from(&mut r)
    }
    /// Write this struct's fields into an already-open container.
    #[allow(clippy::expect_used)] // Vec-backed TlvWriter is infallible.
    pub fn write_fields(&self, w: &mut TlvWriter<'_>) {
        w.put_uint(Tag::Context(0), u64::from(self.hold_time_min))
            .expect("infallible: vec writer");
        w.put_uint(Tag::Context(1), u64::from(self.hold_time_max))
            .expect("infallible: vec writer");
        w.put_uint(Tag::Context(2), u64::from(self.hold_time_default))
            .expect("infallible: vec writer");
    }
    /// Encode as a standalone anonymous TLV structure.
    #[must_use]
    #[allow(clippy::expect_used)] // Vec-backed TlvWriter is infallible.
    pub fn encode(&self) -> Vec<u8> {
        let mut buf = Vec::new();
        let mut w = TlvWriter::new(&mut buf);
        w.start_structure(Tag::Anonymous)
            .expect("infallible: vec writer");
        self.write_fields(&mut w);
        w.end_container().expect("infallible: vec writer");
        buf
    }
}

/// Decode the `Occupancy` attribute value.
///
/// # Errors
/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
pub fn decode_occupancy(tlv: &[u8]) -> Result<OccupancyBitmap, ClusterError> {
    let mut r = TlvReader::new(tlv);
    match r.next()? {
        Some(Element::Scalar {
            value: Value::Uint(v),
            ..
        }) => Ok(OccupancyBitmap::from_bits_retain(
            u8::try_from(v).map_err(|_| ClusterError::InvalidLength("Occupancy"))?,
        )),
        _ => Err(ClusterError::UnexpectedType {
            context: "Occupancy",
        }),
    }
}

/// Decode the `OccupancySensorType` attribute value.
///
/// # Errors
/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
pub fn decode_occupancy_sensor_type(tlv: &[u8]) -> Result<OccupancySensorTypeEnum, ClusterError> {
    let mut r = TlvReader::new(tlv);
    match r.next()? {
        Some(Element::Scalar {
            value: Value::Uint(v),
            ..
        }) => Ok(OccupancySensorTypeEnum::from_raw(u8::try_from(v).map_err(
            |_| ClusterError::InvalidLength("OccupancySensorType"),
        )?)),
        _ => Err(ClusterError::UnexpectedType {
            context: "OccupancySensorType",
        }),
    }
}

/// Decode the `OccupancySensorTypeBitmap` attribute value.
///
/// # Errors
/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
pub fn decode_occupancy_sensor_type_bitmap(
    tlv: &[u8],
) -> Result<OccupancySensorTypeBitmap, ClusterError> {
    let mut r = TlvReader::new(tlv);
    match r.next()? {
        Some(Element::Scalar {
            value: Value::Uint(v),
            ..
        }) => Ok(OccupancySensorTypeBitmap::from_bits_retain(
            u8::try_from(v)
                .map_err(|_| ClusterError::InvalidLength("OccupancySensorTypeBitmap"))?,
        )),
        _ => Err(ClusterError::UnexpectedType {
            context: "OccupancySensorTypeBitmap",
        }),
    }
}

/// Decode the `HoldTime` attribute value.
///
/// # Errors
/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
pub fn decode_hold_time(tlv: &[u8]) -> Result<u16, ClusterError> {
    let mut r = TlvReader::new(tlv);
    match r.next()? {
        Some(Element::Scalar {
            value: Value::Uint(v),
            ..
        }) => Ok(u16::try_from(v).map_err(|_| ClusterError::InvalidLength("HoldTime"))?),
        _ => Err(ClusterError::UnexpectedType {
            context: "HoldTime",
        }),
    }
}

/// Encode the `HoldTime` attribute value as a standalone TLV element.
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] // Vec-backed TlvWriter is infallible.
pub fn encode_hold_time(value: u16) -> Vec<u8> {
    let mut buf = Vec::new();
    let mut w = TlvWriter::new(&mut buf);
    w.put_uint(Tag::Anonymous, u64::from(value))
        .expect("infallible: vec writer");
    buf
}

/// Decode the `HoldTimeLimits` attribute value.
///
/// # Errors
/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
pub fn decode_hold_time_limits(tlv: &[u8]) -> Result<HoldTimeLimitsStruct, ClusterError> {
    HoldTimeLimitsStruct::decode(tlv)
}

/// Decode the `PirOccupiedToUnoccupiedDelay` attribute value.
///
/// # Errors
/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
pub fn decode_pir_occupied_to_unoccupied_delay(tlv: &[u8]) -> Result<u16, ClusterError> {
    let mut r = TlvReader::new(tlv);
    match r.next()? {
        Some(Element::Scalar {
            value: Value::Uint(v),
            ..
        }) => Ok(u16::try_from(v)
            .map_err(|_| ClusterError::InvalidLength("PirOccupiedToUnoccupiedDelay"))?),
        _ => Err(ClusterError::UnexpectedType {
            context: "PirOccupiedToUnoccupiedDelay",
        }),
    }
}

/// Encode the `PirOccupiedToUnoccupiedDelay` attribute value as a standalone TLV element.
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] // Vec-backed TlvWriter is infallible.
pub fn encode_pir_occupied_to_unoccupied_delay(value: u16) -> Vec<u8> {
    let mut buf = Vec::new();
    let mut w = TlvWriter::new(&mut buf);
    w.put_uint(Tag::Anonymous, u64::from(value))
        .expect("infallible: vec writer");
    buf
}

/// Decode the `PirUnoccupiedToOccupiedDelay` attribute value.
///
/// # Errors
/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
pub fn decode_pir_unoccupied_to_occupied_delay(tlv: &[u8]) -> Result<u16, ClusterError> {
    let mut r = TlvReader::new(tlv);
    match r.next()? {
        Some(Element::Scalar {
            value: Value::Uint(v),
            ..
        }) => Ok(u16::try_from(v)
            .map_err(|_| ClusterError::InvalidLength("PirUnoccupiedToOccupiedDelay"))?),
        _ => Err(ClusterError::UnexpectedType {
            context: "PirUnoccupiedToOccupiedDelay",
        }),
    }
}

/// Encode the `PirUnoccupiedToOccupiedDelay` attribute value as a standalone TLV element.
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] // Vec-backed TlvWriter is infallible.
pub fn encode_pir_unoccupied_to_occupied_delay(value: u16) -> Vec<u8> {
    let mut buf = Vec::new();
    let mut w = TlvWriter::new(&mut buf);
    w.put_uint(Tag::Anonymous, u64::from(value))
        .expect("infallible: vec writer");
    buf
}

/// Decode the `PirUnoccupiedToOccupiedThreshold` attribute value.
///
/// # Errors
/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
pub fn decode_pir_unoccupied_to_occupied_threshold(tlv: &[u8]) -> Result<u8, ClusterError> {
    let mut r = TlvReader::new(tlv);
    match r.next()? {
        Some(Element::Scalar {
            value: Value::Uint(v),
            ..
        }) => Ok(u8::try_from(v)
            .map_err(|_| ClusterError::InvalidLength("PirUnoccupiedToOccupiedThreshold"))?),
        _ => Err(ClusterError::UnexpectedType {
            context: "PirUnoccupiedToOccupiedThreshold",
        }),
    }
}

/// Encode the `PirUnoccupiedToOccupiedThreshold` attribute value as a standalone TLV element.
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] // Vec-backed TlvWriter is infallible.
pub fn encode_pir_unoccupied_to_occupied_threshold(value: u8) -> Vec<u8> {
    let mut buf = Vec::new();
    let mut w = TlvWriter::new(&mut buf);
    w.put_uint(Tag::Anonymous, u64::from(value))
        .expect("infallible: vec writer");
    buf
}

/// Decode the `UltrasonicOccupiedToUnoccupiedDelay` attribute value.
///
/// # Errors
/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
pub fn decode_ultrasonic_occupied_to_unoccupied_delay(tlv: &[u8]) -> Result<u16, ClusterError> {
    let mut r = TlvReader::new(tlv);
    match r.next()? {
        Some(Element::Scalar {
            value: Value::Uint(v),
            ..
        }) => Ok(u16::try_from(v)
            .map_err(|_| ClusterError::InvalidLength("UltrasonicOccupiedToUnoccupiedDelay"))?),
        _ => Err(ClusterError::UnexpectedType {
            context: "UltrasonicOccupiedToUnoccupiedDelay",
        }),
    }
}

/// Encode the `UltrasonicOccupiedToUnoccupiedDelay` attribute value as a standalone TLV element.
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] // Vec-backed TlvWriter is infallible.
pub fn encode_ultrasonic_occupied_to_unoccupied_delay(value: u16) -> Vec<u8> {
    let mut buf = Vec::new();
    let mut w = TlvWriter::new(&mut buf);
    w.put_uint(Tag::Anonymous, u64::from(value))
        .expect("infallible: vec writer");
    buf
}

/// Decode the `UltrasonicUnoccupiedToOccupiedDelay` attribute value.
///
/// # Errors
/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
pub fn decode_ultrasonic_unoccupied_to_occupied_delay(tlv: &[u8]) -> Result<u16, ClusterError> {
    let mut r = TlvReader::new(tlv);
    match r.next()? {
        Some(Element::Scalar {
            value: Value::Uint(v),
            ..
        }) => Ok(u16::try_from(v)
            .map_err(|_| ClusterError::InvalidLength("UltrasonicUnoccupiedToOccupiedDelay"))?),
        _ => Err(ClusterError::UnexpectedType {
            context: "UltrasonicUnoccupiedToOccupiedDelay",
        }),
    }
}

/// Encode the `UltrasonicUnoccupiedToOccupiedDelay` attribute value as a standalone TLV element.
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] // Vec-backed TlvWriter is infallible.
pub fn encode_ultrasonic_unoccupied_to_occupied_delay(value: u16) -> Vec<u8> {
    let mut buf = Vec::new();
    let mut w = TlvWriter::new(&mut buf);
    w.put_uint(Tag::Anonymous, u64::from(value))
        .expect("infallible: vec writer");
    buf
}

/// Decode the `UltrasonicUnoccupiedToOccupiedThreshold` attribute value.
///
/// # Errors
/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
pub fn decode_ultrasonic_unoccupied_to_occupied_threshold(tlv: &[u8]) -> Result<u8, ClusterError> {
    let mut r = TlvReader::new(tlv);
    match r.next()? {
        Some(Element::Scalar {
            value: Value::Uint(v),
            ..
        }) => Ok(u8::try_from(v)
            .map_err(|_| ClusterError::InvalidLength("UltrasonicUnoccupiedToOccupiedThreshold"))?),
        _ => Err(ClusterError::UnexpectedType {
            context: "UltrasonicUnoccupiedToOccupiedThreshold",
        }),
    }
}

/// Encode the `UltrasonicUnoccupiedToOccupiedThreshold` attribute value as a standalone TLV element.
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] // Vec-backed TlvWriter is infallible.
pub fn encode_ultrasonic_unoccupied_to_occupied_threshold(value: u8) -> Vec<u8> {
    let mut buf = Vec::new();
    let mut w = TlvWriter::new(&mut buf);
    w.put_uint(Tag::Anonymous, u64::from(value))
        .expect("infallible: vec writer");
    buf
}

/// Decode the `PhysicalContactOccupiedToUnoccupiedDelay` attribute value.
///
/// # Errors
/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
pub fn decode_physical_contact_occupied_to_unoccupied_delay(
    tlv: &[u8],
) -> Result<u16, ClusterError> {
    let mut r = TlvReader::new(tlv);
    match r.next()? {
        Some(Element::Scalar {
            value: Value::Uint(v),
            ..
        }) => Ok(u16::try_from(v).map_err(|_| {
            ClusterError::InvalidLength("PhysicalContactOccupiedToUnoccupiedDelay")
        })?),
        _ => Err(ClusterError::UnexpectedType {
            context: "PhysicalContactOccupiedToUnoccupiedDelay",
        }),
    }
}

/// Encode the `PhysicalContactOccupiedToUnoccupiedDelay` attribute value as a standalone TLV element.
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] // Vec-backed TlvWriter is infallible.
pub fn encode_physical_contact_occupied_to_unoccupied_delay(value: u16) -> Vec<u8> {
    let mut buf = Vec::new();
    let mut w = TlvWriter::new(&mut buf);
    w.put_uint(Tag::Anonymous, u64::from(value))
        .expect("infallible: vec writer");
    buf
}

/// Decode the `PhysicalContactUnoccupiedToOccupiedDelay` attribute value.
///
/// # Errors
/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
pub fn decode_physical_contact_unoccupied_to_occupied_delay(
    tlv: &[u8],
) -> Result<u16, ClusterError> {
    let mut r = TlvReader::new(tlv);
    match r.next()? {
        Some(Element::Scalar {
            value: Value::Uint(v),
            ..
        }) => Ok(u16::try_from(v).map_err(|_| {
            ClusterError::InvalidLength("PhysicalContactUnoccupiedToOccupiedDelay")
        })?),
        _ => Err(ClusterError::UnexpectedType {
            context: "PhysicalContactUnoccupiedToOccupiedDelay",
        }),
    }
}

/// Encode the `PhysicalContactUnoccupiedToOccupiedDelay` attribute value as a standalone TLV element.
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] // Vec-backed TlvWriter is infallible.
pub fn encode_physical_contact_unoccupied_to_occupied_delay(value: u16) -> Vec<u8> {
    let mut buf = Vec::new();
    let mut w = TlvWriter::new(&mut buf);
    w.put_uint(Tag::Anonymous, u64::from(value))
        .expect("infallible: vec writer");
    buf
}

/// Decode the `PhysicalContactUnoccupiedToOccupiedThreshold` attribute value.
///
/// # Errors
/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
pub fn decode_physical_contact_unoccupied_to_occupied_threshold(
    tlv: &[u8],
) -> Result<u8, ClusterError> {
    let mut r = TlvReader::new(tlv);
    match r.next()? {
        Some(Element::Scalar {
            value: Value::Uint(v),
            ..
        }) => Ok(u8::try_from(v).map_err(|_| {
            ClusterError::InvalidLength("PhysicalContactUnoccupiedToOccupiedThreshold")
        })?),
        _ => Err(ClusterError::UnexpectedType {
            context: "PhysicalContactUnoccupiedToOccupiedThreshold",
        }),
    }
}

/// Encode the `PhysicalContactUnoccupiedToOccupiedThreshold` attribute value as a standalone TLV element.
#[must_use]
#[allow(clippy::expect_used, clippy::missing_panics_doc)] // Vec-backed TlvWriter is infallible.
pub fn encode_physical_contact_unoccupied_to_occupied_threshold(value: u8) -> Vec<u8> {
    let mut buf = Vec::new();
    let mut w = TlvWriter::new(&mut buf);
    w.put_uint(Tag::Anonymous, u64::from(value))
        .expect("infallible: vec writer");
    buf
}