fauxmo package

Submodules

fauxmo.cli module

cli.py :: Argparse based CLI for fauxmo.

Provides console_script via argparse.

fauxmo.cli.cli() → None[source]

Parse command line options, provide entry point for console scripts.

fauxmo.fauxmo module

fauxmo.py :: Main server code for Fauxmo.

Emulates a Belkin Wemo for interaction with an Amazon Echo. See README.md at <https://github.com/n8henrie/fauxmo>.

fauxmo.fauxmo.main(config_path_str: str = None, verbosity: int = 20) → None[source]

Run the main fauxmo process.

Spawns a UDP server to handle the Echo’s UPnP / SSDP device discovery process as well as multiple TCP servers to respond to the Echo’s device setup requests and handle its process for turning devices on and off.

Parameters:
  • config_path_str – Path to config file. If not given will search for config.json in cwd, ~/.fauxmo/, and /etc/fauxmo/.
  • verbosity – Logging verbosity, defaults to 20

fauxmo.protocols module

protocols.py :: Provide asyncio protocols for UPnP and SSDP discovery.

class fauxmo.protocols.Fauxmo(name: str, plugin: fauxmo.plugins.FauxmoPlugin)[source]

Bases: asyncio.protocols.Protocol

Mimics a WeMo switch on the network.

Aysncio protocol intended for use with BaseEventLoop.create_server.

NEWLINE = '\r\n'
__init__(name: str, plugin: fauxmo.plugins.FauxmoPlugin) → None[source]

Initialize a Fauxmo device.

Parameters:
  • name – How you want to call the device, e.g. “bedroom light”
  • plugin – Fauxmo plugin
static add_http_headers(xml: str) → str[source]

Add HTTP headers to an XML body.

Parameters:xml – XML body that needs HTTP headers
connection_made(transport: asyncio.transports.BaseTransport) → None[source]

Accept an incoming TCP connection.

Parameters:transport – Passed in asyncio.Transport
data_received(data: bytes) → None[source]

Decode incoming data.

Parameters:data – Incoming message, either setup request or action request
handle_action(msg: str) → None[source]

Execute on, off, or get_state method of plugin.

Parameters:msg – Body of the Echo’s HTTP request to trigger an action
handle_event() → None[source]

Respond to request for eventservice.xml.

handle_metainfo() → None[source]

Respond to request for metadata.

handle_setup() → None[source]

Create a response to the Echo’s setup request.

class fauxmo.protocols.SSDPServer(devices: Iterable[dict] = None)[source]

Bases: asyncio.protocols.DatagramProtocol

UDP server that responds to the Echo’s SSDP / UPnP requests.

__init__(devices: Iterable[dict] = None) → None[source]

Initialize an SSDPServer instance.

Parameters:devices – Iterable of devices to advertise when the Echo’s SSDP search request is received.
add_device(name: str, ip_address: str, port: int) → None[source]

Keep track of a list of devices for logging and shutdown.

Parameters:
  • name – Device name
  • ip_address – IP address of device
  • port – Port of device
connection_lost(exc: Exception) → None[source]

Handle lost connections.

Parameters:exc – Exception type
connection_made(transport: asyncio.transports.BaseTransport) → None[source]

Set transport attribute to incoming transport.

Parameters:transport – Incoming asyncio.DatagramTransport
datagram_received(data: Union[bytes, str], addr: Tuple[str, int]) → None[source]

Check incoming UDP data for requests for Wemo devices.

Parameters:
  • data – Incoming data content
  • addr – Address sending data

Build and send an appropriate response to an SSDP search request.

Parameters:addr – Address sending search request

fauxmo.utils module

utils.py :: Holds utility functions for Fauxmo.

fauxmo.utils.get_local_ip(ip_address: str = None) → str[source]

Attempt to get the local network-connected IP address.

Parameters:ip_address – Either desired ip address or string or “auto”
Returns:Current IP address as string
fauxmo.utils.get_unused_port() → int[source]

Temporarily binds a socket to an unused system assigned port.

Returns:Port number
fauxmo.utils.make_serial(name: str) → str[source]

Create a persistent UUID from the device name.

Returns a suitable UUID derived from name. Should remain static for a given name.

Parameters:name – Friendly device name (e.g. “living room light”)
Returns:Persistent UUID as string
fauxmo.utils.make_udp_sock() → socket.socket[source]

Make a suitable udp socket to listen for device discovery requests.

I would love to get rid of this function and just use the built-in options to create_datagram_endpoint (e.g. allow_broadcast with appropriate local and remote addresses), but having no luck. Would be thrilled if someone can figure this out in a better way than this or <https://github.com/n8henrie/fauxmo/blob/c5419b3f61311e5386387e136d26dd8d4a55518c/src/fauxmo/protocols.py#L149>.

Returns:Socket suitable for responding to multicast requests
fauxmo.utils.module_from_file(modname: str, path_str: str) → module[source]

Load a module into modname from a file path.

Parameters:
  • modname – The desired module name
  • path_str – Path to the file
Returns:

Module read in from path_str

Module contents

fauxmo :: Emulated Belkin Wemo devices for use with the Amazon Echo.