#philips #hue #light

huelib

Rust bindings for the Philips Hue API

3 releases (breaking)

✓ Uses Rust 2018 edition

new 0.3.0 Mar 25, 2020
0.2.0 Mar 24, 2020
0.1.0 Mar 23, 2020

#63 in Hardware support

MIT license

87KB
2K SLoC

huelib-rs

Build Crate Docs License Code size Lines of code

Rust bindings for the Philips Hue API.

About

This library sends HTTP requests to the bridge using the ureq crate. The responses/requests are deserialized/serialized using the serde, serde_json and serde_repr crates.

Example

Register a user and set the brightness and saturation of a light.

use huelib::{bridge, light, Modifier};
use std::net::{IpAddr, Ipv4Addr};

let bridge_ip = IpAddr::V4(Ipv4Addr::new(192, 168, 1, 2));
let username = match bridge::register_user(bridge_ip, "huelib-rs example", false) {
    Ok(v) => v.name,
    Err(e) => {
        println!("Failed to register user: {}", e);
        return;
    }
};
let bridge = huelib::Bridge::new(bridge_ip, &username);
let state_modifier = light::StateModifier::new()
    .brightness(huelib::ModifierType::Increment, 40)
    .saturation(huelib::ModifierType::Override, 200);
match bridge.set_light_state("1", &state_modifier) {
    Ok(v) => {
        for response in v {
            println!("{}", response);
        }
    },
    Err(e) => {
        println!("Failed to set the state of the light: {}", e);
        return;
    }
};

Todo

  • Lights API
  • Groups API
  • Scenes API
  • Configuration API
  • Capabilities API
  • Schedules API
  • Rules API
  • Resourcelinks API
  • Sensors API

Dependencies

~4MB
~92K SLoC