pub struct RustmoServer { /* private fields */ }
Expand description
Create a RustmoServer
and add devices to make them discoverable, and controllable via Alexa.
Each VirtualDevice
you wish to expose requires a backing HTTP server (Rustmo takes care of
this for you). This is the reason why the various ::add_xxx_device()
methods require a port
number.
Note that each device must be assigned a unique port
number.
RustmoServer
also creates a multicast UDP socket listener to implement the SSDP-based device
discovery protocol required by Alexa – this listens on port 1900.
Implementations§
Source§impl RustmoServer
impl RustmoServer
Sourcepub fn new(interface: Ipv4Addr) -> Self
pub fn new(interface: Ipv4Addr) -> Self
Create a new RustmoServer
and listen for SSDP requests on the specified network interface
Sourcepub fn add_device<T: VirtualDevice>(
&mut self,
name: &str,
port: u16,
virtual_device: T,
) -> Result<WrappedVirtualDevice, RustmoError>
pub fn add_device<T: VirtualDevice>( &mut self, name: &str, port: u16, virtual_device: T, ) -> Result<WrappedVirtualDevice, RustmoError>
Add a VirtualDevice
to make it discoverable and controllable.
@name
: The word or phrase you’ll use when talking to Alexa to control this device
@port
: The port on which the backing HTTP server will listen for UPNP requests
@virtual_device
: A VirtualDevice
implementation
Sourcepub fn add_polling_device<T: VirtualDevice>(
&mut self,
name: &str,
port: u16,
virtual_device: T,
) -> Result<WrappedVirtualDevice, RustmoError>
pub fn add_polling_device<T: VirtualDevice>( &mut self, name: &str, port: u16, virtual_device: T, ) -> Result<WrappedVirtualDevice, RustmoError>
Add a VirtualDevice
to make it discoverable and controllable.
This version wraps the provided VirtualDevice
such that it will poll (via
::check_is_on()
), up to 4 seconds, whenever ::turn_on()
or ::turn_off()
is called.
This form is useful when controlling a physical device that takes a few seconds (but less than 5) for its state to register as changed.
@name
: The word or phrase you’ll use when talking to Alexa to control this device
@port
: The port on which the backing HTTP server will listen for UPNP requests
@virtual_device
: A VirtualDevice
implementation
Sourcepub fn add_instant_on_device<T: VirtualDevice>(
&mut self,
name: &str,
port: u16,
virtual_device: T,
) -> Result<WrappedVirtualDevice, RustmoError>
pub fn add_instant_on_device<T: VirtualDevice>( &mut self, name: &str, port: u16, virtual_device: T, ) -> Result<WrappedVirtualDevice, RustmoError>
Add a VirtualDevice
to make it discoverable and controllable.
This version wraps the provided VirtualDevice
and pretends that the ::turn_on()
and
::turn_off()
calls happen immediately.
This form is useful when controlling a physical device that takes more than 5 seconds for its state to register as changed but is otherwise “guaranteed” to eventually happen.
The implementation detail here is that calls to ::check_is_on()
will lie and return “ON”
after a call to ::turn_on()
until your underlying implementation for ::check_is_on()
actually does return “ON”.
@name
: The word or phrase you’ll use when talking to Alexa to control this device
@port
: The port on which the backing HTTP server will listen for UPNP requests
@virtual_device
: A VirtualDevice
implementation
Sourcepub fn add_functional_device<TurnOn, TurnOff, CheckIsOn>(
&mut self,
name: &str,
port: u16,
turn_on: TurnOn,
turn_off: TurnOff,
check_is_on: CheckIsOn,
) -> Result<WrappedVirtualDevice, RustmoError>where
TurnOn: FnMut() -> Result<VirtualDeviceState, VirtualDeviceError> + Sync + Send + 'static,
TurnOff: FnMut() -> Result<VirtualDeviceState, VirtualDeviceError> + Sync + Send + 'static,
CheckIsOn: FnMut() -> Result<VirtualDeviceState, VirtualDeviceError> + Sync + Send + 'static,
pub fn add_functional_device<TurnOn, TurnOff, CheckIsOn>(
&mut self,
name: &str,
port: u16,
turn_on: TurnOn,
turn_off: TurnOff,
check_is_on: CheckIsOn,
) -> Result<WrappedVirtualDevice, RustmoError>where
TurnOn: FnMut() -> Result<VirtualDeviceState, VirtualDeviceError> + Sync + Send + 'static,
TurnOff: FnMut() -> Result<VirtualDeviceState, VirtualDeviceError> + Sync + Send + 'static,
CheckIsOn: FnMut() -> Result<VirtualDeviceState, VirtualDeviceError> + Sync + Send + 'static,
Add an anonymous device to make it discoverable and controllable.
This version allows for the anonymous implementation of a device.
@name
: The word or phrase you’ll use when talking to Alexa to control this device
@port
: The port on which the backing HTTP server will listen for UPNP requests
@turn_on:
A closure that knows how to turn the device on
@turn_off:
A closure that knows how to turn the device off
@check_is_on:
A closure that knows how to determine if the device is on or off
Sourcepub fn add_device_group(
&mut self,
name: &str,
port: u16,
devices: Vec<WrappedVirtualDevice>,
) -> Result<WrappedVirtualDevice, RustmoError>
pub fn add_device_group( &mut self, name: &str, port: u16, devices: Vec<WrappedVirtualDevice>, ) -> Result<WrappedVirtualDevice, RustmoError>
Add a device that is a composite of multiple other devices.
This is useful if you wish to create a “Living Room Lights” device (“Alexa, turn on Living Roomt Lights”), that necessitates controlling multiple other devices that you’ve already added because they can also be controlled independently.
Note that communication with the list of devices in a device group happens in parallel, so make sure you don’t have any kind of state dependencies between devices.
An example of this might be turning a receiver on (one device) and changing its input to “DVD”. The receiver would need to be guaranteed “on” before its input source can be changed and this function does not guarantee that.
@name
: The word or phrase you’ll use when talking to Alexa to control this device
@port
: The port on which the backing HTTP server will listen for UPNP requests
@devices
: A vector of WrappedVirtualDevice
instances that have previously been added
to this RustmoServer
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RustmoServer
impl RefUnwindSafe for RustmoServer
impl Send for RustmoServer
impl Sync for RustmoServer
impl Unpin for RustmoServer
impl UnwindSafe for RustmoServer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more