Skip to main content

matter_kit/clusters/generated/
unit_localization.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Unit Localization — cluster 0x002D.
4//
5// Regenerate with `cargo xtask clusters --dm <checkout>/data_model/1.6`; `cargo xtask check`
6// is the CI gate that keeps this file honest. The XML itself is not vendored here — it
7// carries the CSA's own copyright notice and is not redistributable.
8
9//! Unit Localization (cluster `0x002D`, revision 2).
10//!
11//! 2 identifiers, 1 feature bits, and the specification's own conformance for
12//! every element. `CLUSTER` is the whole table.
13
14#![allow(unused_imports)]
15
16use crate::dm::conformance::{Clause, Condition, Conform, Conformance};
17use crate::dm::meta::{EventPriority, Reporting};
18use crate::dm::spec::{Attribute, Cluster, Command, Event, Feature};
19use crate::dm::{Access, AccessQualities, AttributeQualities, Privilege};
20use crate::error::Result;
21use crate::im::{AttributeId, ClusterId, CommandId, EventId};
22use crate::tlv::{
23    ContainerKind, Element, FromTlv, Nullable, Tag, TlvList, TlvReader, TlvWriter, ToTlv, Value,
24};
25
26/// The cluster id.
27pub const ID: ClusterId = 0x002D;
28
29/// The highest revision the specification's history defines — what `ClusterRevision`
30/// must report (Core §7.13.1).
31pub const REVISION: u16 = 2;
32
33/// The PICS code, which a certification declaration names the cluster by.
34pub const PICS: &str = "LUNIT";
35
36/// The `FeatureMap` bits (Core §7.13.2).
37///
38/// A feature has conformance of its own: a device may not claim one the
39/// specification forbids it alongside another.
40pub mod feature {
41    /// The Node can be configured to use different units of temperature when conveying values to a user.
42    ///
43    /// Code `TEMP`, bit 0.
44    pub const TEMPERATURE_UNIT: u32 = 1 << 0;
45}
46
47/// Every feature bit, with its conformance.
48pub const FEATURES: &[Feature] = &[Feature {
49    bit: 0,
50    code: "TEMP",
51    name: "TemperatureUnit",
52    conform: Conform::OPTIONAL,
53}];
54
55/// The attribute ids.
56pub mod attribute {
57    use crate::im::AttributeId;
58
59    /// `TemperatureUnit`.
60    pub const TEMPERATURE_UNIT: AttributeId = 0x00;
61    /// `SupportedTemperatureUnits`.
62    pub const SUPPORTED_TEMPERATURE_UNITS: AttributeId = 0x01;
63}
64
65/// `TempUnitEnum`.
66#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
67#[repr(u8)]
68pub enum TempUnitEnum {
69    /// Temperature conveyed in Fahrenheit
70    Fahrenheit = 0,
71    /// Temperature conveyed in Celsius
72    Celsius = 1,
73    /// Temperature conveyed in Kelvin
74    Kelvin = 2,
75}
76
77impl TempUnitEnum {
78    /// Reads a wire value, or `None` for one this revision does not define.
79    #[must_use]
80    pub const fn from_value(value: u8) -> Option<Self> {
81        match value {
82            0 => Some(Self::Fahrenheit),
83            1 => Some(Self::Celsius),
84            2 => Some(Self::Kelvin),
85            _ => None,
86        }
87    }
88
89    /// Its wire value.
90    #[must_use]
91    pub const fn value(self) -> u8 {
92        self as u8
93    }
94}
95
96impl ToTlv for TempUnitEnum {
97    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
98        self.value().to_tlv(w, tag)
99    }
100}
101
102impl<'a> FromTlv<'a> for TempUnitEnum {
103    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
104        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
105        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
106    }
107}
108
109/// Every attribute the specification defines, with its conformance.
110pub const ATTRIBUTES: &[Attribute] = &[
111    Attribute {
112        id: 0x0000,
113        name: "TemperatureUnit",
114        kind: "TempUnitEnum",
115        access: Access::read_write_with(Privilege::View, Privilege::Manage),
116        qualities: AttributeQualities::NON_VOLATILE,
117        reporting: Reporting::OnChange,
118        conform: Conform {
119            clauses: &[Clause {
120                verdict: Conformance::Mandatory,
121                when: Condition::Feature(0),
122            }],
123        },
124    },
125    Attribute {
126        id: 0x0001,
127        name: "SupportedTemperatureUnits",
128        kind: "list[TempUnitEnum]",
129        access: Access::read_only(Privilege::View),
130        qualities: AttributeQualities::FIXED,
131        reporting: Reporting::OnChange,
132        conform: Conform {
133            clauses: &[Clause {
134                verdict: Conformance::Mandatory,
135                when: Condition::Feature(0),
136            }],
137        },
138    },
139];
140
141/// Every command, with its conformance.
142pub const COMMANDS: &[Command] = &[];
143
144/// Every event, with its conformance.
145pub const EVENTS: &[Event] = &[];
146
147/// The whole cluster, as the specification defines it.
148pub const CLUSTER: Cluster = Cluster {
149    id: ID,
150    name: "Unit Localization",
151    revision: REVISION,
152    pics: "LUNIT",
153    derived_from: None,
154    features: FEATURES,
155    attributes: ATTRIBUTES,
156    commands: COMMANDS,
157    events: EVENTS,
158};