huelib 0.4.0

Rust bindings for the Philips Hue API
Documentation

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