use crate::light::Light; use lifxi::http::prelude::*; pub struct Lifx { client: Client, } impl Lifx { pub fn new(secret: S) -> Self { Lifx { client: Client::new(secret), } } pub fn find_lights(&self) -> Vec { self.client .select(Selector::All) .list() .send() .unwrap() .json() .unwrap() } pub 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(())) } pub 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(())) } }