Skip to main content

zwave_cc/
tables.rs

1//! The multilevel sensor, meter and notification types assigned by the
2//! Z-Wave Alliance, generated from `defs/tables/*.toml`.
3
4/// A scale (unit) of a sensor or meter type.
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub struct Scale {
7    /// Scale id.
8    pub id: u8,
9    /// Name.
10    pub label: &'static str,
11    /// Unit symbol (empty when unitless).
12    pub unit: &'static str,
13}
14
15/// A multilevel sensor type.
16#[derive(Debug, Clone, Copy, PartialEq, Eq)]
17pub struct SensorType {
18    /// Sensor type id.
19    pub id: u8,
20    /// Snake-case name, e.g. `air_temperature`.
21    pub name: &'static str,
22    /// Label.
23    pub label: &'static str,
24    /// Scales.
25    pub scales: &'static [Scale],
26}
27
28/// A meter type.
29#[derive(Debug, Clone, Copy, PartialEq, Eq)]
30pub struct MeterType {
31    /// Meter type id.
32    pub id: u8,
33    /// Snake-case name, e.g. `electric`.
34    pub name: &'static str,
35    /// Label.
36    pub label: &'static str,
37    /// Scales.
38    pub scales: &'static [Scale],
39}
40
41/// A notification type.
42#[derive(Debug, Clone, Copy, PartialEq, Eq)]
43pub struct NotificationType {
44    /// Notification type id.
45    pub id: u8,
46    /// Snake-case name, e.g. `home_security`.
47    pub name: &'static str,
48    /// Label.
49    pub label: &'static str,
50    /// Events and states.
51    pub events: &'static [NotificationEvent],
52}
53
54/// One notification event or state.
55#[derive(Debug, Clone, Copy, PartialEq, Eq)]
56pub struct NotificationEvent {
57    /// Event id.
58    pub id: u8,
59    /// Label.
60    pub label: &'static str,
61    /// The state variable this event sets (e.g. "Motion sensor status");
62    /// empty for one-shot events.
63    pub variable: &'static str,
64    /// Whether the variable returns to idle (event 0) on its own.
65    pub idle: bool,
66}
67
68impl SensorType {
69    /// A scale by id.
70    pub fn scale(&self, id: u8) -> Option<&'static Scale> {
71        self.scales.iter().find(|s| s.id == id)
72    }
73}
74
75impl MeterType {
76    /// A scale by id.
77    pub fn scale(&self, id: u8) -> Option<&'static Scale> {
78        self.scales.iter().find(|s| s.id == id)
79    }
80}
81
82impl NotificationType {
83    /// An event by id.
84    pub fn event(&self, id: u8) -> Option<&'static NotificationEvent> {
85        self.events.iter().find(|e| e.id == id)
86    }
87}
88
89include!(concat!(env!("OUT_DIR"), "/tables.rs"));
90
91/// A multilevel sensor type by id.
92pub fn sensor_type(id: u8) -> Option<&'static SensorType> {
93    SENSOR_TYPES
94        .binary_search_by_key(&id, |t| t.id)
95        .ok()
96        .map(|i| &SENSOR_TYPES[i])
97}
98
99/// A meter type by id.
100pub fn meter_type(id: u8) -> Option<&'static MeterType> {
101    METER_TYPES
102        .binary_search_by_key(&id, |t| t.id)
103        .ok()
104        .map(|i| &METER_TYPES[i])
105}
106
107/// A notification type by id.
108pub fn notification_type(id: u8) -> Option<&'static NotificationType> {
109    NOTIFICATION_TYPES
110        .binary_search_by_key(&id, |t| t.id)
111        .ok()
112        .map(|i| &NOTIFICATION_TYPES[i])
113}