From c93bed866790fa0912932347e1a284d3323d7f70 Mon Sep 17 00:00:00 2001 From: Nicko van Someren Date: Wed, 10 Jan 2018 18:58:38 -0700 Subject: [PATCH 1/3] Adding support for Lutron Radio RA2 shades as cover components. --- homeassistant/components/lutron.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/lutron.py b/homeassistant/components/lutron.py index 819844325d1f9d..bef821220b347f 100644 --- a/homeassistant/components/lutron.py +++ b/homeassistant/components/lutron.py @@ -37,7 +37,7 @@ def setup(hass, base_config): from pylutron import Lutron hass.data[LUTRON_CONTROLLER] = None - hass.data[LUTRON_DEVICES] = {'light': []} + hass.data[LUTRON_DEVICES] = {'light': [], 'cover': []} config = base_config.get(DOMAIN) hass.data[LUTRON_CONTROLLER] = Lutron( @@ -50,9 +50,12 @@ def setup(hass, base_config): # Sort our devices into types for area in hass.data[LUTRON_CONTROLLER].areas: for output in area.outputs: - hass.data[LUTRON_DEVICES]['light'].append((area.name, output)) + if output.type == 'SYSTEM_SHADE': + hass.data[LUTRON_DEVICES]['cover'].append((area.name, output)) + else: + hass.data[LUTRON_DEVICES]['light'].append((area.name, output)) - for component in ('light',): + for component in ('light', 'cover'): discovery.load_platform(hass, component, DOMAIN, None, base_config) return True From 78eb837d421a965458a4b2ae4d23e2aefe739ca6 Mon Sep 17 00:00:00 2001 From: Nicko van Someren Date: Thu, 11 Jan 2018 15:15:40 -0700 Subject: [PATCH 2/3] Adding initial version of the Lutron shades component. --- homeassistant/components/cover/lutron.py | 75 ++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 homeassistant/components/cover/lutron.py diff --git a/homeassistant/components/cover/lutron.py b/homeassistant/components/cover/lutron.py new file mode 100644 index 00000000000000..a807c2e92a0a13 --- /dev/null +++ b/homeassistant/components/cover/lutron.py @@ -0,0 +1,75 @@ +""" +Support for Lutron shades. + +For more details about this platform, please refer to the documentation at +https://home-assistant.io/components/cover.lutron/ +""" +import logging + +from homeassistant.components.cover import ( + CoverDevice, SUPPORT_OPEN, SUPPORT_CLOSE, SUPPORT_SET_POSITION, + ATTR_POSITION) +from homeassistant.components.lutron import ( + LutronDevice, LUTRON_DEVICES, LUTRON_CONTROLLER) + +_LOGGER = logging.getLogger(__name__) + +DEPENDENCIES = ['lutron'] + + +# pylint: disable=unused-argument +def setup_platform(hass, config, add_devices, discovery_info=None): + """Set up the Lutron shades.""" + devs = [] + for (area_name, device) in hass.data[LUTRON_DEVICES]['cover']: + dev = LutronCover(area_name, device, hass.data[LUTRON_CONTROLLER]) + devs.append(dev) + + add_devices(devs, True) + return True + + +class LutronCover(LutronDevice, CoverDevice): + """Representation of a Lutron shade.""" + + @property + def supported_features(self): + """Flag supported features.""" + return SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_SET_POSITION + + @property + def is_closed(self): + """Return if the cover is closed.""" + return self._lutron_device.last_level() < 1 + + @property + def current_cover_position(self): + """Return the current position of cover.""" + return self._lutron_device.last_level() + + def close_cover(self, **kwargs): + """Close the cover.""" + self._lutron_device.level = 0 + + def open_cover(self, **kwargs): + """Open the cover.""" + self._lutron_device.level = 100 + + def set_cover_position(self, **kwargs): + """Move the shade to a specific position.""" + if ATTR_POSITION in kwargs: + position = kwargs[ATTR_POSITION] + self._lutron_device.level = position + + def update(self): + """Call when forcing a refresh of the device.""" + # Reading the property (rather than last_level()) fetchs value + level = self._lutron_device.level + _LOGGER.debug("Lutron ID: %d updated to %f", self._lutron_device.id, level) + + @property + def device_state_attributes(self): + """Return the state attributes.""" + attr = {} + attr['Lutron Integration ID'] = self._lutron_device.id + return attr From 0602124e8dbf6a1142830dadcdf3fac5243b771a Mon Sep 17 00:00:00 2001 From: Nicko van Someren Date: Fri, 12 Jan 2018 10:48:46 -0700 Subject: [PATCH 3/3] Fixed line-length violation detected by Hound. --- homeassistant/components/cover/lutron.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/cover/lutron.py b/homeassistant/components/cover/lutron.py index a807c2e92a0a13..08a2ef8c5ad7c1 100644 --- a/homeassistant/components/cover/lutron.py +++ b/homeassistant/components/cover/lutron.py @@ -65,7 +65,8 @@ def update(self): """Call when forcing a refresh of the device.""" # Reading the property (rather than last_level()) fetchs value level = self._lutron_device.level - _LOGGER.debug("Lutron ID: %d updated to %f", self._lutron_device.id, level) + _LOGGER.debug("Lutron ID: %d updated to %f", + self._lutron_device.id, level) @property def device_state_attributes(self):