Skip to main content

matter_clusters/gen/
air_quality.rs

1//! AirQuality cluster (0x005B).
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 = 0x005B;
19/// Cluster revision.
20pub const CLUSTER_REVISION: u16 = 1;
21
22/// Command IDs (requests and responses).
23pub mod command_id {}
24
25/// Attribute IDs (cluster-specific).
26pub mod attribute_id {
27    /// `AirQuality`.
28    pub const AIR_QUALITY: u32 = 0x0000;
29}
30
31bitflags::bitflags! {
32    /// `AirQuality` feature bits (FeatureMap).
33    #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
34    pub struct Feature: u32 {
35        /// Fair (FAIR).
36        const FAIR = 1 << 0;
37        /// Moderate (MOD).
38        const MOD = 1 << 1;
39        /// VeryPoor (VPOOR).
40        const VPOOR = 1 << 2;
41        /// ExtremelyPoor (XPOOR).
42        const XPOOR = 1 << 3;
43    }
44}
45
46/// `AirQualityEnum` (enum8).
47#[derive(Copy, Clone, Debug, PartialEq, Eq)]
48pub enum AirQualityEnum {
49    /// Unknown = 0.
50    Unknown,
51    /// Good = 1.
52    Good,
53    /// Fair = 2.
54    Fair,
55    /// Moderate = 3.
56    Moderate,
57    /// Poor = 4.
58    Poor,
59    /// VeryPoor = 5.
60    VeryPoor,
61    /// ExtremelyPoor = 6.
62    ExtremelyPoor,
63    /// A value not known to this codegen revision.
64    Unrecognized(u8),
65}
66
67impl AirQualityEnum {
68    /// Decode from its raw discriminant (unknown → `Unrecognized`).
69    #[must_use]
70    pub fn from_raw(v: u8) -> Self {
71        match v {
72            0 => Self::Unknown,
73            1 => Self::Good,
74            2 => Self::Fair,
75            3 => Self::Moderate,
76            4 => Self::Poor,
77            5 => Self::VeryPoor,
78            6 => Self::ExtremelyPoor,
79            other => Self::Unrecognized(other),
80        }
81    }
82    /// The raw discriminant.
83    #[must_use]
84    pub fn to_raw(self) -> u8 {
85        match self {
86            Self::Unknown => 0,
87            Self::Good => 1,
88            Self::Fair => 2,
89            Self::Moderate => 3,
90            Self::Poor => 4,
91            Self::VeryPoor => 5,
92            Self::ExtremelyPoor => 6,
93            Self::Unrecognized(v) => v,
94        }
95    }
96}
97
98/// Decode the `AirQuality` attribute value.
99///
100/// # Errors
101/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
102pub fn decode_air_quality(tlv: &[u8]) -> Result<AirQualityEnum, ClusterError> {
103    let mut r = TlvReader::new(tlv);
104    match r.next()? {
105        Some(Element::Scalar {
106            value: Value::Uint(v),
107            ..
108        }) => Ok(AirQualityEnum::from_raw(
109            u8::try_from(v).map_err(|_| ClusterError::InvalidLength("AirQuality"))?,
110        )),
111        _ => Err(ClusterError::UnexpectedType {
112            context: "AirQuality",
113        }),
114    }
115}