Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions homeassistant/components/light/lutron.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@
# 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)
Expand All @@ -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):
Expand Down
16 changes: 10 additions & 6 deletions homeassistant/components/lutron.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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
Expand Down Expand Up @@ -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."""
Expand All @@ -68,7 +72,7 @@ def _update_callback(self, _device):
@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):
Expand Down