matter_kit/clusters/generated/
energy_preference.rs1#![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
26pub const ID: ClusterId = 0x009B;
28
29pub const REVISION: u16 = 1;
32
33pub const PICS: &str = "EPREF";
35
36pub mod feature {
41 pub const ENERGY_BALANCE: u32 = 1 << 0;
45 pub const LOW_POWER_MODE_SENSITIVITY: u32 = 1 << 1;
49}
50
51pub 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
67pub mod attribute {
69 use crate::im::AttributeId;
70
71 pub const ENERGY_BALANCES: AttributeId = 0x00;
73 pub const CURRENT_ENERGY_BALANCE: AttributeId = 0x01;
75 pub const ENERGY_PRIORITIES: AttributeId = 0x02;
77 pub const LOW_POWER_MODE_SENSITIVITIES: AttributeId = 0x03;
79 pub const CURRENT_LOW_POWER_MODE_SENSITIVITY: AttributeId = 0x04;
81}
82
83#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
85#[repr(u8)]
86pub enum EnergyPriorityEnum {
87 Comfort = 0,
89 Speed = 1,
91 Efficiency = 2,
93 WaterConsumption = 3,
95}
96
97impl EnergyPriorityEnum {
98 #[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 #[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#[derive(Debug, Clone, Copy, PartialEq)]
132pub struct BalanceStruct<'a> {
133 pub step: u8,
135 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 _ => 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
180pub 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
254pub const COMMANDS: &[Command] = &[];
256
257pub const EVENTS: &[Event] = &[];
259
260pub 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};