Struct hueclient::Bridge

source ·
pub struct Bridge {
    pub ip: IpAddr,
    pub username: String,
    /* private fields */
}
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§

source§

impl Bridge

source

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]);
source

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();
source

pub fn discover_required() -> UnauthBridge

A convience wrapper around Bridge::disover, but panics if there is no bridge present.

Example
let brige = hueclient::Bridge::discover_required();
Panics

This function panics if there is no brige present.

source

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");
source

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);
source

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);
}
source

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);
}
source

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);
}
source

pub fn set_scene(&self, scene: String) -> Result<Value>

source

pub fn set_group_state( &self, group: usize, command: &CommandLight ) -> Result<Value>

source

pub fn set_light_state( &self, light: usize, command: &CommandLight ) -> Result<Value>

Trait Implementations§

source§

impl Debug for Bridge

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more