Rust bindings for the [Philips Hue API].
This library sends HTTP requests to the bridge using the [ureq] crate. The responses/requests are deserialized/serialized using the [serde], [serdejson] and [serderepr] crates.
Modifies the state of a light on a specific bridge:
```rust,no_run 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.setlightstate("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:
```rust,no_run 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::registeruser(ipaddress, "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), }; ```