matter_clusters/gen/
air_quality.rs1#![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
17pub const CLUSTER_ID: u32 = 0x005B;
19pub const CLUSTER_REVISION: u16 = 1;
21
22pub mod command_id {}
24
25pub mod attribute_id {
27 pub const AIR_QUALITY: u32 = 0x0000;
29}
30
31bitflags::bitflags! {
32 #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
34 pub struct Feature: u32 {
35 const FAIR = 1 << 0;
37 const MOD = 1 << 1;
39 const VPOOR = 1 << 2;
41 const XPOOR = 1 << 3;
43 }
44}
45
46#[derive(Copy, Clone, Debug, PartialEq, Eq)]
48pub enum AirQualityEnum {
49 Unknown,
51 Good,
53 Fair,
55 Moderate,
57 Poor,
59 VeryPoor,
61 ExtremelyPoor,
63 Unrecognized(u8),
65}
66
67impl AirQualityEnum {
68 #[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 #[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
98pub 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}