[−][src]Trait rustmo_server::virtual_device::VirtualDevice
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:
-
Alexa will consider a device to be unresponsive if a request takes longer than 5 seconds.
-
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. -
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. -
It's best to implement
::turn_on()
and::turn_off()
to execute as quickly as possible and use one of the helper methods inRustmoServer
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?