From f4c77c85bdda261abf04ea1a87bfc7df739234a7 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Thu, 17 Apr 2014 21:57:01 -0700 Subject: [PATCH] Now using PyWemo instead of Ouimeaux to control WeMo --- README.md | 2 +- homeassistant/components/wemo.py | 28 ++++++++++------------------ homeassistant/external/pywemo | 1 + 3 files changed, 12 insertions(+), 19 deletions(-) create mode 160000 homeassistant/external/pywemo diff --git a/README.md b/README.md index e28a155f866..5ae5de1cf84 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ The system is built modular so support for other devices or actions can be imple Installation instructions ------------------------- -* The core depends on [PyEphem](http://rhodesmill.org/pyephem/) and [Requests](http://python-requests.org). Depending on the components you would like to use you will need [PHue](https://github.com/studioimaginaire/phue) for Philips Hue support, [PyChromecast](https://github.com/balloob/pychromecast) for Chromecast support and [ouimeaux](https://github.com/iancmcc/ouimeaux) for WeMo support. Install these using `pip install pyephem requests phue ouimeaux pychromecast`. +* The core depends on [PyEphem](http://rhodesmill.org/pyephem/) and [Requests](http://python-requests.org). Depending on the components you would like to use you will need [PHue](https://github.com/studioimaginaire/phue) for Philips Hue support and [PyChromecast](https://github.com/balloob/pychromecast) for Chromecast support. Install these using `pip install pyephem requests phue pychromecast`. * Clone the repository and pull in the submodules `git clone --recursive https://github.com/balloob/home-assistant.git` * Copy home-assistant.conf.default to home-assistant.conf and adjust the config values to match your setup. * For Tomato you will have to not only setup your host, username and password but also a http_id. The http_id can be retrieved by going to the admin console of your router, view the source of any of the pages and search for `http_id`. diff --git a/homeassistant/components/wemo.py b/homeassistant/components/wemo.py index 51e2b49ff29..914d48cb8e2 100644 --- a/homeassistant/components/wemo.py +++ b/homeassistant/components/wemo.py @@ -54,28 +54,20 @@ def setup(bus, statemachine): logger = logging.getLogger(__name__) try: - import ouimeaux.environment as wemo_env - import ouimeaux.device.switch as wemo_switch - import ouimeaux.device.insight as wemo_insight + import homeassistant.external.pywemo.pywemo as pywemo except ImportError: - logger.exception(("Failed to import ouimeaux. " - "Did you maybe not install the 'ouimeaux' " - "dependency?")) + pass return False - env = wemo_env.Environment() + logger.info("Scanning for WeMo devices") + devices = pywemo.discover_devices() - try: - env.start() - except socket.error: - # If the socket is already in use - logger.exception("Error starting WeMo environment") - return False + is_switch = lambda switch: isinstance(switch, pywemo.Switch) - env.discover(5) + switches = [device for device in devices if is_switch(device)] - if len(env.list_switches()) == 0: + if len(switches) == 0: logger.error("No WeMo switches found") return False @@ -88,7 +80,7 @@ def setup(bus, statemachine): """ Update the state of specified WeMo device. """ # We currently only support switches - if not isinstance(device, wemo_switch.Switch): + if not is_switch(device): return try: @@ -107,7 +99,7 @@ def setup(bus, statemachine): state_attr = {ATTR_FRIENDLY_NAME: device.name} - if isinstance(device, wemo_insight.Insight): + if isinstance(device, pywemo.Insight): pass # Should work but doesn't.. #state_attr[ATTR_TODAY_KWH] = device.today_kwh @@ -129,7 +121,7 @@ def setup(bus, statemachine): logger.info("Updating WeMo status") _update_wemos_state.last_updated = datetime.now() - for device in env: + for device in switches: _update_wemo_state(device) _update_wemos_state(None, True) diff --git a/homeassistant/external/pywemo b/homeassistant/external/pywemo new file mode 160000 index 00000000000..0e87fe7d724 --- /dev/null +++ b/homeassistant/external/pywemo @@ -0,0 +1 @@ +Subproject commit 0e87fe7d724aca851acfb5e756b751e072b03ca5