use super::super::types::Capability;
use serde::{Deserialize, Serialize};
pub type IeeeAddr = u64;
pub type NwkAddr = u16;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct ZigbeeAddr {
pub ieee: IeeeAddr,
pub nwk: NwkAddr,
}
impl ZigbeeAddr {
pub fn new(ieee: IeeeAddr, nwk: NwkAddr) -> Self {
Self { ieee, nwk }
}
}
impl std::fmt::Display for ZigbeeAddr {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:016x} ({:#06x})", self.ieee, self.nwk)
}
}
#[allow(non_upper_case_globals)]
pub mod cluster_id {
pub const BASIC: u16 = 0x0000;
pub const POWER_CONFIG: u16 = 0x0001;
pub const IDENTIFY: u16 = 0x0003;
pub const GROUPS: u16 = 0x0004;
pub const SCENES: u16 = 0x0005;
pub const ON_OFF: u16 = 0x0006;
pub const ON_OFF_SWITCH_CONFIG: u16 = 0x0007;
pub const LEVEL_CONTROL: u16 = 0x0008;
pub const ALARMS: u16 = 0x0009;
pub const TIME: u16 = 0x000A;
pub const OTA_UPGRADE: u16 = 0x0019;
pub const DOOR_LOCK: u16 = 0x0101;
pub const WINDOW_COVERING: u16 = 0x0102;
pub const COLOR_CONTROL: u16 = 0x0300;
pub const ILLUMINANCE: u16 = 0x0400;
pub const TEMPERATURE: u16 = 0x0402;
pub const HUMIDITY: u16 = 0x0405;
pub const OCCUPANCY: u16 = 0x0406;
pub const IAS_ZONE: u16 = 0x0500;
pub const METERING: u16 = 0x0702;
pub const ELECTRICAL_MEASUREMENT: u16 = 0x0B04;
}
pub type ZigbeeClusterId = u16;
pub type ZigbeeAttrId = u16;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum ZigbeeDeviceKind {
Light,
DimmableLight,
ColorLight,
Switch,
TemperatureSensor,
HumiditySensor,
OccupancySensor,
DoorLock,
Thermostat,
PowerOutlet,
Other(u16),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ZigbeeDevice {
pub addr: ZigbeeAddr,
pub name: Option<String>,
pub manufacturer: Option<String>,
pub model: Option<String>,
pub kind: ZigbeeDeviceKind,
pub clusters: Vec<ZigbeeClusterId>,
pub capabilities: Vec<Capability>,
pub online: bool,
}
impl ZigbeeDevice {
pub fn new(addr: ZigbeeAddr, kind: ZigbeeDeviceKind) -> Self {
Self {
addr,
name: None,
manufacturer: None,
model: None,
kind,
clusters: Vec::new(),
capabilities: Vec::new(),
online: true,
}
}
}