Lutron. Bugfix callback registration. (#7042)
* Lutron. Bugfix callback registration. * Change handling to eventpull/7062/head
parent
e026717239
commit
9d20a17642
|
@ -14,12 +14,9 @@ _LOGGER = logging.getLogger(__name__)
|
|||
# pylint: disable=unused-argument
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Setup Lutron lights."""
|
||||
area_devs = {}
|
||||
devs = []
|
||||
for (area_name, device) in hass.data[LUTRON_DEVICES]['light']:
|
||||
dev = LutronLight(hass, area_name, device,
|
||||
hass.data[LUTRON_CONTROLLER])
|
||||
area_devs.setdefault(area_name, []).append(dev)
|
||||
dev = LutronLight(area_name, device, hass.data[LUTRON_CONTROLLER])
|
||||
devs.append(dev)
|
||||
|
||||
add_devices(devs, True)
|
||||
|
@ -39,10 +36,10 @@ def to_hass_level(level):
|
|||
class LutronLight(LutronDevice, Light):
|
||||
"""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."""
|
||||
self._prev_brightness = None
|
||||
LutronDevice.__init__(self, hass, area_name, lutron_device, controller)
|
||||
LutronDevice.__init__(self, area_name, lutron_device, controller)
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
|
|
|
@ -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
|
||||
https://home-assistant.io/components/lutron/
|
||||
"""
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from homeassistant.helpers import discovery
|
||||
|
@ -50,16 +51,19 @@ def setup(hass, base_config):
|
|||
class LutronDevice(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."""
|
||||
self._lutron_device = lutron_device
|
||||
self._controller = controller
|
||||
self._area_name = area_name
|
||||
|
||||
self.hass = hass
|
||||
self.object_id = '{} {}'.format(area_name, lutron_device.name)
|
||||
|
||||
self._controller.subscribe(self._lutron_device, self._update_callback)
|
||||
@asyncio.coroutine
|
||||
def async_add_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
self.hass.async_add_job(
|
||||
self._controller.subscribe, self._lutron_device,
|
||||
self._update_callback
|
||||
)
|
||||
|
||||
def _update_callback(self, _device):
|
||||
"""Callback invoked by pylutron when the device state changes."""
|
||||
|
@ -68,7 +72,7 @@ class LutronDevice(Entity):
|
|||
@property
|
||||
def name(self):
|
||||
"""Return the name of the device."""
|
||||
return self._lutron_device.name
|
||||
return "{} {}".format(self._area_name, self._lutron_device.name)
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
|
|
Loading…
Reference in New Issue