use crate::light::{Command, Light, Status}; use lifxi::http::prelude::*; pub struct Lifx { client: Client, updates: crossbeam_channel::Sender, commands: crossbeam_channel::Receiver, } impl Lifx { pub fn new( secret: S, updates: crossbeam_channel::Sender, commands: crossbeam_channel::Receiver, ) -> Self { Lifx { client: Client::new(secret), updates, commands, } } pub fn find_lights(&self) -> Vec { self.client .select(Selector::All) .list() .send() .unwrap() .json() .unwrap() } fn set_power(&self, id: String, state: bool) -> Result<(), lifxi::http::Error> { self.client .select(Selector::Id(id)) .change_state() .power(state) .send() .and(Ok(())) } fn set_brightness(&self, id: String, brightness: f32) -> Result<(), lifxi::http::Error> { self.client .select(Selector::Id(id)) .change_state() .brightness(brightness) .send() .and(Ok(())) } }