set_light_state/
set_light_state.rs

1//! Modifies the state of a specific light.
2
3use huelib2::resource::{light, Adjust, Alert};
4use huelib2::{bridge, Bridge};
5
6fn main() {
7    // Discover bridges in the local network and save the first IP address as `bridge_ip`.
8    let bridge_ip = bridge::discover_nupnp().unwrap().pop().unwrap();
9
10    // Register a new user.
11    let username = bridge::register_user(bridge_ip, "huelib-rs example").unwrap();
12
13    // Create a new bridge.
14    let bridge = Bridge::new(bridge_ip, username);
15
16    // Creates a new light modifier to turn on the light, set the saturation to 10 and decrement
17    // the brightness by 40.
18    let light_modifier = light::StateModifier::new()
19        .with_on(true)
20        .with_saturation(Adjust::Override(10))
21        .with_alert(Alert::Select)
22        .with_brightness(Adjust::Decrement(40));
23
24    // Modify the attributes declared in `light_modifier` on the light with the id 1.
25    let response = bridge.set_light_state("1", &light_modifier).unwrap();
26    println!("{:?}", response);
27}