1. added platform per scene entry.
2. changed homeassistant scene setup_platform method to work with 1.pull/1374/head
parent
019af42e94
commit
94633b3795
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue