Giter Club home page Giter Club logo

yeelib_rs's Introduction

yeelib_rs

Crates.io badge License

A Rust library for easy interfacing with Yeelight products, including LAN light discovery with multicast and SSDP, with intended implementation of all major parts of the Yeelight Third-party Control Protocol.

Getting started

Add the following to Cargo.toml:

yeelib_rs = "0.1.1"

Unless otherwise specified, methods to adjust the light's parameters have the method name and behavior exactly as specified in the above spec.

use std::time::Duration;
use std::thread::sleep;

use yeelib_rs::{YeeClient, Light, YeeError};
use yeelib_rs::fields::{PowerStatus, Transition};

fn main() -> Result<(), YeeError> {
    let client = YeeClient::new()?;
    let mut lights: Vec<Light> = client.find_lights(Duration::from_secs(1));

    for light in lights.iter_mut() {
        light.set_power(PowerStatus::On, Transition::sudden())?;
        sleep(Duration::from_secs(1));

        light.set_bright(50, Transition::sudden())?;
        sleep(Duration::from_secs(1));

        light.set_ct_abx(3500,
                         Transition::smooth(Duration::from_millis(400))
                             .unwrap())?;
        sleep(Duration::from_secs(2));

        light.toggle()?;
    }
}

See main.rs for some more examples.

Currently supported methods

set_ct_abx
set_rgb
set_hsv
set_bright
set_power
toggle
adjust_bright
adjust_ct

To do

  • Document every component
  • Flatten public exports
  • Finish implementation of the API
  • Improve test coverage
  • Handle API errors

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

yeelib_rs's People

Contributors

teppah avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

calibrae

yeelib_rs's Issues

Devices are not discovered on local network

I'm trying to run the below snippet

use std::time::Duration;
use yeelib_rs::{
    fields::{PowerStatus, Transition},
    YeeClient,
};

fn main() {
    let client = YeeClient::new().expect("init fail");
    let mut all_lights = client.find_lights(Duration::from_secs(10));

    println!("{:?}", all_lights);

    let light = all_lights.get_mut(0).expect("no light");

    match light.power() {
        PowerStatus::Off => light
            .set_power(PowerStatus::On, Transition::sudden())
            .and_then(|_| light.set_bright(50, Transition::sudden()))
            .and_then(|_| light.set_ct_abx(3500, Transition::sudden()))
            .expect("light on fail"),
        PowerStatus::On => light
            .set_power(PowerStatus::Off, Transition::sudden())
            .expect("light off fail"),
    };
}

here all_lights always comes back as empty. It used to work previously, and I have another android app that works over the local network and can find the devices

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.