use std::collections::BTreeMap; use lighter_lib::{BulbColor, BulbId, BulbMode}; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug, Clone)] #[non_exhaustive] pub enum ServerMessage { InfoPage { html: String, }, /// Update the state of a bulb BulbState { id: BulbId, mode: BulbMode, prefs: BTreeMap, }, BulbMap(BulbMap), } #[derive(Serialize, Deserialize, Debug, Clone)] #[non_exhaustive] pub enum ClientMessage { //SubscribeToInfo, //SubscribeToBulbs, GetBulbs, SetBulbColor { id: BulbId, color: BulbColor, }, SetBulbPower { id: BulbId, power: bool, }, SetBulbPref { bulb: BulbId, script: ScriptId, name: String, value: Param, }, } /// A geometric description of rooms/groups of light bulbs #[derive(Default, Deserialize, Serialize, Debug, Clone)] pub struct BulbMap { pub groups: Vec, } #[derive(Deserialize, Serialize, Debug, Clone)] pub struct BulbGroup { pub name: String, pub bulbs: Vec, pub x: u32, pub y: u32, pub shape: BulbGroupShape, } #[derive(Deserialize, Serialize, Debug, Clone, Copy)] pub enum BulbGroupShape { Circle { r: u32 }, Rectangle { w: u32, h: u32 }, } impl BulbGroupShape { pub fn height(&self) -> u32 { match *self { Self::Circle { r } => r, Self::Rectangle { h, .. } => h, } } pub fn width(&self) -> u32 { match *self { Self::Circle { r } => r, Self::Rectangle { w, .. } => w, } } } pub type ScriptId = String; #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum Param { String(String), Toggle(bool), } #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] pub struct BulbPrefs { pub kvs: BTreeMap, }