From ac4e54c6ff7d2a6cab537639984aa5cd7645cf84 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sat, 24 Sep 2016 00:03:44 -0700 Subject: [PATCH] Filter out falsey platform configs --- homeassistant/helpers/__init__.py | 5 ++++- tests/helpers/test_init.py | 1 - tests/test_bootstrap.py | 23 +++++++++++++++-------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/homeassistant/helpers/__init__.py b/homeassistant/helpers/__init__.py index 2dc3af1dff9..3e45d3ecb83 100644 --- a/homeassistant/helpers/__init__.py +++ b/homeassistant/helpers/__init__.py @@ -22,7 +22,10 @@ def config_per_platform(config: ConfigType, """ for config_key in extract_domain_configs(config, domain): platform_config = config[config_key] - if not isinstance(platform_config, list): + + if not platform_config: + continue + elif not isinstance(platform_config, list): platform_config = [platform_config] for item in platform_config: diff --git a/tests/helpers/test_init.py b/tests/helpers/test_init.py index 541247c5420..1791e5622a9 100644 --- a/tests/helpers/test_init.py +++ b/tests/helpers/test_init.py @@ -45,5 +45,4 @@ class TestHelpers(unittest.TestCase): ('hello', config['zone']), (None, 1), ('hello 2', config['zone Hallo'][1]), - (None, None) ] == list(helpers.config_per_platform(config, 'zone')) diff --git a/tests/test_bootstrap.py b/tests/test_bootstrap.py index b2a3136455a..b74a1de0d35 100644 --- a/tests/test_bootstrap.py +++ b/tests/test_bootstrap.py @@ -110,14 +110,6 @@ class TestBootstrap: loader.set_component( 'platform_conf.whatever', MockPlatform('whatever')) - assert not bootstrap._setup_component(self.hass, 'platform_conf', { - 'platform_conf': None - }) - - assert not bootstrap._setup_component(self.hass, 'platform_conf', { - 'platform_conf': {} - }) - assert not bootstrap._setup_component(self.hass, 'platform_conf', { 'platform_conf': { 'hello': 'world', @@ -150,6 +142,8 @@ class TestBootstrap: } }) + self.hass.config.components.remove('platform_conf') + assert bootstrap._setup_component(self.hass, 'platform_conf', { 'platform_conf': [{ 'platform': 'whatever', @@ -157,6 +151,19 @@ class TestBootstrap: }] }) + self.hass.config.components.remove('platform_conf') + + # Any falsey paltform config will be ignored (None, {}, etc) + assert bootstrap._setup_component(self.hass, 'platform_conf', { + 'platform_conf': None + }) + + self.hass.config.components.remove('platform_conf') + + assert bootstrap._setup_component(self.hass, 'platform_conf', { + 'platform_conf': {} + }) + def test_component_not_found(self): """setup_component should not crash if component doesn't exist.""" assert not bootstrap.setup_component(self.hass, 'non_existing')