#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Scale {
pub id: u8,
pub label: &'static str,
pub unit: &'static str,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SensorType {
pub id: u8,
pub name: &'static str,
pub label: &'static str,
pub scales: &'static [Scale],
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct MeterType {
pub id: u8,
pub name: &'static str,
pub label: &'static str,
pub scales: &'static [Scale],
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct NotificationType {
pub id: u8,
pub name: &'static str,
pub label: &'static str,
pub events: &'static [NotificationEvent],
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct NotificationEvent {
pub id: u8,
pub label: &'static str,
pub variable: &'static str,
pub idle: bool,
}
impl SensorType {
pub fn scale(&self, id: u8) -> Option<&'static Scale> {
self.scales.iter().find(|s| s.id == id)
}
}
impl MeterType {
pub fn scale(&self, id: u8) -> Option<&'static Scale> {
self.scales.iter().find(|s| s.id == id)
}
}
impl NotificationType {
pub fn event(&self, id: u8) -> Option<&'static NotificationEvent> {
self.events.iter().find(|e| e.id == id)
}
}
include!(concat!(env!("OUT_DIR"), "/tables.rs"));
pub fn sensor_type(id: u8) -> Option<&'static SensorType> {
SENSOR_TYPES
.binary_search_by_key(&id, |t| t.id)
.ok()
.map(|i| &SENSOR_TYPES[i])
}
pub fn meter_type(id: u8) -> Option<&'static MeterType> {
METER_TYPES
.binary_search_by_key(&id, |t| t.id)
.ok()
.map(|i| &METER_TYPES[i])
}
pub fn notification_type(id: u8) -> Option<&'static NotificationType> {
NOTIFICATION_TYPES
.binary_search_by_key(&id, |t| t.id)
.ok()
.map(|i| &NOTIFICATION_TYPES[i])
}