Merge pull request #794 from pavoni/wemo-subscription
Adds Wemo event support - so wemo devices update HA more quicklypull/818/head
commit
df99e4ef22
homeassistant/components/switch
|
@ -9,11 +9,14 @@ https://home-assistant.io/components/switch.wemo/
|
|||
import logging
|
||||
|
||||
from homeassistant.components.switch import SwitchDevice
|
||||
from homeassistant.const import STATE_ON, STATE_OFF, STATE_STANDBY
|
||||
from homeassistant.const import (
|
||||
STATE_ON, STATE_OFF, STATE_STANDBY, EVENT_HOMEASSISTANT_STOP)
|
||||
|
||||
REQUIREMENTS = ['pywemo==0.3.3']
|
||||
REQUIREMENTS = ['pywemo==0.3.4']
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
_WEMO_SUBSCRIPTION_REGISTRY = None
|
||||
|
||||
|
||||
# pylint: disable=unused-argument, too-many-function-args
|
||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
|
@ -21,6 +24,18 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||
import pywemo
|
||||
import pywemo.discovery as discovery
|
||||
|
||||
global _WEMO_SUBSCRIPTION_REGISTRY
|
||||
if _WEMO_SUBSCRIPTION_REGISTRY is None:
|
||||
_WEMO_SUBSCRIPTION_REGISTRY = pywemo.SubscriptionRegistry()
|
||||
_WEMO_SUBSCRIPTION_REGISTRY.start()
|
||||
|
||||
def stop_wemo(event):
|
||||
""" Shutdown Wemo subscriptions and subscription thread on exit"""
|
||||
_LOGGER.info("Shutting down subscriptions.")
|
||||
_WEMO_SUBSCRIPTION_REGISTRY.stop()
|
||||
|
||||
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_wemo)
|
||||
|
||||
if discovery_info is not None:
|
||||
location = discovery_info[2]
|
||||
mac = discovery_info[3]
|
||||
|
@ -47,6 +62,23 @@ class WemoSwitch(SwitchDevice):
|
|||
self.insight_params = None
|
||||
self.maker_params = None
|
||||
|
||||
_WEMO_SUBSCRIPTION_REGISTRY.register(wemo)
|
||||
_WEMO_SUBSCRIPTION_REGISTRY.on(
|
||||
wemo, None, self._update_callback)
|
||||
|
||||
def _update_callback(self, _device, _params):
|
||||
""" Called by the wemo device callback to update state. """
|
||||
_LOGGER.info(
|
||||
'Subscription update for %s, sevice=%s',
|
||||
self.name, _device)
|
||||
self.update_ha_state(True)
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
""" No polling should be needed with subscriptions """
|
||||
# but leave in for initial version in case of issues.
|
||||
return True
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
""" Returns the id of this WeMo switch """
|
||||
|
|
|
@ -173,7 +173,7 @@ hikvision==0.4
|
|||
orvibo==1.1.0
|
||||
|
||||
# homeassistant.components.switch.wemo
|
||||
pywemo==0.3.3
|
||||
pywemo==0.3.4
|
||||
|
||||
# homeassistant.components.tellduslive
|
||||
tellive-py==0.5.2
|
||||
|
|
Loading…
Reference in New Issue