[][src]Trait rustmo_server::virtual_device::VirtualDevice

pub trait VirtualDevice: Sync + Send + 'static {
    fn turn_on(&mut self) -> Result<VirtualDeviceState, VirtualDeviceError>;
fn turn_off(&mut self) -> Result<VirtualDeviceState, VirtualDeviceError>;
fn check_is_on(&mut self) -> Result<VirtualDeviceState, VirtualDeviceError>; }

The VirtualDevice trait allows implementors to create devices that can be exposed to Alexa via RustmoServer

Rustmo pretends that devices are a "plug", so they only have two states: On and Off.

Some implementation notes:

  1. Alexa will consider a device to be unresponsive if a request takes longer than 5 seconds.

  2. When Alexa changes the state ("Alexa, turn $device ON/OFF") via ::turn_on() or ::turn_off, it will then immediately check the state via ::check_is_on(). If that request doesn't match what you just told Alexa to do, it will consider the device to be malfunctioning.

  3. RustmoServer provides helper methods for wrapped devices so they can automatically poll to make sure the desired state matches reality, or to just blindly pretend that the state change worked.

  4. It's best to implement ::turn_on() and ::turn_off() to execute as quickly as possible and use one of the helper methods in RustmoServer to provide (slightly) more sophisticated status verification.

Required methods

fn turn_on(&mut self) -> Result<VirtualDeviceState, VirtualDeviceError>

turn the device on

fn turn_off(&mut self) -> Result<VirtualDeviceState, VirtualDeviceError>

turn the device off

fn check_is_on(&mut self) -> Result<VirtualDeviceState, VirtualDeviceError>

is the device on?

Loading content...

Implementors

Loading content...