1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub struct Scale {
7 pub id: u8,
9 pub label: &'static str,
11 pub unit: &'static str,
13}
14
15#[derive(Debug, Clone, Copy, PartialEq, Eq)]
17pub struct SensorType {
18 pub id: u8,
20 pub name: &'static str,
22 pub label: &'static str,
24 pub scales: &'static [Scale],
26}
27
28#[derive(Debug, Clone, Copy, PartialEq, Eq)]
30pub struct MeterType {
31 pub id: u8,
33 pub name: &'static str,
35 pub label: &'static str,
37 pub scales: &'static [Scale],
39}
40
41#[derive(Debug, Clone, Copy, PartialEq, Eq)]
43pub struct NotificationType {
44 pub id: u8,
46 pub name: &'static str,
48 pub label: &'static str,
50 pub events: &'static [NotificationEvent],
52}
53
54#[derive(Debug, Clone, Copy, PartialEq, Eq)]
56pub struct NotificationEvent {
57 pub id: u8,
59 pub label: &'static str,
61 pub variable: &'static str,
64 pub idle: bool,
66}
67
68impl SensorType {
69 pub fn scale(&self, id: u8) -> Option<&'static Scale> {
71 self.scales.iter().find(|s| s.id == id)
72 }
73}
74
75impl MeterType {
76 pub fn scale(&self, id: u8) -> Option<&'static Scale> {
78 self.scales.iter().find(|s| s.id == id)
79 }
80}
81
82impl NotificationType {
83 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
91pub 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
99pub 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
107pub 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}