use serde::*;
#[derive(PartialEq)]
pub enum RequestType {
Get,
Post,
Put,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct LightState {
pub on: bool,
pub bri: u8,
pub hue: u32,
pub sat: u8,
pub effect: String,
pub xy: [f32; 2],
pub ct: u32,
pub alert: String,
pub colormode: String,
pub mode: String,
pub reachable: bool,
}
impl Default for LightState {
fn default() -> Self {
LightState {
on: false,
bri: 254,
hue: 8000,
sat: 140,
effect: "none".to_owned(),
xy: [0.0, 0.0],
ct: 366,
alert: "select".to_owned(),
colormode: "ct".to_owned(),
mode: "homeautomation".to_owned(),
reachable: true,
}
}
}
#[derive(Serialize, Deserialize, Debug)]
struct LightSwUpdate {
pub state: String,
pub lastinstall: String,
}
#[derive(Serialize, Deserialize, Debug)]
struct LightCapabilities {
pub certified: bool,
pub control: LightCapabilityControl,
pub streaming: LightStreamingCapabilities,
}
#[derive(Serialize, Deserialize, Debug)]
struct LightCT {
pub min: u32,
pub max: u32,
}
#[derive(Serialize, Deserialize, Debug)]
struct LightCapabilityControl {
pub mindimlevel: u64,
pub maxlumen: u64,
pub colorgamuttype: String,
pub colorgamut: [[f32; 2]; 3],
pub ct: LightCT,
}
#[derive(Serialize, Deserialize, Debug)]
struct LightStreamingCapabilities {
pub renderer: bool,
pub proxy: bool,
}
#[derive(Serialize, Deserialize, Debug)]
struct LightConfig {
pub archetype: String,
pub function: String,
pub direction: String,
pub startup: LightConfigStartup,
}
#[derive(Serialize, Deserialize, Debug)]
struct LightConfigStartup {
pub mode: String,
pub configured: bool,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Light {
pub state: LightState,
swupdate: LightSwUpdate,
pub r#type: String,
pub name: String,
pub modelid: String,
pub manufacturername: String,
pub productname: String,
capabilities: LightCapabilities,
config: LightConfig,
pub uniqueid: String,
pub swversion: String,
pub swconfigid: String,
pub productid: String,
}
impl std::fmt::Display for Light {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"
Name: {}
Is on: {:?}
Color: {:?}
",
self.name, self.state.on, self.state.xy
)
}
}
#[derive(Serialize, Deserialize, Debug)]
pub struct SendableState {
#[serde(skip_serializing_if = "Option::is_none")]
pub on: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bri: Option<u8>,
#[serde(skip_serializing_if = "Option::is_none")]
pub hue: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub sat: Option<u8>,
#[serde(skip_serializing_if = "Option::is_none")]
pub effect: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub xy: Option<[f32; 2]>,
#[serde(skip_serializing_if = "Option::is_none")]
pub alert: Option<String>,
}
impl Default for SendableState {
fn default() -> Self {
Self {
on: None,
bri: None,
hue: None,
sat: None,
effect: None,
xy: None,
alert: None,
}
}
}
#[macro_export]
macro_rules! state {
($($i:ident:$v:expr), *) => {
SendableState {
$($i: Some($v),) *
..SendableState::default()
}
};
}