Skip to main content

matter_clusters/gen/
switch.rs

1//! Switch cluster (0x003B).
2//! @generated by `cargo xtask codegen` — do not edit.
3
4#![allow(
5    clippy::all,
6    clippy::pedantic,
7    dead_code,
8    unreachable_pub,
9    unused_imports
10)]
11
12use crate::datatypes::SemanticTagStruct;
13use crate::error::ClusterError;
14use crate::types::Nullable;
15use matter_codec::{ContainerKind, Element, Tag, TlvReader, TlvWriter, Value};
16
17/// Cluster ID.
18pub const CLUSTER_ID: u32 = 0x003B;
19/// Cluster revision.
20pub const CLUSTER_REVISION: u16 = 2;
21
22/// Command IDs (requests and responses).
23pub mod command_id {}
24
25/// Attribute IDs (cluster-specific).
26pub mod attribute_id {
27    /// `NumberOfPositions`.
28    pub const NUMBER_OF_POSITIONS: u32 = 0x0000;
29    /// `CurrentPosition`.
30    pub const CURRENT_POSITION: u32 = 0x0001;
31    /// `MultiPressMax`.
32    pub const MULTI_PRESS_MAX: u32 = 0x0002;
33}
34
35bitflags::bitflags! {
36    /// `Switch` feature bits (FeatureMap).
37    #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
38    pub struct Feature: u32 {
39        /// LatchingSwitch (LS).
40        const LS = 1 << 0;
41        /// MomentarySwitch (MS).
42        const MS = 1 << 1;
43        /// MomentarySwitchRelease (MSR).
44        const MSR = 1 << 2;
45        /// MomentarySwitchLongPress (MSL).
46        const MSL = 1 << 3;
47        /// MomentarySwitchMultiPress (MSM).
48        const MSM = 1 << 4;
49        /// ActionSwitch (AS).
50        const AS = 1 << 5;
51    }
52}
53
54/// Decode the `NumberOfPositions` attribute value.
55///
56/// # Errors
57/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
58pub fn decode_number_of_positions(tlv: &[u8]) -> Result<u8, ClusterError> {
59    let mut r = TlvReader::new(tlv);
60    match r.next()? {
61        Some(Element::Scalar {
62            value: Value::Uint(v),
63            ..
64        }) => Ok(u8::try_from(v).map_err(|_| ClusterError::InvalidLength("NumberOfPositions"))?),
65        _ => Err(ClusterError::UnexpectedType {
66            context: "NumberOfPositions",
67        }),
68    }
69}
70
71/// Decode the `CurrentPosition` attribute value.
72///
73/// # Errors
74/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
75pub fn decode_current_position(tlv: &[u8]) -> Result<u8, ClusterError> {
76    let mut r = TlvReader::new(tlv);
77    match r.next()? {
78        Some(Element::Scalar {
79            value: Value::Uint(v),
80            ..
81        }) => Ok(u8::try_from(v).map_err(|_| ClusterError::InvalidLength("CurrentPosition"))?),
82        _ => Err(ClusterError::UnexpectedType {
83            context: "CurrentPosition",
84        }),
85    }
86}
87
88/// Decode the `MultiPressMax` attribute value.
89///
90/// # Errors
91/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
92pub fn decode_multi_press_max(tlv: &[u8]) -> Result<u8, ClusterError> {
93    let mut r = TlvReader::new(tlv);
94    match r.next()? {
95        Some(Element::Scalar {
96            value: Value::Uint(v),
97            ..
98        }) => Ok(u8::try_from(v).map_err(|_| ClusterError::InvalidLength("MultiPressMax"))?),
99        _ => Err(ClusterError::UnexpectedType {
100            context: "MultiPressMax",
101        }),
102    }
103}