Allow platforms to specify PLATFORM_SCHEMA
This commit is contained in:
parent
4fba89b789
commit
f6d584af09
5 changed files with 86 additions and 21 deletions
|
@ -165,11 +165,14 @@ class TestBootstrap:
|
|||
"""Test validating platform configuration."""
|
||||
platform_schema = PLATFORM_SCHEMA.extend({
|
||||
'hello': str,
|
||||
}, required=True)
|
||||
})
|
||||
loader.set_component(
|
||||
'platform_conf',
|
||||
MockModule('platform_conf', platform_schema=platform_schema))
|
||||
|
||||
loader.set_component(
|
||||
'platform_conf.whatever', MockPlatform('whatever'))
|
||||
|
||||
assert not bootstrap._setup_component(self.hass, 'platform_conf', {
|
||||
'platform_conf': None
|
||||
})
|
||||
|
@ -196,6 +199,13 @@ class TestBootstrap:
|
|||
}
|
||||
})
|
||||
|
||||
assert not bootstrap._setup_component(self.hass, 'platform_conf', {
|
||||
'platform_conf': {
|
||||
'platform': 'not_existing',
|
||||
'hello': 'world',
|
||||
}
|
||||
})
|
||||
|
||||
assert bootstrap._setup_component(self.hass, 'platform_conf', {
|
||||
'platform_conf': {
|
||||
'platform': 'whatever',
|
||||
|
@ -318,7 +328,7 @@ class TestBootstrap:
|
|||
loader.set_component('switch.platform_a', MockPlatform('comp_b',
|
||||
['comp_a']))
|
||||
|
||||
assert bootstrap.setup_component(self.hass, 'switch', {
|
||||
bootstrap.setup_component(self.hass, 'switch', {
|
||||
'comp_a': {
|
||||
'valid': True
|
||||
},
|
||||
|
@ -327,3 +337,36 @@ class TestBootstrap:
|
|||
}
|
||||
})
|
||||
assert 'comp_a' in self.hass.config.components
|
||||
|
||||
def test_platform_specific_config_validation(self):
|
||||
"""Test platform that specifies config."""
|
||||
|
||||
platform_schema = PLATFORM_SCHEMA.extend({
|
||||
'valid': True,
|
||||
}, extra=vol.PREVENT_EXTRA)
|
||||
|
||||
loader.set_component(
|
||||
'switch.platform_a',
|
||||
MockPlatform('comp_b', platform_schema=platform_schema))
|
||||
|
||||
assert not bootstrap.setup_component(self.hass, 'switch', {
|
||||
'switch': {
|
||||
'platform': 'platform_a',
|
||||
'invalid': True
|
||||
}
|
||||
})
|
||||
|
||||
assert not bootstrap.setup_component(self.hass, 'switch', {
|
||||
'switch': {
|
||||
'platform': 'platform_a',
|
||||
'valid': True,
|
||||
'invalid_extra': True,
|
||||
}
|
||||
})
|
||||
|
||||
assert bootstrap.setup_component(self.hass, 'switch', {
|
||||
'switch': {
|
||||
'platform': 'platform_a',
|
||||
'valid': True
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue