Skip to main content

matter_kit/clusters/generated/
temperature_control.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Temperature Control — cluster 0x0056.
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//! Temperature Control (cluster `0x0056`, revision 1).
10//!
11//! 7 identifiers, 3 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 = 0x0056;
28
29/// The highest revision the specification's history defines — what `ClusterRevision`
30/// must report (Core §7.13.1).
31pub const REVISION: u16 = 1;
32
33/// The PICS code, which a certification declaration names the cluster by.
34pub const PICS: &str = "TCTL";
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    /// Use actual temperature numbers
42    ///
43    /// Code `TN`, bit 0.
44    pub const TEMPERATURE_NUMBER: u32 = 1 << 0;
45    /// Use temperature levels
46    ///
47    /// Code `TL`, bit 1.
48    pub const TEMPERATURE_LEVEL: u32 = 1 << 1;
49    /// Use step control with temperature numbers
50    ///
51    /// Code `STEP`, bit 2.
52    pub const TEMPERATURE_STEP: u32 = 1 << 2;
53}
54
55/// Every feature bit, with its conformance.
56pub const FEATURES: &[Feature] = &[
57    Feature {
58        bit: 0,
59        code: "TN",
60        name: "TemperatureNumber",
61        conform: Conform::OPTIONAL,
62    },
63    Feature {
64        bit: 1,
65        code: "TL",
66        name: "TemperatureLevel",
67        conform: Conform::OPTIONAL,
68    },
69    Feature {
70        bit: 2,
71        code: "STEP",
72        name: "TemperatureStep",
73        conform: Conform {
74            clauses: &[Clause {
75                verdict: Conformance::Optional,
76                when: Condition::Feature(0),
77            }],
78        },
79    },
80];
81
82/// The attribute ids.
83pub mod attribute {
84    use crate::im::AttributeId;
85
86    /// `TemperatureSetpoint`.
87    pub const TEMPERATURE_SETPOINT: AttributeId = 0x00;
88    /// `MinTemperature`.
89    pub const MIN_TEMPERATURE: AttributeId = 0x01;
90    /// `MaxTemperature`.
91    pub const MAX_TEMPERATURE: AttributeId = 0x02;
92    /// `Step`.
93    pub const STEP: AttributeId = 0x03;
94    /// `SelectedTemperatureLevel`.
95    pub const SELECTED_TEMPERATURE_LEVEL: AttributeId = 0x04;
96    /// `SupportedTemperatureLevels`.
97    pub const SUPPORTED_TEMPERATURE_LEVELS: AttributeId = 0x05;
98}
99
100/// The command ids.
101pub mod command {
102    use crate::im::CommandId;
103
104    /// `SetTemperature`.
105    pub const SET_TEMPERATURE: CommandId = 0x00;
106}
107
108/// The fields of `SetTemperature` (command `0x00`).
109#[derive(Debug, Clone, Copy, PartialEq)]
110pub struct SetTemperatureFields {
111    /// `TargetTemperature`, field 0.
112    pub target_temperature: Option<i16>,
113    /// `TargetTemperatureLevel`, field 1.
114    pub target_temperature_level: Option<u8>,
115}
116
117impl ToTlv for SetTemperatureFields {
118    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
119        w.start_structure(tag)?;
120        if let Some(value) = &self.target_temperature {
121            value.to_tlv(w, Tag::Context(0))?;
122        }
123        if let Some(value) = &self.target_temperature_level {
124            value.to_tlv(w, Tag::Context(1))?;
125        }
126        w.end_container()
127    }
128}
129
130impl<'a> FromTlv<'a> for SetTemperatureFields {
131    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
132        if element.value.container() != Some(ContainerKind::Structure) {
133            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
134        }
135        let mut target_temperature = None;
136        let mut target_temperature_level = None;
137        loop {
138            let Some(field) = reader.next_element()? else {
139                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
140            };
141            if field.value == Value::EndOfContainer {
142                break;
143            }
144            match field.tag.context() {
145                Some(0) => target_temperature = Some(<i16>::from_tlv(reader, &field)?),
146                Some(1) => target_temperature_level = Some(<u8>::from_tlv(reader, &field)?),
147                // A field this revision does not define. §7.19.2: a receiver
148                // ignores what it does not know rather than refusing the whole
149                // structure, which is what lets a newer peer talk to an older one.
150                _ => reader.skip_value(&field)?,
151            }
152        }
153        Ok(Self {
154            target_temperature,
155            target_temperature_level,
156        })
157    }
158}
159
160/// Every attribute the specification defines, with its conformance.
161pub const ATTRIBUTES: &[Attribute] = &[
162    Attribute {
163        id: 0x0000,
164        name: "TemperatureSetpoint",
165        kind: "temperature",
166        access: Access::read_only(Privilege::View),
167        qualities: AttributeQualities::empty(),
168        reporting: Reporting::OnChange,
169        conform: Conform {
170            clauses: &[Clause {
171                verdict: Conformance::Mandatory,
172                when: Condition::Feature(0),
173            }],
174        },
175    },
176    Attribute {
177        id: 0x0001,
178        name: "MinTemperature",
179        kind: "temperature",
180        access: Access::read_only(Privilege::View),
181        qualities: AttributeQualities::FIXED,
182        reporting: Reporting::OnChange,
183        conform: Conform {
184            clauses: &[Clause {
185                verdict: Conformance::Mandatory,
186                when: Condition::Feature(0),
187            }],
188        },
189    },
190    Attribute {
191        id: 0x0002,
192        name: "MaxTemperature",
193        kind: "temperature",
194        access: Access::read_only(Privilege::View),
195        qualities: AttributeQualities::FIXED,
196        reporting: Reporting::OnChange,
197        conform: Conform {
198            clauses: &[Clause {
199                verdict: Conformance::Mandatory,
200                when: Condition::Feature(0),
201            }],
202        },
203    },
204    Attribute {
205        id: 0x0003,
206        name: "Step",
207        kind: "temperature",
208        access: Access::read_only(Privilege::View),
209        qualities: AttributeQualities::FIXED,
210        reporting: Reporting::OnChange,
211        conform: Conform {
212            clauses: &[Clause {
213                verdict: Conformance::Mandatory,
214                when: Condition::Feature(2),
215            }],
216        },
217    },
218    Attribute {
219        id: 0x0004,
220        name: "SelectedTemperatureLevel",
221        kind: "uint8",
222        access: Access::read_only(Privilege::View),
223        qualities: AttributeQualities::empty(),
224        reporting: Reporting::OnChange,
225        conform: Conform {
226            clauses: &[Clause {
227                verdict: Conformance::Mandatory,
228                when: Condition::Feature(1),
229            }],
230        },
231    },
232    Attribute {
233        id: 0x0005,
234        name: "SupportedTemperatureLevels",
235        kind: "list[string]",
236        access: Access::read_only(Privilege::View),
237        qualities: AttributeQualities::empty(),
238        reporting: Reporting::OnChange,
239        conform: Conform {
240            clauses: &[Clause {
241                verdict: Conformance::Mandatory,
242                when: Condition::Feature(1),
243            }],
244        },
245    },
246];
247
248/// Every command, with its conformance.
249pub const COMMANDS: &[Command] = &[Command {
250    id: 0x00,
251    name: "SetTemperature",
252    to_server: true,
253    response: None,
254    access: Access::invoke(Privilege::Operate),
255    conform: Conform::MANDATORY,
256}];
257
258/// Every event, with its conformance.
259pub const EVENTS: &[Event] = &[];
260
261/// The whole cluster, as the specification defines it.
262pub const CLUSTER: Cluster = Cluster {
263    id: ID,
264    name: "Temperature Control",
265    revision: REVISION,
266    pics: "TCTL",
267    derived_from: None,
268    features: FEATURES,
269    attributes: ATTRIBUTES,
270    commands: COMMANDS,
271    events: EVENTS,
272};