From daa00bc65a4f4f6f19132557e269606dda281d5c Mon Sep 17 00:00:00 2001 From: Thijs de Jong Date: Fri, 23 Feb 2018 13:03:00 +0100 Subject: [PATCH] Add Tahoma scenes (#12498) * add scenes to platform * add scene.tahoma * requires tahoma-api 0.0.12 * update requirements_all.txt * hound * fix pylint error --- homeassistant/components/scene/tahoma.py | 48 ++++++++++++++++++++++++ homeassistant/components/tahoma.py | 11 ++++-- requirements_all.txt | 2 +- 3 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 homeassistant/components/scene/tahoma.py diff --git a/homeassistant/components/scene/tahoma.py b/homeassistant/components/scene/tahoma.py new file mode 100644 index 00000000000..39206623901 --- /dev/null +++ b/homeassistant/components/scene/tahoma.py @@ -0,0 +1,48 @@ +""" +Support for Tahoma scenes. + +For more details about this platform, please refer to the documentation at +https://home-assistant.io/components/scene.tahoma/ +""" +import logging + +from homeassistant.components.scene import Scene +from homeassistant.components.tahoma import ( + DOMAIN as TAHOMA_DOMAIN) + +DEPENDENCIES = ['tahoma'] + +_LOGGER = logging.getLogger(__name__) + + +def setup_platform(hass, config, add_devices, discovery_info=None): + """Set up the Tahoma scenes.""" + controller = hass.data[TAHOMA_DOMAIN]['controller'] + scenes = [] + for scene in hass.data[TAHOMA_DOMAIN]['scenes']: + scenes.append(TahomaScene(scene, controller)) + add_devices(scenes, True) + + +class TahomaScene(Scene): + """Representation of a Tahoma scene entity.""" + + def __init__(self, tahoma_scene, controller): + """Initialize the scene.""" + self.tahoma_scene = tahoma_scene + self.controller = controller + self._name = self.tahoma_scene.name + + def activate(self): + """Activate the scene.""" + self.controller.launch_action_group(self.tahoma_scene.oid) + + @property + def name(self): + """Return the name of the scene.""" + return self._name + + @property + def device_state_attributes(self): + """Return the state attributes of the scene.""" + return {'tahoma_scene_oid': self.tahoma_scene.oid} diff --git a/homeassistant/components/tahoma.py b/homeassistant/components/tahoma.py index 00ebc78a40b..b288a704d74 100644 --- a/homeassistant/components/tahoma.py +++ b/homeassistant/components/tahoma.py @@ -14,7 +14,7 @@ from homeassistant.helpers import discovery from homeassistant.helpers import config_validation as cv from homeassistant.helpers.entity import Entity -REQUIREMENTS = ['tahoma-api==0.0.11'] +REQUIREMENTS = ['tahoma-api==0.0.12'] _LOGGER = logging.getLogger(__name__) @@ -32,7 +32,7 @@ CONFIG_SCHEMA = vol.Schema({ }, extra=vol.ALLOW_EXTRA) TAHOMA_COMPONENTS = [ - 'sensor', 'cover' + 'scene', 'sensor', 'cover' ] TAHOMA_TYPES = { @@ -63,13 +63,15 @@ def setup(hass, config): try: api.get_setup() devices = api.get_devices() + scenes = api.get_action_groups() except RequestException: _LOGGER.exception("Error when getting devices from the Tahoma API") return False hass.data[DOMAIN] = { 'controller': api, - 'devices': defaultdict(list) + 'devices': defaultdict(list), + 'scenes': [] } for device in devices: @@ -82,6 +84,9 @@ def setup(hass, config): continue hass.data[DOMAIN]['devices'][device_type].append(_device) + for scene in scenes: + hass.data[DOMAIN]['scenes'].append(scene) + for component in TAHOMA_COMPONENTS: discovery.load_platform(hass, component, DOMAIN, {}, config) diff --git a/requirements_all.txt b/requirements_all.txt index 6742e842657..38b90875870 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1159,7 +1159,7 @@ steamodd==4.21 suds-py3==1.3.3.0 # homeassistant.components.tahoma -tahoma-api==0.0.11 +tahoma-api==0.0.12 # homeassistant.components.sensor.tank_utility tank_utility==1.4.0