Expand description
The bridge is the central access point of the lamps is a Hue setup, and also the central access point of this library.
Fields
ip: IpAddr
The IP-address of the bridge.
username: String
This is the username of the currently logged in user.
Implementations
sourceimpl Bridge
impl Bridge
sourcepub fn for_ip(ip: impl Into<IpAddr>) -> UnauthBridge
pub fn for_ip(ip: impl Into<IpAddr>) -> UnauthBridge
Create a bridge at this IP. If you know the IP-address, this is the fastest option. Note that this function does not validate whether a bridge is really present at the IP-address.
Example
let bridge = hueclient::Bridge::for_ip([192u8, 168, 0, 4]);
sourcepub fn discover() -> Option<UnauthBridge>
pub fn discover() -> Option<UnauthBridge>
Scans the current network for Bridges, and if there is at least one, returns the first one that was found.
Example
let maybe_bridge = hueclient::Bridge::discover();
sourcepub fn discover_required() -> UnauthBridge
pub fn discover_required() -> UnauthBridge
sourcepub fn with_user(self, username: impl Into<String>) -> Bridge
pub fn with_user(self, username: impl Into<String>) -> Bridge
Consumes the bidge and return a new one with a configured username.
Example
let bridge = hueclient::Bridge::for_ip([192u8, 168, 0, 4])
.with_user("rVV05G0i52vQMMLn6BK3dpr0F3uDiqtDjPLPK2uj");
sourcepub fn register_user(self, devicetype: &str) -> Result<Bridge>
pub fn register_user(self, devicetype: &str) -> Result<Bridge>
This function registers a new user at the provided brige, using devicetype
as an
identifier for that user. It returns an error if the button of the bridge was not pressed
shortly before running this function.
Example
let bridge = hueclient::Bridge::for_ip([192u8, 168, 0, 4])
.register_user("mylaptop")
.unwrap();
// now this username d can be stored and reused
println!("the password was {}", bridge.username);
sourcepub fn get_all_lights(&self) -> Result<Vec<IdentifiedLight>>
pub fn get_all_lights(&self) -> Result<Vec<IdentifiedLight>>
Returns a vector of all lights that are registered at this Bridge
, sorted by their id’s.
This function returns an error if bridge.username
is None
.
Example
let bridge = hueclient::Bridge::for_ip([192u8, 168, 0, 4])
.with_user("rVV05G0i52vQMMLn6BK3dpr0F3uDiqtDjPLPK2uj");
for light in &bridge.get_all_lights().unwrap() {
println!("{:?}", light);
}
sourcepub fn get_all_groups(&self) -> Result<Vec<IdentifiedGroup>>
pub fn get_all_groups(&self) -> Result<Vec<IdentifiedGroup>>
Returns a vector of all groups that are registered at this Bridge
, sorted by their id’s.
This function returns an error if bridge.username
is None
.
Example
let bridge = hueclient::Bridge::for_ip([192u8, 168, 0, 4])
.with_user("rVV05G0i52vQMMLn6BK3dpr0F3uDiqtDjPLPK2uj");
for group in &bridge.get_all_groups().unwrap() {
println!("{:?}", group);
}
sourcepub fn get_all_scenes(&self) -> Result<Vec<IdentifiedScene>>
pub fn get_all_scenes(&self) -> Result<Vec<IdentifiedScene>>
Returns a vector of all scenes that are registered at this Bridge
, sorted by their id’s.
This function returns an error if bridge.username
is None
.
Example
let bridge = hueclient::Bridge::for_ip([192u8, 168, 0, 4])
.with_user("rVV05G0i52vQMMLn6BK3dpr0F3uDiqtDjPLPK2uj");
for scene in &bridge.get_all_scenes().unwrap() {
println!("{:?}", scene);
}
pub fn set_scene(&self, scene: String) -> Result<Value>
pub fn set_group_state(
&self,
group: usize,
command: &CommandLight
) -> Result<Value>
pub fn set_light_state(
&self,
light: usize,
command: &CommandLight
) -> Result<Value>
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Bridge
impl Send for Bridge
impl Sync for Bridge
impl Unpin for Bridge
impl !UnwindSafe for Bridge
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more