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
This commit is contained in:
Thijs de Jong 2018-02-23 13:03:00 +01:00 committed by Pascal Vizeli
parent 1b22f2d8b8
commit daa00bc65a
3 changed files with 57 additions and 4 deletions

View File

@ -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}

View File

@ -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)

View File

@ -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