Crates.io | lifx-rs |
lib.rs | lifx-rs |
version | 0.1.30 |
source | src |
created_at | 2022-02-02 19:55:39.287407 |
updated_at | 2023-05-10 17:32:00.814784 |
description | A synchronous + asynchronous library for communicating with the official LIFX-API and the unoffical offline API. |
homepage | |
repository | https://github.com/PixelCoda/lifx-rs |
max_upload_size | |
id | 525842 |
size | 242,611 |
A synchronous + asynchronous library for communicating with the official LIFX-API and the unoffical offline API.
Add the following line to your cargo.toml:
lifx-rs = "0.1.30"
Example:
extern crate lifx_rs as lifx;
fn main() {
let key = "xxx".to_string();
let mut api_endpoints: Vec<String> = Vec::new();
// Official API
api_endpoints.push(format!("https://api.lifx.com"));
// lifx-server-api (Un-Official)
api_endpoints.push(format!("http://localhost:8089"));
let config = lifx::LifxConfig{
access_token: key.clone(),
api_endpoints: api_endpoints
};
// Build an "OffState" to set
let mut off_state = lifx::State::new();
off_state.power = Some(format!("off"));
// Turn off all lights
lifx::Light::set_state_by_selector(config.clone(), format!("all"), off_state);
let all_lights = lifx::Light::list_all(config.clone());
match all_lights {
Ok(lights) => {
println!("{:?}",lights.clone());
let mut state = lifx::State::new();
state.power = Some(format!("on"));
state.brightness = Some(1.0);
for light in lights {
let results = light.set_state(config.clone(), state.clone());
println!("{:?}",results);
}
},
Err(e) => println!("{}",e)
}
}
Async Example:
extern crate lifx_rs as lifx;
#[tokio::main]
async fn main() {
let key = "xxx".to_string();
let mut api_endpoints: Vec<String> = Vec::new();
// Official API
api_endpoints.push(format!("https://api.lifx.com"));
// lifx-server-api (Un-Official)
api_endpoints.push(format!("http://localhost:8089"));
let config = lifx::LifxConfig{
access_token: key.clone(),
api_endpoints: api_endpoints
};
// Build "OffState" to set
let mut off_state = lifx::State::new();
off_state.power = Some(format!("off"));
// Turn off all lights
lifx::Light::async_set_state_by_selector(config.clone(), format!("all"), off_state).await;
}
Released under Apache 2.0 or MIT.