Fixed old config value conversion

Added a new unit test for the config list mode
pull/404/head
Stefan Jonasson 2015-09-19 21:13:09 +02:00
parent 2084976bc2
commit 40651ef2bc
2 changed files with 41 additions and 3 deletions

View File

@ -42,15 +42,15 @@ def setup(hass, config):
while config_key in config:
# check for one block syntax
if isinstance(config[config_key], dict):
name = config[config_key].get(CONF_ALIAS, config_key)
_setup_automation(hass, config[config_key], name, config)
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):
for list_no, config_block in enumerate(config[config_key]):
name = config_block.get(CONF_ALIAS,
"{}, {}".format(config_key, list_no))
config_block = _migrate_old_config(config_block)
_setup_automation(hass, config_block, name, config)
# any scalar value is incorrect

View File

@ -322,3 +322,41 @@ class TestAutomationEvent(unittest.TestCase):
self.hass.bus.fire('test_event')
self.hass.pool.block_till_done()
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))