Support manually-defined WeMo devices
This is extremely useful if you want to support wemos that are on another subnet or across a VPN. It also lets you sidestep the discovery process, which is problematic for a lot of people and situations. In order for this to work, we need to bump the pywemo requirement to 0.3.10, which includes my changes to make this possible. WeMo devices can be manually configured by adding a static section to the config, like this: switch: platform: wemo static: - 192.168.100.5 - 192.168.100.6
This commit is contained in:
parent
4ce1a67c13
commit
4cfa14c29d
2 changed files with 19 additions and 2 deletions
|
@ -12,7 +12,7 @@ from homeassistant.components.switch import SwitchDevice
|
|||
from homeassistant.const import (
|
||||
STATE_ON, STATE_OFF, STATE_STANDBY, EVENT_HOMEASSISTANT_STOP)
|
||||
|
||||
REQUIREMENTS = ['pywemo==0.3.9']
|
||||
REQUIREMENTS = ['pywemo==0.3.10']
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
_WEMO_SUBSCRIPTION_REGISTRY = None
|
||||
|
@ -24,6 +24,17 @@ MAKER_SWITCH_MOMENTARY = "momentary"
|
|||
MAKER_SWITCH_TOGGLE = "toggle"
|
||||
|
||||
|
||||
def _find_manual_wemos(pywemo, static_config):
|
||||
for address in static_config:
|
||||
port = pywemo.ouimeaux_device.probe_wemo(address)
|
||||
if not port:
|
||||
_LOGGER.warning('Unable to probe wemo at %s', address)
|
||||
continue
|
||||
_LOGGER.info('Adding static wemo at %s:%i', address, port)
|
||||
url = 'http://%s:%i/setup.xml' % (address, port)
|
||||
yield pywemo.discovery.device_from_description(url, None)
|
||||
|
||||
|
||||
# pylint: disable=unused-argument, too-many-function-args
|
||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
""" Find and return WeMo switches. """
|
||||
|
@ -60,6 +71,12 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||
[WemoSwitch(switch) for switch in switches
|
||||
if isinstance(switch, pywemo.Switch)])
|
||||
|
||||
# Add manually-defined wemo devices
|
||||
if discovery_info is None and 'static' in config:
|
||||
add_devices_callback(
|
||||
[WemoSwitch(wemo)
|
||||
for wemo in _find_manual_wemos(pywemo, config['static'])])
|
||||
|
||||
|
||||
class WemoSwitch(SwitchDevice):
|
||||
""" Represents a WeMo switch. """
|
||||
|
|
|
@ -210,7 +210,7 @@ pyuserinput==0.1.9
|
|||
pyvera==0.2.8
|
||||
|
||||
# homeassistant.components.switch.wemo
|
||||
pywemo==0.3.9
|
||||
pywemo==0.3.10
|
||||
|
||||
# homeassistant.components.thermostat.radiotherm
|
||||
radiotherm==1.2
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue