From 94633b3795c3e75816c8426e7f8a090fd590ed68 Mon Sep 17 00:00:00 2001 From: sander Date: Sun, 28 Feb 2016 10:24:02 +0100 Subject: [PATCH] 1. added platform per scene entry. 2. changed homeassistant scene setup_platform method to work with 1. --- homeassistant/components/scene/__init__.py | 19 ++++++++++++++----- .../components/scene/homeassistant.py | 12 +++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/homeassistant/components/scene/__init__.py b/homeassistant/components/scene/__init__.py index b69ed326b89..fbf8ab77230 100644 --- a/homeassistant/components/scene/__init__.py +++ b/homeassistant/components/scene/__init__.py @@ -11,6 +11,7 @@ from collections import namedtuple from homeassistant.const import ( ATTR_ENTITY_ID, SERVICE_TURN_ON, CONF_PLATFORM) +from homeassistant.helpers import extract_domain_configs from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity_component import EntityComponent @@ -38,11 +39,19 @@ def setup(hass, config): logger = logging.getLogger(__name__) - for entry in config: - if DOMAIN in entry: - if not any(CONF_PLATFORM in key for key in config[entry]): - config[entry] = {'platform': 'homeassistant', - 'config': config[entry]} + # You are not allowed to mutate the original config so make a copy + config = dict(config) + + for config_key in extract_domain_configs(config, DOMAIN): + platform_config = config[config_key] + if not isinstance(platform_config, list): + platform_config = [platform_config] + + if not any(CONF_PLATFORM in entry for entry in platform_config): + platform_config = [{'platform': 'homeassistant', 'config': entry} + for entry in platform_config] + + config[config_key] = platform_config component = EntityComponent(logger, DOMAIN, hass) diff --git a/homeassistant/components/scene/homeassistant.py b/homeassistant/components/scene/homeassistant.py index 9f41ebecc94..96599a2afc6 100644 --- a/homeassistant/components/scene/homeassistant.py +++ b/homeassistant/components/scene/homeassistant.py @@ -25,19 +25,13 @@ SceneConfig = namedtuple('SceneConfig', ['name', 'states']) # pylint: disable=unused-argument def setup_platform(hass, config, add_devices, discovery_info=None): - """ Sets up scenes. """ + """ Sets up home assistant scene entries. """ logger = logging.getLogger(__name__) - scene_configs = config.get("config") + scene_config = config.get("config") - if not isinstance(scene_configs, list) or \ - any(not isinstance(item, dict) for item in scene_configs): - logger.error('Scene config should be a list of dictionaries') - return False - - add_devices(HomeAssistantScene(hass, _process_config(scene_config)) - for scene_config in scene_configs) + add_devices([HomeAssistantScene(hass, _process_config(scene_config))]) return True