1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//! Sysinfo for TP-Link HS220 dimmer switches.
//!
//! Detected when IOT.SMARTPLUGSWITCH + "Dimmer" in dev_name.
//! Brightness lives in sysinfo root (not light_state). brightness=0 is invalid
//! hardware — use set_relay_state to turn off instead.
//!
//! NOTE: not tested on live hardware.
use serde::Deserialize;
#[derive(Debug, Deserialize)]
pub struct Dimmer {
pub alias: String,
pub model: String,
pub hw_ver: String,
pub sw_ver: String,
pub rssi: i32,
pub relay_state: u8,
#[serde(default)]
pub brightness: u8,
pub feature: Option<String>,
}
impl Dimmer {
pub fn is_on(&self) -> bool {
self.relay_state == 1
}
}
pub fn parse(json: &serde_json::Value) -> Option<Dimmer> {
let sysinfo = json.pointer("/system/get_sysinfo")?;
// Structural guard: reject non-switch types (e.g. bulbs). The finer
// "Dimmer" vs plug/strip discrimination is detect_kind's responsibility.
if !crate::devices::is_plug_switch(sysinfo) {
return None;
}
serde_json::from_value(sysinfo.clone()).ok()
}