#philips #hue #light

huelib

Rust bindings for the Philips Hue API

9 releases (breaking)

✓ Uses Rust 2018 edition

new 0.8.0 Jun 28, 2020
0.6.1 May 25, 2020
0.3.0 Mar 25, 2020

#36 in Hardware support

Download history 52/week @ 2020-03-19 15/week @ 2020-03-26 10/week @ 2020-04-02 33/week @ 2020-04-09 29/week @ 2020-04-16 32/week @ 2020-04-23 10/week @ 2020-04-30 9/week @ 2020-05-07 2/week @ 2020-05-14 25/week @ 2020-05-21 24/week @ 2020-05-28 48/week @ 2020-06-04 5/week @ 2020-06-11 22/week @ 2020-06-18 31/week @ 2020-06-25

85 downloads per month
Used in 2 crates

MIT license

120KB
2.5K SLoC

huelib-rs

Build Crate Docs License Downloads

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.

Examples

Modifies the state of a light on a specific bridge:

use huelib::resource::{light, Modifier, ModifierType};
use huelib::Bridge;
use std::net::{IpAddr, Ipv4Addr};

// Create a bridge with IP address and username.
let bridge = Bridge::new(IpAddr::V4(Ipv4Addr::new(192, 168, 1, 2)), "username");

// Create a state modifier that increments the brightness by 40 and sets the saturation to 200.
let modifier = light::StateModifier::new()
    .brightness(ModifierType::Increment, 40)
    .saturation(ModifierType::Override, 200);

// Set attributes of the light with index '1' from the modifier and print the responses.
match bridge.set_light_state("1", &modifier) {
    Ok(v) => v.iter().for_each(|response| println!("{}", response)),
    Err(e) => eprintln!("Failed to modify the light state: {}", e),
};

Creates a group and registers a user on a discovered bridge:

use huelib::{bridge, resource::group, Bridge};

// Get the IP address of the bridge that was first discovered in the local network.
let ip_address = bridge::discover()
    .expect("Failed to discover bridges")
    .pop()
    .expect("No bridges found in the local network");

// Register a user on the discovered bridge.
let user = bridge::register_user(ip_address, "huelib-rs example", false)
    .expect("Failed to register user");

// Create a bridge with IP address and username.
let bridge = Bridge::new(ip_address, user.name);

// Create a group creator that sets the name to 'group1', adds the lights with the index '1'
// and '2' to the group and sets the class to 'Office'.
let creator = group::Creator::new("group1", ["1", "2"].to_vec()).class(group::Class::Office);

// Create the group and print the identifier of the new group.
match bridge.create_group(&creator) {
    Ok(v) => println!("Created group with id '{}'", v),
    Err(e) => eprintln!("Failed to create group: {}", e),
};

Dependencies

~4MB
~96K SLoC