Implemented configuration loading from
This commit is contained in:
parent
90e2aefd23
commit
e4c5108c9d
1 changed files with 36 additions and 16 deletions
|
@ -40,27 +40,47 @@ def setup(hass, config):
|
|||
found = 1
|
||||
|
||||
while config_key in config:
|
||||
p_config = _migrate_old_config(config[config_key])
|
||||
# check for one block syntax
|
||||
if isinstance(config[config_key], dict):
|
||||
config_block = _migrate_old_config(config[config_key])
|
||||
name = config_block.get(CONF_ALIAS, config_key)
|
||||
_setup_automation(hass, config_block, name, config)
|
||||
|
||||
# check for multiple block syntax
|
||||
elif isinstance(config[config_key], list):
|
||||
list_no = 0
|
||||
for config_block in config[config_key]:
|
||||
name = config_block.get(CONF_ALIAS, "{}, {}".format(config_key, list_no))
|
||||
list_no += 1
|
||||
config_block = _migrate_old_config(config_block)
|
||||
_setup_automation(hass, config_block, name, config)
|
||||
|
||||
# any scalar value is incorrect
|
||||
else:
|
||||
_LOGGER.error('Error in config in section %s.', config_key)
|
||||
|
||||
found += 1
|
||||
config_key = "{} {}".format(DOMAIN, found)
|
||||
|
||||
name = p_config.get(CONF_ALIAS, config_key)
|
||||
action = _get_action(hass, p_config.get(CONF_ACTION, {}), name)
|
||||
|
||||
if action is None:
|
||||
continue
|
||||
|
||||
if CONF_CONDITION in p_config or CONF_CONDITION_TYPE in p_config:
|
||||
action = _process_if(hass, config, p_config, action)
|
||||
|
||||
if action is None:
|
||||
continue
|
||||
|
||||
_process_trigger(hass, config, p_config.get(CONF_TRIGGER, []), name,
|
||||
action)
|
||||
|
||||
return True
|
||||
|
||||
def _setup_automation(hass, config_block, name, config):
|
||||
""" Setup one instance of automation """
|
||||
|
||||
action = _get_action(hass, config_block.get(CONF_ACTION, {}), name)
|
||||
|
||||
if action is None:
|
||||
return False
|
||||
|
||||
if CONF_CONDITION in p_config or CONF_CONDITION_TYPE in p_config:
|
||||
action = _process_if(hass, config, config_block, action)
|
||||
|
||||
if action is None:
|
||||
return False
|
||||
|
||||
_process_trigger(hass, config, config_block.get(CONF_TRIGGER, []), name,
|
||||
action)
|
||||
return True
|
||||
|
||||
def _get_action(hass, config, name):
|
||||
""" Return an action based on a config. """
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue