From d1b73a96f4e45722abc0882ce4b3c41cf1b58bfa Mon Sep 17 00:00:00 2001 From: kfcook <809694+kfcook@users.noreply.github.com> Date: Sat, 29 Jul 2017 12:07:28 -0400 Subject: [PATCH] Added Lutron Caseta Scene Support (#8690) * added scene support * Updated pylutron_caseta version number * Updated pylutron_caseta version number * Fixed lint errors * fix style --- homeassistant/components/lutron_caseta.py | 8 ++- .../components/scene/lutron_caseta.py | 55 +++++++++++++++++++ requirements_all.txt | 2 +- 3 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 homeassistant/components/scene/lutron_caseta.py diff --git a/homeassistant/components/lutron_caseta.py b/homeassistant/components/lutron_caseta.py index e2ad733fb36..dcb3347e919 100644 --- a/homeassistant/components/lutron_caseta.py +++ b/homeassistant/components/lutron_caseta.py @@ -14,7 +14,7 @@ from homeassistant.const import CONF_HOST from homeassistant.helpers import discovery from homeassistant.helpers.entity import Entity -REQUIREMENTS = ['pylutron-caseta==0.2.6'] +REQUIREMENTS = ['pylutron-caseta==0.2.7'] _LOGGER = logging.getLogger(__name__) @@ -28,6 +28,10 @@ CONFIG_SCHEMA = vol.Schema({ }) }, extra=vol.ALLOW_EXTRA) +LUTRON_CASETA_COMPONENTS = [ + 'light', 'switch', 'cover', 'scene' +] + def setup(hass, base_config): """Set up the Lutron component.""" @@ -44,7 +48,7 @@ def setup(hass, base_config): _LOGGER.info("Connected to Lutron smartbridge at %s", config[CONF_HOST]) - for component in ('light', 'switch', 'cover'): + for component in LUTRON_CASETA_COMPONENTS: discovery.load_platform(hass, component, DOMAIN, {}, config) return True diff --git a/homeassistant/components/scene/lutron_caseta.py b/homeassistant/components/scene/lutron_caseta.py new file mode 100644 index 00000000000..b98f7f3e6ea --- /dev/null +++ b/homeassistant/components/scene/lutron_caseta.py @@ -0,0 +1,55 @@ +""" +Support for Lutron Caseta scenes. + +For more details about this platform, please refer to the documentation at +https://home-assistant.io/components/scene.lutron_caseta/ +""" +import logging + +from homeassistant.components.scene import Scene +from homeassistant.components.lutron_caseta import LUTRON_CASETA_SMARTBRIDGE + +_LOGGER = logging.getLogger(__name__) + +DEPENDENCIES = ['lutron_caseta'] + + +def setup_platform(hass, config, add_devices, discovery_info=None): + """Set up the Lutron Caseta lights.""" + devs = [] + bridge = hass.data[LUTRON_CASETA_SMARTBRIDGE] + scenes = bridge.get_scenes() + for scene in scenes: + dev = LutronCasetaScene(scenes[scene], bridge) + devs.append(dev) + + add_devices(devs, True) + + +class LutronCasetaScene(Scene): + """Representation of a Lutron Caseta scene.""" + + def __init__(self, scene, bridge): + """Initialize the Lutron Caseta scene.""" + self._scene_name = scene["name"] + self._scene_id = scene["scene_id"] + self._bridge = bridge + + @property + def name(self): + """Return the name of the scene.""" + return self._scene_name + + @property + def should_poll(self): + """Return that polling is not necessary.""" + return False + + @property + def is_on(self): + """There is no way of detecting if a scene is active (yet).""" + return False + + def activate(self, **kwargs): + """Activate the scene.""" + self._bridge.activate_scene(self._scene_id) diff --git a/requirements_all.txt b/requirements_all.txt index 5b140580140..7220bd0cfc2 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -624,7 +624,7 @@ pylitejet==0.1 pyloopenergy==0.0.17 # homeassistant.components.lutron_caseta -pylutron-caseta==0.2.6 +pylutron-caseta==0.2.7 # homeassistant.components.lutron pylutron==0.1.0