Filter out falsey platform configs
This commit is contained in:
parent
d3a012a536
commit
ac4e54c6ff
3 changed files with 19 additions and 10 deletions
|
@ -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:
|
||||
|
|
|
@ -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'))
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Add table
Reference in a new issue