From 40651ef2bc5948f3702a7dbee3e597b96dadc5e8 Mon Sep 17 00:00:00 2001 From: Stefan Jonasson Date: Sat, 19 Sep 2015 21:13:09 +0200 Subject: [PATCH] Fixed old config value conversion Added a new unit test for the config list mode --- .../components/automation/__init__.py | 6 +-- tests/components/automation/test_init.py | 38 +++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/automation/__init__.py b/homeassistant/components/automation/__init__.py index 4384b6a1848..5e35188a33c 100644 --- a/homeassistant/components/automation/__init__.py +++ b/homeassistant/components/automation/__init__.py @@ -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 diff --git a/tests/components/automation/test_init.py b/tests/components/automation/test_init.py index 6a011a072a5..1df59840aea 100644 --- a/tests/components/automation/test_init.py +++ b/tests/components/automation/test_init.py @@ -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))