From 4cfa14c29dfeb96d33baf47a1cac61ca139733dd Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Tue, 9 Feb 2016 22:57:55 +0000 Subject: [PATCH] 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 --- homeassistant/components/switch/wemo.py | 19 ++++++++++++++++++- requirements_all.txt | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/switch/wemo.py b/homeassistant/components/switch/wemo.py index 1d569449ff7..43c325795c6 100644 --- a/homeassistant/components/switch/wemo.py +++ b/homeassistant/components/switch/wemo.py @@ -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. """ diff --git a/requirements_all.txt b/requirements_all.txt index 5ea5c6ec73f..1a032958157 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -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