matter-kit 0.3.0

Matter (CSA smart-home standard) protocol implementation in Rust: no_std, no-alloc, executor-agnostic
Documentation
// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
//
// Air Quality — cluster 0x005B.
//
// Regenerate with `cargo xtask clusters --dm <checkout>/data_model/1.6`; `cargo xtask check`
// is the CI gate that keeps this file honest. The XML itself is not vendored here — it
// carries the CSA's own copyright notice and is not redistributable.

//! Air Quality (cluster `0x005B`, revision 1).
//!
//! 1 identifiers, 4 feature bits, and the specification's own conformance for
//! every element. `CLUSTER` is the whole table.

#![allow(unused_imports)]

use crate::dm::conformance::{Clause, Condition, Conform, Conformance};
use crate::dm::meta::{EventPriority, Reporting};
use crate::dm::spec::{Attribute, Cluster, Command, Event, Feature};
use crate::dm::{Access, AccessQualities, AttributeQualities, Privilege};
use crate::error::Result;
use crate::im::{AttributeId, ClusterId, CommandId, EventId};
use crate::tlv::{
    ContainerKind, Element, FromTlv, Nullable, Tag, TlvList, TlvReader, TlvWriter, ToTlv, Value,
};

/// The cluster id.
pub const ID: ClusterId = 0x005B;

/// The highest revision the specification's history defines — what `ClusterRevision`
/// must report (Core §7.13.1).
pub const REVISION: u16 = 1;

/// The PICS code, which a certification declaration names the cluster by.
pub const PICS: &str = "AIRQUAL";

/// The `FeatureMap` bits (Core §7.13.2).
///
/// A feature has conformance of its own: a device may not claim one the
/// specification forbids it alongside another.
pub mod feature {
    /// Cluster supports the Fair air quality level
    ///
    /// Code `FAIR`, bit 0.
    pub const FAIR: u32 = 1 << 0;
    /// Cluster supports the Moderate air quality level
    ///
    /// Code `MOD`, bit 1.
    pub const MODERATE: u32 = 1 << 1;
    /// Cluster supports the Very poor air quality level
    ///
    /// Code `VPOOR`, bit 2.
    pub const VERY_POOR: u32 = 1 << 2;
    /// Cluster supports the Extremely poor air quality level
    ///
    /// Code `XPOOR`, bit 3.
    pub const EXTREMELY_POOR: u32 = 1 << 3;
}

/// Every feature bit, with its conformance.
pub const FEATURES: &[Feature] = &[
    Feature {
        bit: 0,
        code: "FAIR",
        name: "Fair",
        conform: Conform::OPTIONAL,
    },
    Feature {
        bit: 1,
        code: "MOD",
        name: "Moderate",
        conform: Conform::OPTIONAL,
    },
    Feature {
        bit: 2,
        code: "VPOOR",
        name: "VeryPoor",
        conform: Conform::OPTIONAL,
    },
    Feature {
        bit: 3,
        code: "XPOOR",
        name: "ExtremelyPoor",
        conform: Conform::OPTIONAL,
    },
];

/// The attribute ids.
pub mod attribute {
    use crate::im::AttributeId;

    /// `AirQuality`.
    pub const AIR_QUALITY: AttributeId = 0x00;
}

/// `AirQualityEnum`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum AirQualityEnum {
    /// The air quality is unknown.
    Unknown = 0,
    /// The air quality is good.
    Good = 1,
    /// The air quality is fair.
    Fair = 2,
    /// The air quality is moderate.
    Moderate = 3,
    /// The air quality is poor.
    Poor = 4,
    /// The air quality is very poor.
    VeryPoor = 5,
    /// The air quality is extremely poor.
    ExtremelyPoor = 6,
}

impl AirQualityEnum {
    /// Reads a wire value, or `None` for one this revision does not define.
    #[must_use]
    pub const fn from_value(value: u8) -> Option<Self> {
        match value {
            0 => Some(Self::Unknown),
            1 => Some(Self::Good),
            2 => Some(Self::Fair),
            3 => Some(Self::Moderate),
            4 => Some(Self::Poor),
            5 => Some(Self::VeryPoor),
            6 => Some(Self::ExtremelyPoor),
            _ => None,
        }
    }

    /// Its wire value.
    #[must_use]
    pub const fn value(self) -> u8 {
        self as u8
    }
}

impl ToTlv for AirQualityEnum {
    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
        self.value().to_tlv(w, tag)
    }
}

impl<'a> FromTlv<'a> for AirQualityEnum {
    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
    }
}

/// Every attribute the specification defines, with its conformance.
pub const ATTRIBUTES: &[Attribute] = &[Attribute {
    id: 0x0000,
    name: "AirQuality",
    kind: "AirQualityEnum",
    access: Access::read_only(Privilege::View),
    qualities: AttributeQualities::empty(),
    reporting: Reporting::OnChange,
    conform: Conform::MANDATORY,
}];

/// Every command, with its conformance.
pub const COMMANDS: &[Command] = &[];

/// Every event, with its conformance.
pub const EVENTS: &[Event] = &[];

/// The whole cluster, as the specification defines it.
pub const CLUSTER: Cluster = Cluster {
    id: ID,
    name: "Air Quality",
    revision: REVISION,
    pics: "AIRQUAL",
    derived_from: None,
    features: FEATURES,
    attributes: ATTRIBUTES,
    commands: COMMANDS,
    events: EVENTS,
};