matc 0.1.3

Matter protocol library (controller side)
Documentation
//! Matter TLV encoders and decoders for RVC Operational State Cluster
//! Cluster ID: 0x0061
//!
//! This file is automatically generated from OperationalState_RVC.xml

#![allow(clippy::too_many_arguments)]

use anyhow;
use serde_json;


// Enum definitions

#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[repr(u8)]
pub enum ErrorState {
    /// 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 ErrorState {
    /// Convert from u8 value
    pub fn from_u8(value: u8) -> Option<Self> {
        match value {
            0 => Some(ErrorState::Noerror),
            1 => Some(ErrorState::Unabletostartorresume),
            2 => Some(ErrorState::Unabletocompleteoperation),
            3 => Some(ErrorState::Commandinvalidinstate),
            64 => Some(ErrorState::Failedtofindchargingdock),
            65 => Some(ErrorState::Stuck),
            66 => Some(ErrorState::Dustbinmissing),
            67 => Some(ErrorState::Dustbinfull),
            68 => Some(ErrorState::Watertankempty),
            69 => Some(ErrorState::Watertankmissing),
            70 => Some(ErrorState::Watertanklidopen),
            71 => Some(ErrorState::Mopcleaningpadmissing),
            72 => Some(ErrorState::Lowbattery),
            73 => Some(ErrorState::Cannotreachtargetarea),
            74 => Some(ErrorState::Dirtywatertankfull),
            75 => Some(ErrorState::Dirtywatertankmissing),
            76 => Some(ErrorState::Wheelsjammed),
            77 => Some(ErrorState::Brushjammed),
            78 => Some(ErrorState::Navigationsensorobscured),
            _ => None,
        }
    }

    /// Convert to u8 value
    pub fn to_u8(self) -> u8 {
        self as u8
    }
}

impl From<ErrorState> for u8 {
    fn from(val: ErrorState) -> Self {
        val as u8
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[repr(u8)]
pub enum OperationalState {
    /// 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 OperationalState {
    /// Convert from u8 value
    pub fn from_u8(value: u8) -> Option<Self> {
        match value {
            0 => Some(OperationalState::Stopped),
            1 => Some(OperationalState::Running),
            2 => Some(OperationalState::Paused),
            3 => Some(OperationalState::Error),
            64 => Some(OperationalState::Seekingcharger),
            65 => Some(OperationalState::Charging),
            66 => Some(OperationalState::Docked),
            67 => Some(OperationalState::Emptyingdustbin),
            68 => Some(OperationalState::Cleaningmop),
            69 => Some(OperationalState::Fillingwatertank),
            70 => Some(OperationalState::Updatingmaps),
            _ => None,
        }
    }

    /// Convert to u8 value
    pub fn to_u8(self) -> u8 {
        self as u8
    }
}

impl From<OperationalState> for u8 {
    fn from(val: OperationalState) -> Self {
        val as u8
    }
}

// Command encoders

// Command listing

pub fn get_command_list() -> Vec<(u32, &'static str)> {
    vec![
        (0x00, "Pause"),
        (0x01, "Stop"),
        (0x02, "Start"),
        (0x03, "Resume"),
        (0x04, "OperationalCommandResponse"),
        (0x80, "GoHome"),
    ]
}

pub fn get_command_name(cmd_id: u32) -> Option<&'static str> {
    match cmd_id {
        0x00 => Some("Pause"),
        0x01 => Some("Stop"),
        0x02 => Some("Start"),
        0x03 => Some("Resume"),
        0x04 => Some("OperationalCommandResponse"),
        0x80 => Some("GoHome"),
        _ => None,
    }
}

pub fn get_command_schema(cmd_id: u32) -> Option<Vec<crate::clusters::codec::CommandField>> {
    match cmd_id {
        0x00 => Some(vec![]),
        0x01 => Some(vec![]),
        0x02 => Some(vec![]),
        0x03 => Some(vec![]),
        0x04 => Some(vec![]),
        0x80 => Some(vec![]),
        _ => None,
    }
}

pub fn encode_command_json(cmd_id: u32, _args: &serde_json::Value) -> anyhow::Result<Vec<u8>> {
    match cmd_id {
        0x00 => Ok(vec![]),
        0x01 => Ok(vec![]),
        0x02 => Ok(vec![]),
        0x03 => Ok(vec![]),
        0x04 => Ok(vec![]),
        0x80 => Ok(vec![]),
        _ => Err(anyhow::anyhow!("unknown command ID: 0x{:02X}", cmd_id)),
    }
}

// Typed facade (invokes + reads)

/// Invoke `Pause` command on cluster `RVC Operational State`.
pub async fn pause(conn: &crate::controller::Connection, endpoint: u16) -> anyhow::Result<()> {
    conn.invoke_request(endpoint, crate::clusters::defs::CLUSTER_ID_RVC_OPERATIONAL_STATE, crate::clusters::defs::CLUSTER_RVC_OPERATIONAL_STATE_CMD_ID_PAUSE, &[]).await?;
    Ok(())
}

/// Invoke `Stop` command on cluster `RVC Operational State`.
pub async fn stop(conn: &crate::controller::Connection, endpoint: u16) -> anyhow::Result<()> {
    conn.invoke_request(endpoint, crate::clusters::defs::CLUSTER_ID_RVC_OPERATIONAL_STATE, crate::clusters::defs::CLUSTER_RVC_OPERATIONAL_STATE_CMD_ID_STOP, &[]).await?;
    Ok(())
}

/// Invoke `Start` command on cluster `RVC Operational State`.
pub async fn start(conn: &crate::controller::Connection, endpoint: u16) -> anyhow::Result<()> {
    conn.invoke_request(endpoint, crate::clusters::defs::CLUSTER_ID_RVC_OPERATIONAL_STATE, crate::clusters::defs::CLUSTER_RVC_OPERATIONAL_STATE_CMD_ID_START, &[]).await?;
    Ok(())
}

/// Invoke `Resume` command on cluster `RVC Operational State`.
pub async fn resume(conn: &crate::controller::Connection, endpoint: u16) -> anyhow::Result<()> {
    conn.invoke_request(endpoint, crate::clusters::defs::CLUSTER_ID_RVC_OPERATIONAL_STATE, crate::clusters::defs::CLUSTER_RVC_OPERATIONAL_STATE_CMD_ID_RESUME, &[]).await?;
    Ok(())
}

/// Invoke `OperationalCommandResponse` command on cluster `RVC Operational State`.
pub async fn operational_command_response(conn: &crate::controller::Connection, endpoint: u16) -> anyhow::Result<()> {
    conn.invoke_request(endpoint, crate::clusters::defs::CLUSTER_ID_RVC_OPERATIONAL_STATE, crate::clusters::defs::CLUSTER_RVC_OPERATIONAL_STATE_CMD_ID_OPERATIONALCOMMANDRESPONSE, &[]).await?;
    Ok(())
}

/// Invoke `GoHome` command on cluster `RVC Operational State`.
pub async fn go_home(conn: &crate::controller::Connection, endpoint: u16) -> anyhow::Result<()> {
    conn.invoke_request(endpoint, crate::clusters::defs::CLUSTER_ID_RVC_OPERATIONAL_STATE, crate::clusters::defs::CLUSTER_RVC_OPERATIONAL_STATE_CMD_ID_GOHOME, &[]).await?;
    Ok(())
}