Skip to main content

matter_kit/clusters/generated/
energy_preference.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Energy Preference — cluster 0x009B.
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//! Energy Preference (cluster `0x009B`, revision 1).
10//!
11//! 5 identifiers, 2 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 = 0x009B;
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 = "EPREF";
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    /// Device can balance energy consumption vs. another priority
42    ///
43    /// Code `BALA`, bit 0.
44    pub const ENERGY_BALANCE: u32 = 1 << 0;
45    /// Device can adjust the conditions for entering a low power mode
46    ///
47    /// Code `LPMS`, bit 1.
48    pub const LOW_POWER_MODE_SENSITIVITY: u32 = 1 << 1;
49}
50
51/// Every feature bit, with its conformance.
52pub const FEATURES: &[Feature] = &[
53    Feature {
54        bit: 0,
55        code: "BALA",
56        name: "EnergyBalance",
57        conform: Conform::OPTIONAL,
58    },
59    Feature {
60        bit: 1,
61        code: "LPMS",
62        name: "LowPowerModeSensitivity",
63        conform: Conform::OPTIONAL,
64    },
65];
66
67/// The attribute ids.
68pub mod attribute {
69    use crate::im::AttributeId;
70
71    /// `EnergyBalances`.
72    pub const ENERGY_BALANCES: AttributeId = 0x00;
73    /// `CurrentEnergyBalance`.
74    pub const CURRENT_ENERGY_BALANCE: AttributeId = 0x01;
75    /// `EnergyPriorities`.
76    pub const ENERGY_PRIORITIES: AttributeId = 0x02;
77    /// `LowPowerModeSensitivities`.
78    pub const LOW_POWER_MODE_SENSITIVITIES: AttributeId = 0x03;
79    /// `CurrentLowPowerModeSensitivity`.
80    pub const CURRENT_LOW_POWER_MODE_SENSITIVITY: AttributeId = 0x04;
81}
82
83/// `EnergyPriorityEnum`.
84#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
85#[repr(u8)]
86pub enum EnergyPriorityEnum {
87    /// User comfort
88    Comfort = 0,
89    /// Speed of operation
90    Speed = 1,
91    /// Amount of Energy consumed by the device
92    Efficiency = 2,
93    /// Amount of water consumed by the device
94    WaterConsumption = 3,
95}
96
97impl EnergyPriorityEnum {
98    /// Reads a wire value, or `None` for one this revision does not define.
99    #[must_use]
100    pub const fn from_value(value: u8) -> Option<Self> {
101        match value {
102            0 => Some(Self::Comfort),
103            1 => Some(Self::Speed),
104            2 => Some(Self::Efficiency),
105            3 => Some(Self::WaterConsumption),
106            _ => None,
107        }
108    }
109
110    /// Its wire value.
111    #[must_use]
112    pub const fn value(self) -> u8 {
113        self as u8
114    }
115}
116
117impl ToTlv for EnergyPriorityEnum {
118    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
119        self.value().to_tlv(w, tag)
120    }
121}
122
123impl<'a> FromTlv<'a> for EnergyPriorityEnum {
124    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
125        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
126        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
127    }
128}
129
130/// `BalanceStruct`.
131#[derive(Debug, Clone, Copy, PartialEq)]
132pub struct BalanceStruct<'a> {
133    /// `Step`, field 0.
134    pub step: u8,
135    /// `Label`, field 1.
136    pub label: Option<&'a str>,
137}
138
139impl<'a> ToTlv for BalanceStruct<'a> {
140    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
141        w.start_structure(tag)?;
142        self.step.to_tlv(w, Tag::Context(0))?;
143        if let Some(value) = &self.label {
144            value.to_tlv(w, Tag::Context(1))?;
145        }
146        w.end_container()
147    }
148}
149
150impl<'a> FromTlv<'a> for BalanceStruct<'a> {
151    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
152        if element.value.container() != Some(ContainerKind::Structure) {
153            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
154        }
155        let mut step = None;
156        let mut label = None;
157        loop {
158            let Some(field) = reader.next_element()? else {
159                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
160            };
161            if field.value == Value::EndOfContainer {
162                break;
163            }
164            match field.tag.context() {
165                Some(0) => step = Some(<u8>::from_tlv(reader, &field)?),
166                Some(1) => label = Some(<&'a str>::from_tlv(reader, &field)?),
167                // A field this revision does not define. §7.19.2: a receiver
168                // ignores what it does not know rather than refusing the whole
169                // structure, which is what lets a newer peer talk to an older one.
170                _ => reader.skip_value(&field)?,
171            }
172        }
173        Ok(Self {
174            step: step.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
175            label,
176        })
177    }
178}
179
180/// Every attribute the specification defines, with its conformance.
181pub const ATTRIBUTES: &[Attribute] = &[
182    Attribute {
183        id: 0x0000,
184        name: "EnergyBalances",
185        kind: "list[BalanceStruct]",
186        access: Access::read_only(Privilege::View),
187        qualities: AttributeQualities::FIXED,
188        reporting: Reporting::OnChange,
189        conform: Conform {
190            clauses: &[Clause {
191                verdict: Conformance::Mandatory,
192                when: Condition::Feature(0),
193            }],
194        },
195    },
196    Attribute {
197        id: 0x0001,
198        name: "CurrentEnergyBalance",
199        kind: "uint8",
200        access: Access::read_write_with(Privilege::View, Privilege::Operate),
201        qualities: AttributeQualities::NON_VOLATILE,
202        reporting: Reporting::OnChange,
203        conform: Conform {
204            clauses: &[Clause {
205                verdict: Conformance::Mandatory,
206                when: Condition::Feature(0),
207            }],
208        },
209    },
210    Attribute {
211        id: 0x0002,
212        name: "EnergyPriorities",
213        kind: "list[EnergyPriorityEnum]",
214        access: Access::read_only(Privilege::View),
215        qualities: AttributeQualities::FIXED,
216        reporting: Reporting::OnChange,
217        conform: Conform {
218            clauses: &[Clause {
219                verdict: Conformance::Mandatory,
220                when: Condition::Feature(0),
221            }],
222        },
223    },
224    Attribute {
225        id: 0x0003,
226        name: "LowPowerModeSensitivities",
227        kind: "list[BalanceStruct]",
228        access: Access::read_only(Privilege::View),
229        qualities: AttributeQualities::FIXED,
230        reporting: Reporting::OnChange,
231        conform: Conform {
232            clauses: &[Clause {
233                verdict: Conformance::Mandatory,
234                when: Condition::Feature(1),
235            }],
236        },
237    },
238    Attribute {
239        id: 0x0004,
240        name: "CurrentLowPowerModeSensitivity",
241        kind: "uint8",
242        access: Access::read_write_with(Privilege::View, Privilege::Operate),
243        qualities: AttributeQualities::NON_VOLATILE,
244        reporting: Reporting::OnChange,
245        conform: Conform {
246            clauses: &[Clause {
247                verdict: Conformance::Mandatory,
248                when: Condition::Feature(1),
249            }],
250        },
251    },
252];
253
254/// Every command, with its conformance.
255pub const COMMANDS: &[Command] = &[];
256
257/// Every event, with its conformance.
258pub const EVENTS: &[Event] = &[];
259
260/// The whole cluster, as the specification defines it.
261pub const CLUSTER: Cluster = Cluster {
262    id: ID,
263    name: "Energy Preference",
264    revision: REVISION,
265    pics: "EPREF",
266    derived_from: None,
267    features: FEATURES,
268    attributes: ATTRIBUTES,
269    commands: COMMANDS,
270    events: EVENTS,
271};