pub struct Bridge { /* private fields */ }
Expand description
A bridge with IP address and username.
Implementations§
Source§impl Bridge
impl Bridge
Sourcepub fn new<S>(ip_address: IpAddr, username: S) -> Self
pub fn new<S>(ip_address: IpAddr, username: S) -> Self
Creates a new bridge.
§Examples
Create a bridge with an already registered user:
use huelib::Bridge;
use std::net::{IpAddr, Ipv4Addr};
let ip = IpAddr::V4(Ipv4Addr::new(192, 168, 1, 2));
let bridge = Bridge::new(ip, "username");
Examples found in repository?
5fn main() {
6 // Discover bridges in the local network and save the first IP address as `bridge_ip`.
7 let bridge_ip = bridge::discover_nupnp().unwrap().pop().unwrap();
8
9 // Register a new user.
10 let username = bridge::register_user(bridge_ip, "huelib-rs example").unwrap();
11
12 // Create a new bridge.
13 let bridge = Bridge::new(bridge_ip, username);
14
15 // Print out every light that is connected to the bridge.
16 let lights = bridge.get_all_lights().unwrap();
17 println!("{:?}", lights);
18}
More examples
5fn main() {
6 // Discover bridges in the local network and save the first IP address as `bridge_ip`.
7 let bridge_ip = bridge::discover_nupnp().unwrap().pop().unwrap();
8
9 // Register a new user.
10 let username = bridge::register_user(bridge_ip, "huelib-rs example").unwrap();
11
12 // Create a new bridge.
13 let bridge = Bridge::new(bridge_ip, username);
14
15 // Deletes the light with the id 1.
16 match bridge.delete_light("1") {
17 Ok(_) => println!("Deleted light"),
18 Err(e) => println!("Failed to delete light: {}", e),
19 };
20}
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}
Sourcepub fn ip_address(&self) -> &IpAddr
pub fn ip_address(&self) -> &IpAddr
Returns the IP address of the bridge.
Sourcepub fn set_config(&self, modifier: &Modifier) -> Result<Vec<Response<Modified>>>
pub fn set_config(&self, modifier: &Modifier) -> Result<Vec<Response<Modified>>>
Modifies the configuration of the bridge.
Sourcepub fn get_config(&self) -> Result<Config>
pub fn get_config(&self) -> Result<Config>
Returns the configuration of the bridge.
Sourcepub fn set_light_attribute<S>(
&self,
id: S,
modifier: &AttributeModifier,
) -> Result<Vec<Response<Modified>>>
pub fn set_light_attribute<S>( &self, id: S, modifier: &AttributeModifier, ) -> Result<Vec<Response<Modified>>>
Modifies attributes of a light.
Sourcepub fn set_light_state<S>(
&self,
id: S,
modifier: &StateModifier,
) -> Result<Vec<Response<Modified>>>
pub fn set_light_state<S>( &self, id: S, modifier: &StateModifier, ) -> Result<Vec<Response<Modified>>>
Modifies the state of a light.
Examples found in repository?
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}
Sourcepub fn get_all_lights(&self) -> Result<Vec<Light>>
pub fn get_all_lights(&self) -> Result<Vec<Light>>
Returns all lights that are connected to the bridge.
Examples found in repository?
5fn main() {
6 // Discover bridges in the local network and save the first IP address as `bridge_ip`.
7 let bridge_ip = bridge::discover_nupnp().unwrap().pop().unwrap();
8
9 // Register a new user.
10 let username = bridge::register_user(bridge_ip, "huelib-rs example").unwrap();
11
12 // Create a new bridge.
13 let bridge = Bridge::new(bridge_ip, username);
14
15 // Print out every light that is connected to the bridge.
16 let lights = bridge.get_all_lights().unwrap();
17 println!("{:?}", lights);
18}
Sourcepub fn search_new_lights(&self, scanner: &Scanner) -> Result<()>
pub fn search_new_lights(&self, scanner: &Scanner) -> Result<()>
Starts searching for new lights.
The bridge will open the network for 40 seconds. The overall search might take longer since the configuration of new devices can take longer. If many devices are found the command will have to be issued a second time after discovery time has elapsed. If the command is received again during search the search will continue for at least an additional 40 seconds.
When the search has finished, new lights will be available using the get_new_lights
function.
Sourcepub fn get_new_lights(&self) -> Result<Scan>
pub fn get_new_lights(&self) -> Result<Scan>
Returns discovered lights.
Sourcepub fn delete_light<S>(&self, id: S) -> Result<()>
pub fn delete_light<S>(&self, id: S) -> Result<()>
Deletes a light from the bridge.
Examples found in repository?
5fn main() {
6 // Discover bridges in the local network and save the first IP address as `bridge_ip`.
7 let bridge_ip = bridge::discover_nupnp().unwrap().pop().unwrap();
8
9 // Register a new user.
10 let username = bridge::register_user(bridge_ip, "huelib-rs example").unwrap();
11
12 // Create a new bridge.
13 let bridge = Bridge::new(bridge_ip, username);
14
15 // Deletes the light with the id 1.
16 match bridge.delete_light("1") {
17 Ok(_) => println!("Deleted light"),
18 Err(e) => println!("Failed to delete light: {}", e),
19 };
20}
Sourcepub fn create_group(&self, creator: &Creator) -> Result<String>
pub fn create_group(&self, creator: &Creator) -> Result<String>
Creates a new group.
Sourcepub fn set_group_attribute<S>(
&self,
id: S,
modifier: &AttributeModifier,
) -> Result<Vec<Response<Modified>>>
pub fn set_group_attribute<S>( &self, id: S, modifier: &AttributeModifier, ) -> Result<Vec<Response<Modified>>>
Modifies attributes of a group.
Sourcepub fn set_group_state<S>(
&self,
id: S,
modifier: &StateModifier,
) -> Result<Vec<Response<Modified>>>
pub fn set_group_state<S>( &self, id: S, modifier: &StateModifier, ) -> Result<Vec<Response<Modified>>>
Modifies the state of a group.
Sourcepub fn get_all_groups(&self) -> Result<Vec<Group>>
pub fn get_all_groups(&self) -> Result<Vec<Group>>
Returns all groups.
Sourcepub fn delete_group<S>(&self, id: S) -> Result<()>
pub fn delete_group<S>(&self, id: S) -> Result<()>
Deletes a group from the bridge.
Sourcepub fn create_scene(&self, creator: &Creator) -> Result<String>
pub fn create_scene(&self, creator: &Creator) -> Result<String>
Creates a new scene.
Sourcepub fn set_scene<S>(
&self,
id: S,
modifier: &Modifier,
) -> Result<Vec<Response<Modified>>>
pub fn set_scene<S>( &self, id: S, modifier: &Modifier, ) -> Result<Vec<Response<Modified>>>
Modifies the state and attributes of a scene.
Sourcepub fn get_all_scenes(&self) -> Result<Vec<Scene>>
pub fn get_all_scenes(&self) -> Result<Vec<Scene>>
Returns all scenes.
Sourcepub fn get_capabilities(&self) -> Result<Capabilities>
pub fn get_capabilities(&self) -> Result<Capabilities>
Returns the capabilities of resources.
Sourcepub fn create_schedule(&self, creator: &Creator) -> Result<String>
pub fn create_schedule(&self, creator: &Creator) -> Result<String>
Creates a new schedule and returns the identifier.
Sourcepub fn set_schedule<S>(
&self,
id: S,
modifier: &Modifier,
) -> Result<Vec<Response<Modified>>>
pub fn set_schedule<S>( &self, id: S, modifier: &Modifier, ) -> Result<Vec<Response<Modified>>>
Modifies attributes of a schedule.
Sourcepub fn get_schedule<S>(&self, id: S) -> Result<Schedule>
pub fn get_schedule<S>(&self, id: S) -> Result<Schedule>
Returns a schedule.
Sourcepub fn get_all_schedules(&self) -> Result<Vec<Schedule>>
pub fn get_all_schedules(&self) -> Result<Vec<Schedule>>
Returns all schedules.
Sourcepub fn delete_schedule<S>(&self, id: S) -> Result<()>
pub fn delete_schedule<S>(&self, id: S) -> Result<()>
Deletes a schedule.
Sourcepub fn create_resourcelink(&self, creator: &Creator) -> Result<String>
pub fn create_resourcelink(&self, creator: &Creator) -> Result<String>
Creates a new resourcelink and returns the identifier.
Sourcepub fn set_resourcelink<S>(
&self,
id: S,
modifier: &Modifier,
) -> Result<Vec<Response<Modified>>>
pub fn set_resourcelink<S>( &self, id: S, modifier: &Modifier, ) -> Result<Vec<Response<Modified>>>
Modifies attributes of a resourcelink.
Sourcepub fn get_resourcelink<S>(&self, id: S) -> Result<Resourcelink>
pub fn get_resourcelink<S>(&self, id: S) -> Result<Resourcelink>
Returns a resourcelink.
Sourcepub fn get_all_resourcelinks(&self) -> Result<Vec<Resourcelink>>
pub fn get_all_resourcelinks(&self) -> Result<Vec<Resourcelink>>
Returns all resourcelinks.
Sourcepub fn delete_resourcelink<S>(&self, id: S) -> Result<()>
pub fn delete_resourcelink<S>(&self, id: S) -> Result<()>
Deletes a resourcelink.
Sourcepub fn set_sensor_attribute<S>(
&self,
id: S,
modifier: &AttributeModifier,
) -> Result<Vec<Response<Modified>>>
pub fn set_sensor_attribute<S>( &self, id: S, modifier: &AttributeModifier, ) -> Result<Vec<Response<Modified>>>
Modifies attributes of a sensor.
Sourcepub fn set_sensor_state<S>(
&self,
id: S,
modifier: &StateModifier,
) -> Result<Vec<Response<Modified>>>
pub fn set_sensor_state<S>( &self, id: S, modifier: &StateModifier, ) -> Result<Vec<Response<Modified>>>
Modifies the state of a sensor.
Sourcepub fn set_sensor_config<S>(
&self,
id: S,
modifier: &ConfigModifier,
) -> Result<Vec<Response<Modified>>>
pub fn set_sensor_config<S>( &self, id: S, modifier: &ConfigModifier, ) -> Result<Vec<Response<Modified>>>
Modifies the configuration of a sensor.
Sourcepub fn get_all_sensors(&self) -> Result<Vec<Sensor>>
pub fn get_all_sensors(&self) -> Result<Vec<Sensor>>
Returns all sensors that are connected to the bridge.
Sourcepub fn search_new_sensors(&self, scanner: &Scanner) -> Result<()>
pub fn search_new_sensors(&self, scanner: &Scanner) -> Result<()>
Starts searching for new sensors.
The bridge will open the network for 40 seconds. The overall search might take longer since the configuration of new devices can take longer. If many devices are found the command will have to be issued a second time after discovery time has elapsed. If the command is received again during search the search will continue for at least an additional 40 seconds.
When the search has finished, new sensors will be available using the get_new_sensors
function.
Sourcepub fn get_new_sensors(&self) -> Result<Scan>
pub fn get_new_sensors(&self) -> Result<Scan>
Returns discovered sensors.
Sourcepub fn delete_sensor<S>(&self, id: S) -> Result<()>
pub fn delete_sensor<S>(&self, id: S) -> Result<()>
Deletes a sensor from the bridge.
Sourcepub fn create_rule(&self, creator: &Creator) -> Result<String>
pub fn create_rule(&self, creator: &Creator) -> Result<String>
Creates a new rule.
Sourcepub fn set_rule<S>(
&self,
id: S,
modifier: &Modifier,
) -> Result<Vec<Response<Modified>>>
pub fn set_rule<S>( &self, id: S, modifier: &Modifier, ) -> Result<Vec<Response<Modified>>>
Modifies attributes of a rule.
Sourcepub fn get_all_rules(&self) -> Result<Vec<Rule>>
pub fn get_all_rules(&self) -> Result<Vec<Rule>>
Returns all rules.