Skip to main content

matter_kit/clusters/generated/
fan_control.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Fan Control — cluster 0x0202.
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//! Fan Control (cluster `0x0202`, revision 6).
10//!
11//! 13 identifiers, 6 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 = 0x0202;
28
29/// The highest revision the specification's history defines — what `ClusterRevision`
30/// must report (Core §7.13.1).
31pub const REVISION: u16 = 6;
32
33/// The PICS code, which a certification declaration names the cluster by.
34pub const PICS: &str = "FAN";
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    /// 0-SpeedMax Fan Speeds
42    ///
43    /// Code `SPD`, bit 0.
44    pub const MULTI_SPEED: u32 = 1 << 0;
45    /// Automatic mode supported for fan speed
46    ///
47    /// Code `AUT`, bit 1.
48    pub const AUTO: u32 = 1 << 1;
49    /// Rocking movement supported
50    ///
51    /// Code `RCK`, bit 2.
52    pub const ROCKING: u32 = 1 << 2;
53    /// Wind emulation supported
54    ///
55    /// Code `WND`, bit 3.
56    pub const WIND: u32 = 1 << 3;
57    /// Step command supported
58    ///
59    /// Code `STEP`, bit 4.
60    pub const STEP: u32 = 1 << 4;
61    /// Airflow Direction attribute is supported
62    ///
63    /// Code `DIR`, bit 5.
64    pub const AIRFLOW_DIRECTION: u32 = 1 << 5;
65}
66
67/// Every feature bit, with its conformance.
68pub const FEATURES: &[Feature] = &[
69    Feature {
70        bit: 0,
71        code: "SPD",
72        name: "MultiSpeed",
73        conform: Conform::OPTIONAL,
74    },
75    Feature {
76        bit: 1,
77        code: "AUT",
78        name: "Auto",
79        conform: Conform::OPTIONAL,
80    },
81    Feature {
82        bit: 2,
83        code: "RCK",
84        name: "Rocking",
85        conform: Conform::OPTIONAL,
86    },
87    Feature {
88        bit: 3,
89        code: "WND",
90        name: "Wind",
91        conform: Conform::OPTIONAL,
92    },
93    Feature {
94        bit: 4,
95        code: "STEP",
96        name: "Step",
97        conform: Conform::OPTIONAL,
98    },
99    Feature {
100        bit: 5,
101        code: "DIR",
102        name: "AirflowDirection",
103        conform: Conform::OPTIONAL,
104    },
105];
106
107/// The attribute ids.
108pub mod attribute {
109    use crate::im::AttributeId;
110
111    /// `FanMode`.
112    pub const FAN_MODE: AttributeId = 0x00;
113    /// `FanModeSequence`.
114    pub const FAN_MODE_SEQUENCE: AttributeId = 0x01;
115    /// `PercentSetting`.
116    pub const PERCENT_SETTING: AttributeId = 0x02;
117    /// `PercentCurrent`.
118    pub const PERCENT_CURRENT: AttributeId = 0x03;
119    /// `SpeedMax`.
120    pub const SPEED_MAX: AttributeId = 0x04;
121    /// `SpeedSetting`.
122    pub const SPEED_SETTING: AttributeId = 0x05;
123    /// `SpeedCurrent`.
124    pub const SPEED_CURRENT: AttributeId = 0x06;
125    /// `RockSupport`.
126    pub const ROCK_SUPPORT: AttributeId = 0x07;
127    /// `RockSetting`.
128    pub const ROCK_SETTING: AttributeId = 0x08;
129    /// `WindSupport`.
130    pub const WIND_SUPPORT: AttributeId = 0x09;
131    /// `WindSetting`.
132    pub const WIND_SETTING: AttributeId = 0x0A;
133    /// `AirflowDirection`.
134    pub const AIRFLOW_DIRECTION: AttributeId = 0x0B;
135}
136
137/// The command ids.
138pub mod command {
139    use crate::im::CommandId;
140
141    /// `Step`.
142    pub const STEP: CommandId = 0x00;
143}
144
145/// `AirflowDirectionEnum`.
146#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
147#[repr(u8)]
148pub enum AirflowDirectionEnum {
149    /// Airflow is in the forward direction
150    Forward = 0,
151    /// Airflow is in the reverse direction
152    Reverse = 1,
153}
154
155impl AirflowDirectionEnum {
156    /// Reads a wire value, or `None` for one this revision does not define.
157    #[must_use]
158    pub const fn from_value(value: u8) -> Option<Self> {
159        match value {
160            0 => Some(Self::Forward),
161            1 => Some(Self::Reverse),
162            _ => None,
163        }
164    }
165
166    /// Its wire value.
167    #[must_use]
168    pub const fn value(self) -> u8 {
169        self as u8
170    }
171}
172
173impl ToTlv for AirflowDirectionEnum {
174    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
175        self.value().to_tlv(w, tag)
176    }
177}
178
179impl<'a> FromTlv<'a> for AirflowDirectionEnum {
180    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
181        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
182        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
183    }
184}
185
186/// `FanModeEnum`.
187#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
188#[repr(u8)]
189pub enum FanModeEnum {
190    /// Fan is off
191    Off = 0,
192    /// Fan using low speed
193    Low = 1,
194    /// Fan using medium speed
195    Medium = 2,
196    /// Fan using high speed
197    High = 3,
198    /// `On`.
199    On = 4,
200    /// Fan is using auto mode
201    Auto = 5,
202    /// Fan is using smart mode
203    Smart = 6,
204}
205
206impl FanModeEnum {
207    /// Reads a wire value, or `None` for one this revision does not define.
208    #[must_use]
209    pub const fn from_value(value: u8) -> Option<Self> {
210        match value {
211            0 => Some(Self::Off),
212            1 => Some(Self::Low),
213            2 => Some(Self::Medium),
214            3 => Some(Self::High),
215            4 => Some(Self::On),
216            5 => Some(Self::Auto),
217            6 => Some(Self::Smart),
218            _ => None,
219        }
220    }
221
222    /// Its wire value.
223    #[must_use]
224    pub const fn value(self) -> u8 {
225        self as u8
226    }
227}
228
229impl ToTlv for FanModeEnum {
230    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
231        self.value().to_tlv(w, tag)
232    }
233}
234
235impl<'a> FromTlv<'a> for FanModeEnum {
236    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
237        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
238        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
239    }
240}
241
242/// `FanModeSequenceEnum`.
243#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
244#[repr(u8)]
245pub enum FanModeSequenceEnum {
246    /// Fan is capable of off, low, medium and high modes
247    OffLowMedHigh = 0,
248    /// Fan is capable of off, low and high modes
249    OffLowHigh = 1,
250    /// Fan is capable of off, low, medium, high and auto modes
251    OffLowMedHighAuto = 2,
252    /// Fan is capable of off, low, high and auto modes
253    OffLowHighAuto = 3,
254    /// Fan is capable of off, high and auto modes
255    OffHighAuto = 4,
256    /// Fan is capable of off and high modes
257    OffHigh = 5,
258}
259
260impl FanModeSequenceEnum {
261    /// Reads a wire value, or `None` for one this revision does not define.
262    #[must_use]
263    pub const fn from_value(value: u8) -> Option<Self> {
264        match value {
265            0 => Some(Self::OffLowMedHigh),
266            1 => Some(Self::OffLowHigh),
267            2 => Some(Self::OffLowMedHighAuto),
268            3 => Some(Self::OffLowHighAuto),
269            4 => Some(Self::OffHighAuto),
270            5 => Some(Self::OffHigh),
271            _ => None,
272        }
273    }
274
275    /// Its wire value.
276    #[must_use]
277    pub const fn value(self) -> u8 {
278        self as u8
279    }
280}
281
282impl ToTlv for FanModeSequenceEnum {
283    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
284        self.value().to_tlv(w, tag)
285    }
286}
287
288impl<'a> FromTlv<'a> for FanModeSequenceEnum {
289    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
290        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
291        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
292    }
293}
294
295/// `StepDirectionEnum`.
296#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
297#[repr(u8)]
298pub enum StepDirectionEnum {
299    /// Step moves in increasing direction
300    Increase = 0,
301    /// Step moves in decreasing direction
302    Decrease = 1,
303}
304
305impl StepDirectionEnum {
306    /// Reads a wire value, or `None` for one this revision does not define.
307    #[must_use]
308    pub const fn from_value(value: u8) -> Option<Self> {
309        match value {
310            0 => Some(Self::Increase),
311            1 => Some(Self::Decrease),
312            _ => None,
313        }
314    }
315
316    /// Its wire value.
317    #[must_use]
318    pub const fn value(self) -> u8 {
319        self as u8
320    }
321}
322
323impl ToTlv for StepDirectionEnum {
324    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
325        self.value().to_tlv(w, tag)
326    }
327}
328
329impl<'a> FromTlv<'a> for StepDirectionEnum {
330    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
331        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
332        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
333    }
334}
335
336bitflags::bitflags! {
337    /// `RockBitmap`.
338    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
339    pub struct RockBitmap: u8 {
340        /// Indicate rock left to right
341        const ROCK_LEFT_RIGHT = 1 << 0;
342        /// Indicate rock up and down
343        const ROCK_UP_DOWN = 1 << 1;
344        /// Indicate rock around
345        const ROCK_ROUND = 1 << 2;
346    }
347}
348
349impl ToTlv for RockBitmap {
350    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
351        self.bits().to_tlv(w, tag)
352    }
353}
354
355impl<'a> FromTlv<'a> for RockBitmap {
356    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
357        let bits = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
358        Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
359    }
360}
361
362bitflags::bitflags! {
363    /// `WindBitmap`.
364    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
365    pub struct WindBitmap: u8 {
366        /// Indicate sleep wind
367        const SLEEP_WIND = 1 << 0;
368        /// Indicate natural wind
369        const NATURAL_WIND = 1 << 1;
370    }
371}
372
373impl ToTlv for WindBitmap {
374    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
375        self.bits().to_tlv(w, tag)
376    }
377}
378
379impl<'a> FromTlv<'a> for WindBitmap {
380    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
381        let bits = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
382        Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
383    }
384}
385
386/// The fields of `Step` (command `0x00`).
387#[derive(Debug, Clone, Copy, PartialEq)]
388pub struct StepFields {
389    /// `Direction`, field 0.
390    pub direction: StepDirectionEnum,
391    /// `Wrap`, field 1.
392    pub wrap: Option<bool>,
393    /// `LowestOff`, field 2.
394    pub lowest_off: Option<bool>,
395}
396
397impl ToTlv for StepFields {
398    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
399        w.start_structure(tag)?;
400        self.direction.to_tlv(w, Tag::Context(0))?;
401        if let Some(value) = &self.wrap {
402            value.to_tlv(w, Tag::Context(1))?;
403        }
404        if let Some(value) = &self.lowest_off {
405            value.to_tlv(w, Tag::Context(2))?;
406        }
407        w.end_container()
408    }
409}
410
411impl<'a> FromTlv<'a> for StepFields {
412    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
413        if element.value.container() != Some(ContainerKind::Structure) {
414            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
415        }
416        let mut direction = None;
417        let mut wrap = None;
418        let mut lowest_off = None;
419        loop {
420            let Some(field) = reader.next_element()? else {
421                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
422            };
423            if field.value == Value::EndOfContainer {
424                break;
425            }
426            match field.tag.context() {
427                Some(0) => direction = Some(<StepDirectionEnum>::from_tlv(reader, &field)?),
428                Some(1) => wrap = Some(<bool>::from_tlv(reader, &field)?),
429                Some(2) => lowest_off = Some(<bool>::from_tlv(reader, &field)?),
430                // A field this revision does not define. §7.19.2: a receiver
431                // ignores what it does not know rather than refusing the whole
432                // structure, which is what lets a newer peer talk to an older one.
433                _ => reader.skip_value(&field)?,
434            }
435        }
436        Ok(Self {
437            direction: direction.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
438            wrap,
439            lowest_off,
440        })
441    }
442}
443
444/// Every attribute the specification defines, with its conformance.
445pub const ATTRIBUTES: &[Attribute] = &[
446    Attribute {
447        id: 0x0000,
448        name: "FanMode",
449        kind: "FanModeEnum",
450        access: Access::read_write_with(Privilege::View, Privilege::Operate),
451        qualities: AttributeQualities::NON_VOLATILE,
452        reporting: Reporting::OnChange,
453        conform: Conform::MANDATORY,
454    },
455    Attribute {
456        id: 0x0001,
457        name: "FanModeSequence",
458        kind: "FanModeSequenceEnum",
459        access: Access::read_only(Privilege::View),
460        qualities: AttributeQualities::FIXED,
461        reporting: Reporting::OnChange,
462        conform: Conform::MANDATORY,
463    },
464    Attribute {
465        id: 0x0002,
466        name: "PercentSetting",
467        kind: "percent",
468        access: Access::read_write_with(Privilege::View, Privilege::Operate),
469        qualities: AttributeQualities::NULLABLE,
470        reporting: Reporting::OnChange,
471        conform: Conform::MANDATORY,
472    },
473    Attribute {
474        id: 0x0003,
475        name: "PercentCurrent",
476        kind: "percent",
477        access: Access::read_only(Privilege::View),
478        qualities: AttributeQualities::empty(),
479        reporting: Reporting::OnChange,
480        conform: Conform::MANDATORY,
481    },
482    Attribute {
483        id: 0x0004,
484        name: "SpeedMax",
485        kind: "uint8",
486        access: Access::read_only(Privilege::View),
487        qualities: AttributeQualities::FIXED,
488        reporting: Reporting::OnChange,
489        conform: Conform {
490            clauses: &[Clause {
491                verdict: Conformance::Mandatory,
492                when: Condition::Feature(0),
493            }],
494        },
495    },
496    Attribute {
497        id: 0x0005,
498        name: "SpeedSetting",
499        kind: "uint8",
500        access: Access::read_write_with(Privilege::View, Privilege::Operate),
501        qualities: AttributeQualities::NULLABLE,
502        reporting: Reporting::OnChange,
503        conform: Conform {
504            clauses: &[Clause {
505                verdict: Conformance::Mandatory,
506                when: Condition::Feature(0),
507            }],
508        },
509    },
510    Attribute {
511        id: 0x0006,
512        name: "SpeedCurrent",
513        kind: "uint8",
514        access: Access::read_only(Privilege::View),
515        qualities: AttributeQualities::empty(),
516        reporting: Reporting::OnChange,
517        conform: Conform {
518            clauses: &[Clause {
519                verdict: Conformance::Mandatory,
520                when: Condition::Feature(0),
521            }],
522        },
523    },
524    Attribute {
525        id: 0x0007,
526        name: "RockSupport",
527        kind: "RockBitmap",
528        access: Access::read_only(Privilege::View),
529        qualities: AttributeQualities::FIXED,
530        reporting: Reporting::OnChange,
531        conform: Conform {
532            clauses: &[Clause {
533                verdict: Conformance::Mandatory,
534                when: Condition::Feature(2),
535            }],
536        },
537    },
538    Attribute {
539        id: 0x0008,
540        name: "RockSetting",
541        kind: "RockBitmap",
542        access: Access::read_write_with(Privilege::View, Privilege::Operate),
543        qualities: AttributeQualities::empty(),
544        reporting: Reporting::OnChange,
545        conform: Conform {
546            clauses: &[Clause {
547                verdict: Conformance::Mandatory,
548                when: Condition::Feature(2),
549            }],
550        },
551    },
552    Attribute {
553        id: 0x0009,
554        name: "WindSupport",
555        kind: "WindBitmap",
556        access: Access::read_only(Privilege::View),
557        qualities: AttributeQualities::FIXED,
558        reporting: Reporting::OnChange,
559        conform: Conform {
560            clauses: &[Clause {
561                verdict: Conformance::Mandatory,
562                when: Condition::Feature(3),
563            }],
564        },
565    },
566    Attribute {
567        id: 0x000A,
568        name: "WindSetting",
569        kind: "WindBitmap",
570        access: Access::read_write_with(Privilege::View, Privilege::Operate),
571        qualities: AttributeQualities::empty(),
572        reporting: Reporting::OnChange,
573        conform: Conform {
574            clauses: &[Clause {
575                verdict: Conformance::Mandatory,
576                when: Condition::Feature(3),
577            }],
578        },
579    },
580    Attribute {
581        id: 0x000B,
582        name: "AirflowDirection",
583        kind: "AirflowDirectionEnum",
584        access: Access::read_write_with(Privilege::View, Privilege::Operate),
585        qualities: AttributeQualities::empty(),
586        reporting: Reporting::OnChange,
587        conform: Conform {
588            clauses: &[Clause {
589                verdict: Conformance::Mandatory,
590                when: Condition::Feature(5),
591            }],
592        },
593    },
594];
595
596/// Every command, with its conformance.
597pub const COMMANDS: &[Command] = &[Command {
598    id: 0x00,
599    name: "Step",
600    to_server: true,
601    response: None,
602    access: Access::invoke(Privilege::Operate),
603    conform: Conform {
604        clauses: &[Clause {
605            verdict: Conformance::Mandatory,
606            when: Condition::Feature(4),
607        }],
608    },
609}];
610
611/// Every event, with its conformance.
612pub const EVENTS: &[Event] = &[];
613
614/// The whole cluster, as the specification defines it.
615pub const CLUSTER: Cluster = Cluster {
616    id: ID,
617    name: "Fan Control",
618    revision: REVISION,
619    pics: "FAN",
620    derived_from: None,
621    features: FEATURES,
622    attributes: ATTRIBUTES,
623    commands: COMMANDS,
624    events: EVENTS,
625};