[−][src]Crate yeelight
This is crate provides rust Bindings for yeelight API.
It implements methods as listed in Yeelight_Inter-Operation_spec.pdf. To communicate with the bulbs you have to enable LAN mode in the yeelight app.
Currently the TCP connection to the bulb is maintained for the whole life
of the Bulb
object. This could cause a problem since the light bulbs
only support 4 simultaneous TCP connections.
This is a work in progress, the following features are still in the works:
- Allow creation of bulb that creates and closes connections for each message.
- Handle messages and responses asynchronously.
- Handle notification messages.
- Discover bulbs in LAN.
- Support for music mode.
Example
This example shows some methods and how to parse the responses. It turns on the bulb and changes the brightness following the collatz sequence (applied 10 times), waiting 1 second for each iteration. More examples are provided in the examples folder.
use std::{thread, time}; use yeelight::*; fn main() -> Result<(), Box<dyn std::error::Error>> { let mut bulb = Bulb::connect("192.168.1.204", 55443)?; // Turn on the bulb bulb.set_power(Power::On, Effect::Sudden, 0, Mode::Normal)?; let second = time::Duration::from_millis(1000); // Define vector with properties to query let props = Properties(vec![ Property::Bright ]); for _ in 1..10 { let response = bulb.get_prop(&props)?; let brightness = match response { Response::Result(result) => result[0].parse::<u32>().unwrap(), Response::Error(code, message) => { eprintln!("Error (code {}): {}", code, message); std::process::exit(code); } }; // Change brightness following collatz sequence let brightness = if brightness%2 == 0 { brightness/2 } else { brightness*3 + 1 }; // Make sure brightness is between 1 and 100. let brightness = (brightness%100 + 1) as u8; println!("Setting brightness to {}", brightness); // Change brightness smooth over 1 second let response = bulb.set_bright(brightness, Effect::Smooth, 1000)?; eprintln!("Response: {:?}", response); // Sleep for 1 second thread::sleep(second); } Ok(()) }
Structs
Bulb | Bulb connection |
FlowExpresion | FlowExpresion consisting of a series of |
FlowTuple | State Change used to build |
Properties | List of |
QuotedString |
Enums
AdjustAction | |
CfAction | |
Class | |
CronType | |
Effect | |
FlowMode | |
Mode | |
MusicAction | |
Power | |
Prop | |
Property | |
Response | Parsed response from the bulb. |