Now using PyWemo instead of Ouimeaux to control WeMo

This commit is contained in:
Paulus Schoutsen 2014-04-17 21:57:01 -07:00
parent 85f401f209
commit f4c77c85bd
3 changed files with 12 additions and 19 deletions

View File

@ -31,7 +31,7 @@ The system is built modular so support for other devices or actions can be imple
Installation instructions 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` * 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. * 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`. * 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`.

View File

@ -54,28 +54,20 @@ def setup(bus, statemachine):
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
try: try:
import ouimeaux.environment as wemo_env import homeassistant.external.pywemo.pywemo as pywemo
import ouimeaux.device.switch as wemo_switch
import ouimeaux.device.insight as wemo_insight
except ImportError: except ImportError:
logger.exception(("Failed to import ouimeaux. " pass
"Did you maybe not install the 'ouimeaux' "
"dependency?"))
return False return False
env = wemo_env.Environment() logger.info("Scanning for WeMo devices")
devices = pywemo.discover_devices()
try: is_switch = lambda switch: isinstance(switch, pywemo.Switch)
env.start()
except socket.error:
# If the socket is already in use
logger.exception("Error starting WeMo environment")
return False
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") logger.error("No WeMo switches found")
return False return False
@ -88,7 +80,7 @@ def setup(bus, statemachine):
""" Update the state of specified WeMo device. """ """ Update the state of specified WeMo device. """
# We currently only support switches # We currently only support switches
if not isinstance(device, wemo_switch.Switch): if not is_switch(device):
return return
try: try:
@ -107,7 +99,7 @@ def setup(bus, statemachine):
state_attr = {ATTR_FRIENDLY_NAME: device.name} state_attr = {ATTR_FRIENDLY_NAME: device.name}
if isinstance(device, wemo_insight.Insight): if isinstance(device, pywemo.Insight):
pass pass
# Should work but doesn't.. # Should work but doesn't..
#state_attr[ATTR_TODAY_KWH] = device.today_kwh #state_attr[ATTR_TODAY_KWH] = device.today_kwh
@ -129,7 +121,7 @@ def setup(bus, statemachine):
logger.info("Updating WeMo status") logger.info("Updating WeMo status")
_update_wemos_state.last_updated = datetime.now() _update_wemos_state.last_updated = datetime.now()
for device in env: for device in switches:
_update_wemo_state(device) _update_wemo_state(device)
_update_wemos_state(None, True) _update_wemos_state(None, True)

1
homeassistant/external/pywemo vendored Submodule

@ -0,0 +1 @@
Subproject commit 0e87fe7d724aca851acfb5e756b751e072b03ca5