Skip to main content

matter_kit/clusters/generated/
meter_identification.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Meter Identification — cluster 0x0B06.
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//! Meter Identification (cluster `0x0B06`, revision 1).
10//!
11//! 5 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 = 0x0B06;
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 = "MTRID";
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    /// Supports information about power threshold
42    ///
43    /// Code `PWRTHLD`, bit 0.
44    pub const POWER_THRESHOLD: u32 = 1 << 0;
45}
46
47/// Every feature bit, with its conformance.
48pub const FEATURES: &[Feature] = &[Feature {
49    bit: 0,
50    code: "PWRTHLD",
51    name: "PowerThreshold",
52    conform: Conform::OPTIONAL,
53}];
54
55/// The attribute ids.
56pub mod attribute {
57    use crate::im::AttributeId;
58
59    /// `MeterType`.
60    pub const METER_TYPE: AttributeId = 0x00;
61    /// `PointOfDelivery`.
62    pub const POINT_OF_DELIVERY: AttributeId = 0x01;
63    /// `MeterSerialNumber`.
64    pub const METER_SERIAL_NUMBER: AttributeId = 0x02;
65    /// `ProtocolVersion`.
66    pub const PROTOCOL_VERSION: AttributeId = 0x03;
67    /// `PowerThreshold`.
68    pub const POWER_THRESHOLD: AttributeId = 0x04;
69}
70
71/// `MeterTypeEnum`.
72#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
73#[repr(u8)]
74pub enum MeterTypeEnum {
75    /// Utility Meter
76    Utility = 0,
77    /// Private Meter
78    Private = 1,
79    /// Generic Meter
80    Generic = 2,
81}
82
83impl MeterTypeEnum {
84    /// Reads a wire value, or `None` for one this revision does not define.
85    #[must_use]
86    pub const fn from_value(value: u8) -> Option<Self> {
87        match value {
88            0 => Some(Self::Utility),
89            1 => Some(Self::Private),
90            2 => Some(Self::Generic),
91            _ => None,
92        }
93    }
94
95    /// Its wire value.
96    #[must_use]
97    pub const fn value(self) -> u8 {
98        self as u8
99    }
100}
101
102impl ToTlv for MeterTypeEnum {
103    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
104        self.value().to_tlv(w, tag)
105    }
106}
107
108impl<'a> FromTlv<'a> for MeterTypeEnum {
109    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
110        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
111        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
112    }
113}
114
115/// Every attribute the specification defines, with its conformance.
116pub const ATTRIBUTES: &[Attribute] = &[
117    Attribute {
118        id: 0x0000,
119        name: "MeterType",
120        kind: "MeterTypeEnum",
121        access: Access::read_only(Privilege::View),
122        qualities: AttributeQualities::NULLABLE,
123        reporting: Reporting::OnChange,
124        conform: Conform::MANDATORY,
125    },
126    Attribute {
127        id: 0x0001,
128        name: "PointOfDelivery",
129        kind: "string",
130        access: Access::read_only(Privilege::View),
131        qualities: AttributeQualities::NULLABLE,
132        reporting: Reporting::OnChange,
133        conform: Conform::MANDATORY,
134    },
135    Attribute {
136        id: 0x0002,
137        name: "MeterSerialNumber",
138        kind: "string",
139        access: Access::read_only(Privilege::View),
140        qualities: AttributeQualities::NULLABLE,
141        reporting: Reporting::OnChange,
142        conform: Conform::MANDATORY,
143    },
144    Attribute {
145        id: 0x0003,
146        name: "ProtocolVersion",
147        kind: "string",
148        access: Access::read_only(Privilege::View),
149        qualities: AttributeQualities::NULLABLE,
150        reporting: Reporting::OnChange,
151        conform: Conform::OPTIONAL,
152    },
153    Attribute {
154        id: 0x0004,
155        name: "PowerThreshold",
156        kind: "PowerThresholdStruct",
157        access: Access::read_only(Privilege::View),
158        qualities: AttributeQualities::NULLABLE,
159        reporting: Reporting::OnChange,
160        conform: Conform {
161            clauses: &[Clause {
162                verdict: Conformance::Mandatory,
163                when: Condition::Feature(0),
164            }],
165        },
166    },
167];
168
169/// Every command, with its conformance.
170pub const COMMANDS: &[Command] = &[];
171
172/// Every event, with its conformance.
173pub const EVENTS: &[Event] = &[];
174
175/// The whole cluster, as the specification defines it.
176pub const CLUSTER: Cluster = Cluster {
177    id: ID,
178    name: "Meter Identification",
179    revision: REVISION,
180    pics: "MTRID",
181    derived_from: None,
182    features: FEATURES,
183    attributes: ATTRIBUTES,
184    commands: COMMANDS,
185    events: EVENTS,
186};