Skip to main content

matter_kit/clusters/generated/
commodity_metering.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Commodity Metering — cluster 0x0B07.
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//! Commodity Metering (cluster `0x0B07`, revision 1).
10//!
11//! 4 identifiers, 0 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 = 0x0B07;
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 = "COMMTR";
35
36/// This cluster defines no features, so its `FeatureMap` is always zero.
37pub const FEATURES: &[Feature] = &[];
38
39/// The attribute ids.
40pub mod attribute {
41    use crate::im::AttributeId;
42
43    /// `MeteredQuantity`.
44    pub const METERED_QUANTITY: AttributeId = 0x00;
45    /// `MeteredQuantityTimestamp`.
46    pub const METERED_QUANTITY_TIMESTAMP: AttributeId = 0x01;
47    /// `TariffUnit`.
48    pub const TARIFF_UNIT: AttributeId = 0x02;
49    /// `MaximumMeteredQuantities`.
50    pub const MAXIMUM_METERED_QUANTITIES: AttributeId = 0x03;
51}
52
53/// `MeteredQuantityStruct`.
54#[derive(Debug, Clone, Copy, PartialEq)]
55pub struct MeteredQuantityStruct<'a> {
56    /// `TariffComponentIDs`, field 0.
57    pub tariff_component_i_ds: TlvList<'a, u32>,
58    /// `Quantity`, field 1.
59    pub quantity: i64,
60}
61
62impl<'a> ToTlv for MeteredQuantityStruct<'a> {
63    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
64        w.start_structure(tag)?;
65        self.tariff_component_i_ds.to_tlv(w, Tag::Context(0))?;
66        self.quantity.to_tlv(w, Tag::Context(1))?;
67        w.end_container()
68    }
69}
70
71impl<'a> FromTlv<'a> for MeteredQuantityStruct<'a> {
72    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
73        if element.value.container() != Some(ContainerKind::Structure) {
74            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
75        }
76        let mut tariff_component_i_ds = None;
77        let mut quantity = None;
78        loop {
79            let Some(field) = reader.next_element()? else {
80                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
81            };
82            if field.value == Value::EndOfContainer {
83                break;
84            }
85            match field.tag.context() {
86                Some(0) => {
87                    tariff_component_i_ds = Some(<TlvList<'a, u32>>::from_tlv(reader, &field)?)
88                }
89                Some(1) => quantity = Some(<i64>::from_tlv(reader, &field)?),
90                // A field this revision does not define. §7.19.2: a receiver
91                // ignores what it does not know rather than refusing the whole
92                // structure, which is what lets a newer peer talk to an older one.
93                _ => reader.skip_value(&field)?,
94            }
95        }
96        Ok(Self {
97            tariff_component_i_ds: tariff_component_i_ds
98                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
99            quantity: quantity.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
100        })
101    }
102}
103
104/// Every attribute the specification defines, with its conformance.
105pub const ATTRIBUTES: &[Attribute] = &[
106    Attribute {
107        id: 0x0000,
108        name: "MeteredQuantity",
109        kind: "list[MeteredQuantityStruct]",
110        access: Access::read_only(Privilege::View),
111        qualities: AttributeQualities::NULLABLE,
112        reporting: Reporting::OnChange,
113        conform: Conform::MANDATORY,
114    },
115    Attribute {
116        id: 0x0001,
117        name: "MeteredQuantityTimestamp",
118        kind: "epoch-s",
119        access: Access::read_only(Privilege::View),
120        qualities: AttributeQualities::NULLABLE,
121        reporting: Reporting::OnChange,
122        conform: Conform::MANDATORY,
123    },
124    Attribute {
125        id: 0x0002,
126        name: "TariffUnit",
127        kind: "TariffUnitEnum",
128        access: Access::read_only(Privilege::View),
129        qualities: AttributeQualities::NULLABLE,
130        reporting: Reporting::OnChange,
131        conform: Conform::MANDATORY,
132    },
133    Attribute {
134        id: 0x0003,
135        name: "MaximumMeteredQuantities",
136        kind: "uint16",
137        access: Access::read_only(Privilege::View),
138        qualities: AttributeQualities::NULLABLE,
139        reporting: Reporting::OnChange,
140        conform: Conform::MANDATORY,
141    },
142];
143
144/// Every command, with its conformance.
145pub const COMMANDS: &[Command] = &[];
146
147/// Every event, with its conformance.
148pub const EVENTS: &[Event] = &[];
149
150/// The whole cluster, as the specification defines it.
151pub const CLUSTER: Cluster = Cluster {
152    id: ID,
153    name: "Commodity Metering",
154    revision: REVISION,
155    pics: "COMMTR",
156    derived_from: None,
157    features: FEATURES,
158    attributes: ATTRIBUTES,
159    commands: COMMANDS,
160    events: EVENTS,
161};