[][src]Struct yeelight::Bulb

pub struct Bulb { /* fields omitted */ }

Bulb connection

Implementations

impl Bulb[src]

pub fn attach(stream: TcpStream) -> Result<Self, Box<dyn Error>>[src]

Attach to existing std::net::TcpStream.

Example

let stream = std::net::TcpStream::connect("192.168.1.204:55443")
    .expect("Connection failed");
let mut bulb = Bulb::attach(stream).unwrap();
bulb.toggle().await.unwrap();

pub fn attach_tokio(stream: TcpStream) -> Self[src]

Same as attach(stream: std::net::TcpStream) but for tokio::net::TcpStream;

pub async fn connect<'_>(
    addr: &'_ str,
    __arg1: u16
) -> Result<Self, Box<dyn Error>>
[src]

Connect to bulb at the specified address and port.

If port is 0, the default value (55443) is used.

Example

let my_bulb_ip = "192.168.1.204";
let mut bulb = Bulb::connect(my_bulb_ip, 55443).await
    .expect("Connection failed");
bulb.toggle().await.unwrap();

pub fn no_response(self) -> Self[src]

Do not wait for response from the bulb (all commands will return None)

Example

let my_bulb_ip = "192.168.1.204";
let mut bulb = Bulb::connect(my_bulb_ip, 55443).await
    .expect("Connection failed").no_response();
let response = bulb.toggle().await.unwrap(); // response will be `None`

pub fn get_response(self) -> Self[src]

pub async fn set_notify<'_>(&'_ mut self, chan: Sender<Notification>)[src]

pub async fn get_notify<'_>(&'_ mut self) -> Receiver<Notification>[src]

pub async fn start_music<'_, '_>(
    &'_ mut self,
    host: &'_ str,
    port: u16
) -> Result<Self, Box<dyn Error>>
[src]

Establishes a Music mode connection with bulb.

This method returns another Bulb object to send commands to the bulb in music mode. Note that all commands send to the bulb get no response and produce no notification message, so there is no way to know if the command was executed successfully by the bulb.

impl Bulb[src]

Messages

This are all the methods as by the yeelight API spec. They all take the parameters specified by the spec, build a message, send it to the bulb and wait for the response which is parsed into a Response.

Example

let mut bulb = Bulb::connect("192.168.1.204", 0).await.expect("Connection failed");
let response = bulb.set_power(Power::On, Effect::Smooth, 1000, Mode::Normal).await.unwrap();

match response {
    Some(vec) => {
        // In this case, the response should be ["ok"].
        for v in vec.iter() {
            println!("{}", v);
        }
    },
    None => eprintln!("This should not happen"),
}

pub async fn get_prop<'_, '_>(
    &'_ mut self,
    properties: &'_ Properties
) -> Result<Option<Response>, BulbError>
[src]

pub async fn set_power<'_>(
    &'_ mut self,
    power: Power,
    effect: Effect,
    duration: u64,
    mode: Mode
) -> Result<Option<Response>, BulbError>
[src]

pub async fn bg_set_power<'_>(
    &'_ mut self,
    power: Power,
    effect: Effect,
    duration: u64,
    mode: Mode
) -> Result<Option<Response>, BulbError>
[src]

pub async fn toggle<'_>(&'_ mut self) -> Result<Option<Response>, BulbError>[src]

pub async fn bg_toggle<'_>(&'_ mut self) -> Result<Option<Response>, BulbError>[src]

pub async fn dev_toggle<'_>(&'_ mut self) -> Result<Option<Response>, BulbError>[src]

pub async fn set_ct_abx<'_>(
    &'_ mut self,
    ct_value: u16,
    effect: Effect,
    duration: u64
) -> Result<Option<Response>, BulbError>
[src]

pub async fn bg_set_ct_abx<'_>(
    &'_ mut self,
    ct_value: u16,
    effect: Effect,
    duration: u64
) -> Result<Option<Response>, BulbError>
[src]

pub async fn set_rgb<'_>(
    &'_ mut self,
    rgb_value: u32,
    effect: Effect,
    duration: u64
) -> Result<Option<Response>, BulbError>
[src]

pub async fn bg_set_rgb<'_>(
    &'_ mut self,
    rgb_value: u32,
    effect: Effect,
    duration: u64
) -> Result<Option<Response>, BulbError>
[src]

pub async fn set_hsv<'_>(
    &'_ mut self,
    hue: u16,
    sat: u8,
    effect: Effect,
    duration: u64
) -> Result<Option<Response>, BulbError>
[src]

pub async fn bg_set_hsv<'_>(
    &'_ mut self,
    hue: u16,
    sat: u8,
    effect: Effect,
    duration: u64
) -> Result<Option<Response>, BulbError>
[src]

pub async fn set_bright<'_>(
    &'_ mut self,
    brightness: u8,
    effect: Effect,
    duration: u64
) -> Result<Option<Response>, BulbError>
[src]

pub async fn bg_set_bright<'_>(
    &'_ mut self,
    brightness: u8,
    effect: Effect,
    duration: u64
) -> Result<Option<Response>, BulbError>
[src]

pub async fn set_scene<'_>(
    &'_ mut self,
    class: Class,
    val1: u64,
    val2: u64,
    val3: u64
) -> Result<Option<Response>, BulbError>
[src]

pub async fn bg_set_scene<'_>(
    &'_ mut self,
    class: Class,
    val1: u64,
    val2: u64,
    val3: u64
) -> Result<Option<Response>, BulbError>
[src]

pub async fn start_cf<'_>(
    &'_ mut self,
    count: u8,
    action: CfAction,
    flow_expression: FlowExpresion
) -> Result<Option<Response>, BulbError>
[src]

pub async fn bg_start_cf<'_>(
    &'_ mut self,
    count: u8,
    action: CfAction,
    flow_expression: FlowExpresion
) -> Result<Option<Response>, BulbError>
[src]

pub async fn stop_cf<'_>(&'_ mut self) -> Result<Option<Response>, BulbError>[src]

pub async fn bg_stop_cf<'_>(&'_ mut self) -> Result<Option<Response>, BulbError>[src]

pub async fn set_adjust<'_>(
    &'_ mut self,
    action: AdjustAction,
    prop: Prop
) -> Result<Option<Response>, BulbError>
[src]

pub async fn bg_set_adjust<'_>(
    &'_ mut self,
    action: AdjustAction,
    prop: Prop
) -> Result<Option<Response>, BulbError>
[src]

pub async fn adjust_bright<'_>(
    &'_ mut self,
    percentage: i8,
    duration: u64
) -> Result<Option<Response>, BulbError>
[src]

pub async fn bg_adjust_bright<'_>(
    &'_ mut self,
    percentage: i8,
    duration: u64
) -> Result<Option<Response>, BulbError>
[src]

pub async fn adjust_ct<'_>(
    &'_ mut self,
    percentage: i8,
    duration: u64
) -> Result<Option<Response>, BulbError>
[src]

pub async fn bg_adjust_ct<'_>(
    &'_ mut self,
    percentage: i8,
    duration: u64
) -> Result<Option<Response>, BulbError>
[src]

pub async fn adjust_color<'_>(
    &'_ mut self,
    percentage: i8,
    duration: u64
) -> Result<Option<Response>, BulbError>
[src]

pub async fn bg_adjust_color<'_>(
    &'_ mut self,
    percentage: i8,
    duration: u64
) -> Result<Option<Response>, BulbError>
[src]

pub async fn set_default<'_>(
    &'_ mut self
) -> Result<Option<Response>, BulbError>
[src]

pub async fn bg_set_default<'_>(
    &'_ mut self
) -> Result<Option<Response>, BulbError>
[src]

pub async fn set_name<'_, '_>(
    &'_ mut self,
    name: &'_ str
) -> Result<Option<Response>, BulbError>
[src]

pub async fn set_music<'_, '_>(
    &'_ mut self,
    action: MusicAction,
    host: &'_ str,
    port: u16
) -> Result<Option<Response>, BulbError>
[src]

pub async fn cron_add<'_>(
    &'_ mut self,
    cron_type: CronType,
    value: u64
) -> Result<Option<Response>, BulbError>
[src]

pub async fn cron_del<'_>(
    &'_ mut self,
    cron_type: CronType
) -> Result<Option<Response>, BulbError>
[src]

pub async fn cron_get<'_>(
    &'_ mut self,
    _cron_type: CronType
) -> Result<Option<Response>, BulbError>
[src]

Auto Trait Implementations

impl !RefUnwindSafe for Bulb

impl Send for Bulb

impl Sync for Bulb

impl Unpin for Bulb

impl !UnwindSafe for Bulb

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.