Add support for subscriptions
This commit is contained in:
parent
3e51d0b539
commit
1e2b5e6991
1 changed files with 22 additions and 1 deletions
|
@ -11,9 +11,10 @@ import logging
|
||||||
from homeassistant.components.switch import SwitchDevice
|
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
|
||||||
|
|
||||||
REQUIREMENTS = ['pywemo==0.3.3']
|
# REQUIREMENTS = ['pywemo==0.3.3']
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
_WEMO_SUBSCRIPTION_REGISTRY = None
|
||||||
|
|
||||||
# pylint: disable=unused-argument, too-many-function-args
|
# pylint: disable=unused-argument, too-many-function-args
|
||||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||||
|
@ -21,6 +22,11 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||||
import pywemo
|
import pywemo
|
||||||
import pywemo.discovery as discovery
|
import pywemo.discovery as discovery
|
||||||
|
|
||||||
|
global _WEMO_SUBSCRIPTION_REGISTRY
|
||||||
|
if _WEMO_SUBSCRIPTION_REGISTRY is None:
|
||||||
|
_WEMO_SUBSCRIPTION_REGISTRY = pywemo.SubscriptionRegistry()
|
||||||
|
_WEMO_SUBSCRIPTION_REGISTRY.start()
|
||||||
|
|
||||||
if discovery_info is not None:
|
if discovery_info is not None:
|
||||||
location = discovery_info[2]
|
location = discovery_info[2]
|
||||||
mac = discovery_info[3]
|
mac = discovery_info[3]
|
||||||
|
@ -47,6 +53,21 @@ class WemoSwitch(SwitchDevice):
|
||||||
self.insight_params = None
|
self.insight_params = None
|
||||||
self.maker_params = None
|
self.maker_params = None
|
||||||
|
|
||||||
|
global _WEMO_SUBSCRIPTION_REGISTRY
|
||||||
|
_WEMO_SUBSCRIPTION_REGISTRY.register(wemo)
|
||||||
|
_WEMO_SUBSCRIPTION_REGISTRY.on(wemo, 'BinaryState', self._update_callback)
|
||||||
|
_WEMO_SUBSCRIPTION_REGISTRY.on(wemo, 'attributeList', self._update_callback)
|
||||||
|
|
||||||
|
def _update_callback(self, _device, _params):
|
||||||
|
_LOGGER.info('Subscription update for %s, sevice=%s params=%s', self.name, _device, _params)
|
||||||
|
# import pdb; pdb.set_trace()
|
||||||
|
self.update()
|
||||||
|
|
||||||
|
@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
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
""" Returns the id of this WeMo switch """
|
""" Returns the id of this WeMo switch """
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue