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
//! AirQuality cluster (0x005B).
//! @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 = 0x005B;
/// Cluster revision.
pub const CLUSTER_REVISION: u16 = 1;
/// Command IDs (requests and responses).
pub mod command_id {}
/// Attribute IDs (cluster-specific).
pub mod attribute_id {
/// `AirQuality`.
pub const AIR_QUALITY: u32 = 0x0000;
}
bitflags::bitflags! {
/// `AirQuality` feature bits (FeatureMap).
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct Feature: u32 {
/// Fair (FAIR).
const FAIR = 1 << 0;
/// Moderate (MOD).
const MOD = 1 << 1;
/// VeryPoor (VPOOR).
const VPOOR = 1 << 2;
/// ExtremelyPoor (XPOOR).
const XPOOR = 1 << 3;
}
}
/// `AirQualityEnum` (enum8).
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum AirQualityEnum {
/// Unknown = 0.
Unknown,
/// Good = 1.
Good,
/// Fair = 2.
Fair,
/// Moderate = 3.
Moderate,
/// Poor = 4.
Poor,
/// VeryPoor = 5.
VeryPoor,
/// ExtremelyPoor = 6.
ExtremelyPoor,
/// A value not known to this codegen revision.
Unrecognized(u8),
}
impl AirQualityEnum {
/// Decode from its raw discriminant (unknown → `Unrecognized`).
#[must_use]
pub fn from_raw(v: u8) -> Self {
match v {
0 => Self::Unknown,
1 => Self::Good,
2 => Self::Fair,
3 => Self::Moderate,
4 => Self::Poor,
5 => Self::VeryPoor,
6 => Self::ExtremelyPoor,
other => Self::Unrecognized(other),
}
}
/// The raw discriminant.
#[must_use]
pub fn to_raw(self) -> u8 {
match self {
Self::Unknown => 0,
Self::Good => 1,
Self::Fair => 2,
Self::Moderate => 3,
Self::Poor => 4,
Self::VeryPoor => 5,
Self::ExtremelyPoor => 6,
Self::Unrecognized(v) => v,
}
}
}
/// Decode the `AirQuality` attribute value.
///
/// # Errors
/// Returns [`ClusterError`] on a type mismatch or out-of-range value.
pub fn decode_air_quality(tlv: &[u8]) -> Result<AirQualityEnum, ClusterError> {
let mut r = TlvReader::new(tlv);
match r.next()? {
Some(Element::Scalar {
value: Value::Uint(v),
..
}) => Ok(AirQualityEnum::from_raw(
u8::try_from(v).map_err(|_| ClusterError::InvalidLength("AirQuality"))?,
)),
_ => Err(ClusterError::UnexpectedType {
context: "AirQuality",
}),
}
}