Expand description
This library provides an interface to find and interact with Yeelight IoT smart lights present on the local network.
It aims to be fully compliant with parts of the Yeelight Third-party Control Protocol. Every method name and field name used in this library is named the same as, and behave exactly as the spec describes.
§Usage
To find existing lights on the local network, use YeeClient
.
After obtaining a vector of Light
s found, change their states with methods as named in the spec.
use yeelib_rs::{YeeClient, Light};
use std::time::Duration;
use yeelib_rs::req::Transition;
use yeelib_rs::fields::PowerStatus;
use std::thread::sleep;
use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
let client = YeeClient::new()?;
let mut lights: Vec<Light> = client.find_lights(Duration::from_millis(500));
// turn the lights on with smooth 500ms transition
for light in lights.iter_mut() {
light.set_power(PowerStatus::On, Transition::smooth(Duration::from_millis(500)).unwrap())?;
}
// let the lights finish changing
sleep(Duration::from_secs(1));
// set the color-temperature to 3500 with instant transition
for light in lights.iter_mut() {
light.set_ct_abx(3500, Transition::sudden())?;
}
sleep(Duration::from_secs(1));
// set the brightness to full with instant transition
for light in lights.iter_mut() {
light.set_bright(100, Transition::sudden())?;
}
// toggle the power state
for light in lights.iter_mut() {
light.toggle()?;
}
Ok(())
}
Re-exports§
Modules§
Structs§
Constants§
- ALL_
LOCAL - Address to listen on all interfaces: 0.0.0.0
- DEFAULT_
LOCAL_ PORT - Default port for
YeeClient
. - MULTICAST_
ADDR - Multicast IPv4 address that Yeelight products listen on for discovery.
- MULTICAST_
PORT - Multicast port that Yeelight products listen on for discovery.
- SEARCH_
MSG - Message that is broadcasted to
MULTICAST_ADDR
.