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.
//
// Time Format Localization — cluster 0x002C.
//
// 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.

//! Time Format Localization (cluster `0x002C`, revision 1).
//!
//! 3 identifiers, 1 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 = 0x002C;

/// 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 = "LTIME";

/// 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 {
    /// The Node can be configured to use different calendar formats when conveying values to a user.
    ///
    /// Code `CALFMT`, bit 0.
    pub const CALENDAR_FORMAT: u32 = 1 << 0;
}

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

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

    /// `HourFormat`.
    pub const HOUR_FORMAT: AttributeId = 0x00;
    /// `ActiveCalendarType`.
    pub const ACTIVE_CALENDAR_TYPE: AttributeId = 0x01;
    /// `SupportedCalendarTypes`.
    pub const SUPPORTED_CALENDAR_TYPES: AttributeId = 0x02;
}

/// `CalendarTypeEnum`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum CalendarTypeEnum {
    /// Dates conveyed using the Buddhist calendar
    Buddhist = 0,
    /// Dates conveyed using the Chinese calendar
    Chinese = 1,
    /// Dates conveyed using the Coptic calendar
    Coptic = 2,
    /// Dates conveyed using the Ethiopian calendar
    Ethiopian = 3,
    /// Dates conveyed using the Gregorian calendar
    Gregorian = 4,
    /// Dates conveyed using the Hebrew calendar
    Hebrew = 5,
    /// Dates conveyed using the Indian calendar
    Indian = 6,
    /// Dates conveyed using the Islamic calendar
    Islamic = 7,
    /// Dates conveyed using the Japanese calendar
    Japanese = 8,
    /// Dates conveyed using the Korean calendar
    Korean = 9,
    /// Dates conveyed using the Persian calendar
    Persian = 10,
    /// Dates conveyed using the Taiwanese calendar
    Taiwanese = 11,
    /// calendar implied from active locale
    UseActiveLocale = 255,
}

impl CalendarTypeEnum {
    /// 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::Buddhist),
            1 => Some(Self::Chinese),
            2 => Some(Self::Coptic),
            3 => Some(Self::Ethiopian),
            4 => Some(Self::Gregorian),
            5 => Some(Self::Hebrew),
            6 => Some(Self::Indian),
            7 => Some(Self::Islamic),
            8 => Some(Self::Japanese),
            9 => Some(Self::Korean),
            10 => Some(Self::Persian),
            11 => Some(Self::Taiwanese),
            255 => Some(Self::UseActiveLocale),
            _ => None,
        }
    }

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

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

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

/// `HourFormatEnum`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum HourFormatEnum {
    /// Time conveyed with a 12-hour clock
    N12Hr = 0,
    /// Time conveyed with a 24-hour clock
    N24Hr = 1,
    /// Use active locale clock
    UseActiveLocale = 255,
}

impl HourFormatEnum {
    /// 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::N12Hr),
            1 => Some(Self::N24Hr),
            255 => Some(Self::UseActiveLocale),
            _ => None,
        }
    }

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

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

impl<'a> FromTlv<'a> for HourFormatEnum {
    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: "HourFormat",
        kind: "HourFormatEnum",
        access: Access::read_write_with(Privilege::View, Privilege::Manage),
        qualities: AttributeQualities::NON_VOLATILE,
        reporting: Reporting::OnChange,
        conform: Conform::MANDATORY,
    },
    Attribute {
        id: 0x0001,
        name: "ActiveCalendarType",
        kind: "CalendarTypeEnum",
        access: Access::read_write_with(Privilege::View, Privilege::Manage),
        qualities: AttributeQualities::NON_VOLATILE,
        reporting: Reporting::OnChange,
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Mandatory,
                when: Condition::Feature(0),
            }],
        },
    },
    Attribute {
        id: 0x0002,
        name: "SupportedCalendarTypes",
        kind: "list[CalendarTypeEnum]",
        access: Access::read_only(Privilege::View),
        qualities: AttributeQualities::FIXED,
        reporting: Reporting::OnChange,
        conform: Conform {
            clauses: &[Clause {
                verdict: Conformance::Mandatory,
                when: Condition::Feature(0),
            }],
        },
    },
];

/// 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: "Time Format Localization",
    revision: REVISION,
    pics: "LTIME",
    derived_from: None,
    features: FEATURES,
    attributes: ATTRIBUTES,
    commands: COMMANDS,
    events: EVENTS,
};