mirror of
https://github.com/home-assistant/core.git
synced 2025-04-27 18:57:57 +00:00
Fixed old config value conversion
Added a new unit test for the config list mode
This commit is contained in:
parent
2084976bc2
commit
40651ef2bc
@ -42,15 +42,15 @@ def setup(hass, config):
|
|||||||
while config_key in config:
|
while config_key in config:
|
||||||
# check for one block syntax
|
# check for one block syntax
|
||||||
if isinstance(config[config_key], dict):
|
if isinstance(config[config_key], dict):
|
||||||
name = config[config_key].get(CONF_ALIAS, config_key)
|
config_block = _migrate_old_config(config[config_key])
|
||||||
_setup_automation(hass, config[config_key], name, config)
|
name = config_block.get(CONF_ALIAS, config_key)
|
||||||
|
_setup_automation(hass, config_block, name, config)
|
||||||
|
|
||||||
# check for multiple block syntax
|
# check for multiple block syntax
|
||||||
elif isinstance(config[config_key], list):
|
elif isinstance(config[config_key], list):
|
||||||
for list_no, config_block in enumerate(config[config_key]):
|
for list_no, config_block in enumerate(config[config_key]):
|
||||||
name = config_block.get(CONF_ALIAS,
|
name = config_block.get(CONF_ALIAS,
|
||||||
"{}, {}".format(config_key, list_no))
|
"{}, {}".format(config_key, list_no))
|
||||||
config_block = _migrate_old_config(config_block)
|
|
||||||
_setup_automation(hass, config_block, name, config)
|
_setup_automation(hass, config_block, name, config)
|
||||||
|
|
||||||
# any scalar value is incorrect
|
# any scalar value is incorrect
|
||||||
|
@ -322,3 +322,41 @@ class TestAutomationEvent(unittest.TestCase):
|
|||||||
self.hass.bus.fire('test_event')
|
self.hass.bus.fire('test_event')
|
||||||
self.hass.pool.block_till_done()
|
self.hass.pool.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
self.assertEqual(1, len(self.calls))
|
||||||
|
|
||||||
|
def test_automation_list_setting(self):
|
||||||
|
""" Event is not a valid condition. Will it still work? """
|
||||||
|
automation.setup(self.hass, {
|
||||||
|
automation.DOMAIN: [
|
||||||
|
{
|
||||||
|
'trigger': [
|
||||||
|
{
|
||||||
|
'platform': 'event',
|
||||||
|
'event_type': 'test_event',
|
||||||
|
},
|
||||||
|
|
||||||
|
],
|
||||||
|
'action': {
|
||||||
|
'execute_service': 'test.automation',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'trigger': [
|
||||||
|
{
|
||||||
|
'platform': 'event',
|
||||||
|
'event_type': 'test_event_2',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
'action': {
|
||||||
|
'execute_service': 'test.automation',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
self.hass.bus.fire('test_event')
|
||||||
|
self.hass.pool.block_till_done()
|
||||||
|
self.assertEqual(1, len(self.calls))
|
||||||
|
|
||||||
|
self.hass.bus.fire('test_event_2')
|
||||||
|
self.hass.pool.block_till_done()
|
||||||
|
self.assertEqual(2, len(self.calls))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user