Crate yeelib_rs

Source
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 Lights 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§

pub use crate::err::YeeError;
pub use crate::light::Light;

Modules§

err
fields
light
req
fsadqqqqqqqqqq

Structs§

YeeClient
Find YeeLight IoT lights on the local network and initialize corresponding Lights.

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.