mirror of https://github.com/home-assistant/core
Filter out falsey platform configs
This commit is contained in:
parent
d3a012a536
commit
ac4e54c6ff
|
@ -22,7 +22,10 @@ def config_per_platform(config: ConfigType,
|
||||||
"""
|
"""
|
||||||
for config_key in extract_domain_configs(config, domain):
|
for config_key in extract_domain_configs(config, domain):
|
||||||
platform_config = config[config_key]
|
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]
|
platform_config = [platform_config]
|
||||||
|
|
||||||
for item in platform_config:
|
for item in platform_config:
|
||||||
|
|
|
@ -45,5 +45,4 @@ class TestHelpers(unittest.TestCase):
|
||||||
('hello', config['zone']),
|
('hello', config['zone']),
|
||||||
(None, 1),
|
(None, 1),
|
||||||
('hello 2', config['zone Hallo'][1]),
|
('hello 2', config['zone Hallo'][1]),
|
||||||
(None, None)
|
|
||||||
] == list(helpers.config_per_platform(config, 'zone'))
|
] == list(helpers.config_per_platform(config, 'zone'))
|
||||||
|
|
|
@ -110,14 +110,6 @@ class TestBootstrap:
|
||||||
loader.set_component(
|
loader.set_component(
|
||||||
'platform_conf.whatever', MockPlatform('whatever'))
|
'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', {
|
assert not bootstrap._setup_component(self.hass, 'platform_conf', {
|
||||||
'platform_conf': {
|
'platform_conf': {
|
||||||
'hello': 'world',
|
'hello': 'world',
|
||||||
|
@ -150,6 +142,8 @@ class TestBootstrap:
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
self.hass.config.components.remove('platform_conf')
|
||||||
|
|
||||||
assert bootstrap._setup_component(self.hass, 'platform_conf', {
|
assert bootstrap._setup_component(self.hass, 'platform_conf', {
|
||||||
'platform_conf': [{
|
'platform_conf': [{
|
||||||
'platform': 'whatever',
|
'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):
|
def test_component_not_found(self):
|
||||||
"""setup_component should not crash if component doesn't exist."""
|
"""setup_component should not crash if component doesn't exist."""
|
||||||
assert not bootstrap.setup_component(self.hass, 'non_existing')
|
assert not bootstrap.setup_component(self.hass, 'non_existing')
|
||||||
|
|
Loading…
Reference in New Issue