Lutron. Bugfix callback registration. (#7042)

* Lutron. Bugfix callback registration.

* Change handling to event
This commit is contained in:
Pascal Vizeli 2017-04-12 09:52:01 +02:00 committed by GitHub
parent e026717239
commit 9d20a17642
2 changed files with 13 additions and 12 deletions

View File

@ -14,12 +14,9 @@ _LOGGER = logging.getLogger(__name__)
# pylint: disable=unused-argument # pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup Lutron lights.""" """Setup Lutron lights."""
area_devs = {}
devs = [] devs = []
for (area_name, device) in hass.data[LUTRON_DEVICES]['light']: for (area_name, device) in hass.data[LUTRON_DEVICES]['light']:
dev = LutronLight(hass, area_name, device, dev = LutronLight(area_name, device, hass.data[LUTRON_CONTROLLER])
hass.data[LUTRON_CONTROLLER])
area_devs.setdefault(area_name, []).append(dev)
devs.append(dev) devs.append(dev)
add_devices(devs, True) add_devices(devs, True)
@ -39,10 +36,10 @@ def to_hass_level(level):
class LutronLight(LutronDevice, Light): class LutronLight(LutronDevice, Light):
"""Representation of a Lutron Light, including dimmable.""" """Representation of a Lutron Light, including dimmable."""
def __init__(self, hass, area_name, lutron_device, controller): def __init__(self, area_name, lutron_device, controller):
"""Initialize the light.""" """Initialize the light."""
self._prev_brightness = None self._prev_brightness = None
LutronDevice.__init__(self, hass, area_name, lutron_device, controller) LutronDevice.__init__(self, area_name, lutron_device, controller)
@property @property
def supported_features(self): def supported_features(self):

View File

@ -4,6 +4,7 @@ Component for interacting with a Lutron RadioRA 2 system.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/lutron/ https://home-assistant.io/components/lutron/
""" """
import asyncio
import logging import logging
from homeassistant.helpers import discovery from homeassistant.helpers import discovery
@ -50,16 +51,19 @@ def setup(hass, base_config):
class LutronDevice(Entity): class LutronDevice(Entity):
"""Representation of a Lutron device entity.""" """Representation of a Lutron device entity."""
def __init__(self, hass, area_name, lutron_device, controller): def __init__(self, area_name, lutron_device, controller):
"""Initialize the device.""" """Initialize the device."""
self._lutron_device = lutron_device self._lutron_device = lutron_device
self._controller = controller self._controller = controller
self._area_name = area_name self._area_name = area_name
self.hass = hass @asyncio.coroutine
self.object_id = '{} {}'.format(area_name, lutron_device.name) def async_add_to_hass(self):
"""Register callbacks."""
self._controller.subscribe(self._lutron_device, self._update_callback) self.hass.async_add_job(
self._controller.subscribe, self._lutron_device,
self._update_callback
)
def _update_callback(self, _device): def _update_callback(self, _device):
"""Callback invoked by pylutron when the device state changes.""" """Callback invoked by pylutron when the device state changes."""
@ -68,7 +72,7 @@ class LutronDevice(Entity):
@property @property
def name(self): def name(self):
"""Return the name of the device.""" """Return the name of the device."""
return self._lutron_device.name return "{} {}".format(self._area_name, self._lutron_device.name)
@property @property
def should_poll(self): def should_poll(self):