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.
//
// RVC Operational State — cluster 0x0061.
//
// 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.

//! RVC Operational State (cluster `0x0061`, revision 3).
//!
//! 6 identifiers, 0 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 = 0x0061;

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

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

/// This cluster defines no features, so its `FeatureMap` is always zero.
pub const FEATURES: &[Feature] = &[];

/// The command ids.
pub mod command {
    use crate::im::CommandId;

    /// `Pause`.
    pub const PAUSE: CommandId = 0x00;
    /// `Stop`.
    pub const STOP: CommandId = 0x01;
    /// `Start`.
    pub const START: CommandId = 0x02;
    /// `Resume`.
    pub const RESUME: CommandId = 0x03;
    /// `OperationalCommandResponse`.
    pub const OPERATIONAL_COMMAND_RESPONSE: CommandId = 0x04;
    /// `GoHome`.
    pub const GO_HOME: CommandId = 0x80;
}

/// `ErrorStateEnum`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum ErrorStateEnum {
    /// The device is not in an error state
    NoError = 0,
    /// The device is unable to start or resume operation
    UnableToStartOrResume = 1,
    /// The device was unable to complete the current operation
    UnableToCompleteOperation = 2,
    /// The device cannot process the command in its current state
    CommandInvalidInState = 3,
    /// The device has failed to find or reach the charging dock
    FailedToFindChargingDock = 64,
    /// The device is stuck and requires manual intervention
    Stuck = 65,
    /// The device has detected that its dust bin is missing
    DustBinMissing = 66,
    /// The device has detected that its dust bin is full
    DustBinFull = 67,
    /// The device has detected that its clean water tank is empty
    WaterTankEmpty = 68,
    /// The device has detected that its clean water tank is missing
    WaterTankMissing = 69,
    /// The device has detected that its water tank lid is open
    WaterTankLidOpen = 70,
    /// The device has detected that its cleaning pad is missing
    MopCleaningPadMissing = 71,
    /// The device is unable to start or to continue operating due to a low battery
    LowBattery = 72,
    /// The device is unable to move to an area where it was asked to operate, such as by setting the ServiceArea cluster's SelectedAreas attribute, due to an obstruction. For example, the obstruction might be a closed door or objects blocking the mapped path.
    CannotReachTargetArea = 73,
    /// The device has detected that its dirty water tank is full
    DirtyWaterTankFull = 74,
    /// The device has detected that its dirty water tank is missing
    DirtyWaterTankMissing = 75,
    /// The device has detected that one or more wheels are jammed by an object
    WheelsJammed = 76,
    /// The device has detected that its brush is jammed by an object
    BrushJammed = 77,
    /// The device has detected that one of its sensors, such as LiDAR, infrared, or camera is obscured and needs to be cleaned
    NavigationSensorObscured = 78,
}

impl ErrorStateEnum {
    /// 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::NoError),
            1 => Some(Self::UnableToStartOrResume),
            2 => Some(Self::UnableToCompleteOperation),
            3 => Some(Self::CommandInvalidInState),
            64 => Some(Self::FailedToFindChargingDock),
            65 => Some(Self::Stuck),
            66 => Some(Self::DustBinMissing),
            67 => Some(Self::DustBinFull),
            68 => Some(Self::WaterTankEmpty),
            69 => Some(Self::WaterTankMissing),
            70 => Some(Self::WaterTankLidOpen),
            71 => Some(Self::MopCleaningPadMissing),
            72 => Some(Self::LowBattery),
            73 => Some(Self::CannotReachTargetArea),
            74 => Some(Self::DirtyWaterTankFull),
            75 => Some(Self::DirtyWaterTankMissing),
            76 => Some(Self::WheelsJammed),
            77 => Some(Self::BrushJammed),
            78 => Some(Self::NavigationSensorObscured),
            _ => None,
        }
    }

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

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

impl<'a> FromTlv<'a> for ErrorStateEnum {
    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))
    }
}

/// `OperationalStateEnum`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum OperationalStateEnum {
    /// The device is stopped
    Stopped = 0,
    /// The device is operating
    Running = 1,
    /// The device is paused during an operation
    Paused = 2,
    /// The device is in an error state
    Error = 3,
    /// The device is en route to the charging dock
    SeekingCharger = 64,
    /// The device is charging
    Charging = 65,
    /// The device is on the dock, not charging
    Docked = 66,
    /// The device is automatically emptying its own dust bin, such as to a dock
    EmptyingDustBin = 67,
    /// The device is automatically cleaning its own mopping device, such as on a dock
    CleaningMop = 68,
    /// The device is automatically filling its own clean water tank for use when mopping, such as from a dock
    FillingWaterTank = 69,
    /// The device is processing acquired data to update its maps
    UpdatingMaps = 70,
}

impl OperationalStateEnum {
    /// 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::Stopped),
            1 => Some(Self::Running),
            2 => Some(Self::Paused),
            3 => Some(Self::Error),
            64 => Some(Self::SeekingCharger),
            65 => Some(Self::Charging),
            66 => Some(Self::Docked),
            67 => Some(Self::EmptyingDustBin),
            68 => Some(Self::CleaningMop),
            69 => Some(Self::FillingWaterTank),
            70 => Some(Self::UpdatingMaps),
            _ => None,
        }
    }

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

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

impl<'a> FromTlv<'a> for OperationalStateEnum {
    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] = &[];

/// Every command, with its conformance.
pub const COMMANDS: &[Command] = &[
    Command {
        id: 0x00,
        name: "Pause",
        to_server: true,
        response: None,
        access: Access::invoke(Privilege::Operate),
        conform: Conform::MANDATORY,
    },
    Command {
        id: 0x01,
        name: "Stop",
        to_server: true,
        response: None,
        access: Access::invoke(Privilege::Operate),
        conform: Conform::DISALLOWED,
    },
    Command {
        id: 0x02,
        name: "Start",
        to_server: true,
        response: None,
        access: Access::invoke(Privilege::Operate),
        conform: Conform::DISALLOWED,
    },
    Command {
        id: 0x03,
        name: "Resume",
        to_server: true,
        response: None,
        access: Access::invoke(Privilege::Operate),
        conform: Conform::MANDATORY,
    },
    Command {
        id: 0x04,
        name: "OperationalCommandResponse",
        to_server: true,
        response: None,
        access: Access::invoke(Privilege::Operate),
        conform: Conform::MANDATORY,
    },
    Command {
        id: 0x80,
        name: "GoHome",
        to_server: true,
        response: Some(0x04),
        access: Access::invoke(Privilege::Operate),
        conform: Conform::OPTIONAL,
    },
];

/// 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: "RVC Operational State",
    revision: REVISION,
    pics: "RVCOPSTATE",
    derived_from: Some("Operational State"),
    features: FEATURES,
    attributes: ATTRIBUTES,
    commands: COMMANDS,
    events: EVENTS,
};