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.
//
// Laundry Washer Controls — cluster 0x0053.
//
// 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.

//! Laundry Washer Controls (cluster `0x0053`, revision 2).
//!
//! 4 identifiers, 2 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 = 0x0053;

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

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

/// 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 {
    /// Multiple spin speeds supported
    ///
    /// Code `SPIN`, bit 0.
    pub const SPIN: u32 = 1 << 0;
    /// Multiple rinse cycles supported
    ///
    /// Code `RINSE`, bit 1.
    pub const RINSE: u32 = 1 << 1;
}

/// Every feature bit, with its conformance.
pub const FEATURES: &[Feature] = &[
    Feature {
        bit: 0,
        code: "SPIN",
        name: "Spin",
        conform: Conform::OPTIONAL,
    },
    Feature {
        bit: 1,
        code: "RINSE",
        name: "Rinse",
        conform: Conform::OPTIONAL,
    },
];

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

    /// `SpinSpeeds`.
    pub const SPIN_SPEEDS: AttributeId = 0x00;
    /// `SpinSpeedCurrent`.
    pub const SPIN_SPEED_CURRENT: AttributeId = 0x01;
    /// `NumberOfRinses`.
    pub const NUMBER_OF_RINSES: AttributeId = 0x02;
    /// `SupportedRinses`.
    pub const SUPPORTED_RINSES: AttributeId = 0x03;
}

/// `NumberOfRinsesEnum`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum NumberOfRinsesEnum {
    /// This laundry washer mode does not perform rinse cycles
    None = 0,
    /// This laundry washer mode performs normal rinse cycles determined by the manufacturer
    Normal = 1,
    /// This laundry washer mode performs an extra rinse cycle
    Extra = 2,
    /// This laundry washer mode performs the maximum number of rinse cycles determined by the manufacturer
    Max = 3,
}

impl NumberOfRinsesEnum {
    /// 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::None),
            1 => Some(Self::Normal),
            2 => Some(Self::Extra),
            3 => Some(Self::Max),
            _ => None,
        }
    }

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

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

impl<'a> FromTlv<'a> for NumberOfRinsesEnum {
    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: "SpinSpeeds",
        kind: "list[string]",
        access: Access::read_only(Privilege::View),
        qualities: AttributeQualities::empty(),
        reporting: Reporting::OnChange,
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Mandatory,
                when: Condition::Feature(0),
            }],
        },
    },
    Attribute {
        id: 0x0001,
        name: "SpinSpeedCurrent",
        kind: "uint8",
        access: Access::read_write_with(Privilege::View, Privilege::Operate),
        qualities: AttributeQualities::NULLABLE,
        reporting: Reporting::OnChange,
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Mandatory,
                when: Condition::Feature(0),
            }],
        },
    },
    Attribute {
        id: 0x0002,
        name: "NumberOfRinses",
        kind: "NumberOfRinsesEnum",
        access: Access::read_write_with(Privilege::View, Privilege::Operate),
        qualities: AttributeQualities::empty(),
        reporting: Reporting::OnChange,
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Mandatory,
                when: Condition::Feature(1),
            }],
        },
    },
    Attribute {
        id: 0x0003,
        name: "SupportedRinses",
        kind: "list[NumberOfRinsesEnum]",
        access: Access::read_only(Privilege::View),
        qualities: AttributeQualities::empty(),
        reporting: Reporting::OnChange,
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Mandatory,
                when: Condition::Feature(1),
            }],
        },
    },
];

/// 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: "Laundry Washer Controls",
    revision: REVISION,
    pics: "WASHERCTRL",
    derived_from: None,
    features: FEATURES,
    attributes: ATTRIBUTES,
    commands: COMMANDS,
    events: EVENTS,
};