mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
1. added platform per scene entry.
2. changed homeassistant scene setup_platform method to work with 1.
This commit is contained in:
parent
019af42e94
commit
94633b3795
@ -11,6 +11,7 @@ from collections import namedtuple
|
|||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ENTITY_ID, SERVICE_TURN_ON, CONF_PLATFORM)
|
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 import Entity
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
|
|
||||||
@ -38,11 +39,19 @@ def setup(hass, config):
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
for entry in config:
|
# You are not allowed to mutate the original config so make a copy
|
||||||
if DOMAIN in entry:
|
config = dict(config)
|
||||||
if not any(CONF_PLATFORM in key for key in config[entry]):
|
|
||||||
config[entry] = {'platform': 'homeassistant',
|
for config_key in extract_domain_configs(config, DOMAIN):
|
||||||
'config': config[entry]}
|
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)
|
component = EntityComponent(logger, DOMAIN, hass)
|
||||||
|
|
||||||
|
@ -25,19 +25,13 @@ SceneConfig = namedtuple('SceneConfig', ['name', 'states'])
|
|||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
""" Sets up scenes. """
|
""" Sets up home assistant scene entries. """
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
scene_configs = config.get("config")
|
scene_config = config.get("config")
|
||||||
|
|
||||||
if not isinstance(scene_configs, list) or \
|
add_devices([HomeAssistantScene(hass, _process_config(scene_config))])
|
||||||
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)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user