Add entity_namespace to PLATFORM_SCHEMA (#20693)
* Add entity_namespace to base platform schema * Add test * Fixpull/20794/head
parent
b669e1498a
commit
4255f2c62f
|
@ -16,7 +16,7 @@ from homeassistant.const import (
|
|||
CONF_ALIAS, CONF_ENTITY_ID, CONF_VALUE_TEMPLATE, WEEKDAYS,
|
||||
CONF_CONDITION, CONF_BELOW, CONF_ABOVE, CONF_TIMEOUT, SUN_EVENT_SUNSET,
|
||||
SUN_EVENT_SUNRISE, CONF_UNIT_SYSTEM_IMPERIAL, CONF_UNIT_SYSTEM_METRIC,
|
||||
ENTITY_MATCH_ALL)
|
||||
ENTITY_MATCH_ALL, CONF_ENTITY_NAMESPACE)
|
||||
from homeassistant.core import valid_entity_id, split_entity_id
|
||||
from homeassistant.exceptions import TemplateError
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
@ -554,12 +554,14 @@ def key_dependency(key, dependency):
|
|||
|
||||
PLATFORM_SCHEMA = vol.Schema({
|
||||
vol.Required(CONF_PLATFORM): string,
|
||||
vol.Optional(CONF_ENTITY_NAMESPACE): string,
|
||||
vol.Optional(CONF_SCAN_INTERVAL): time_period
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
# This will replace PLATFORM_SCHEMA once all base components are updated
|
||||
PLATFORM_SCHEMA_2 = vol.Schema({
|
||||
vol.Required(CONF_PLATFORM): string,
|
||||
vol.Optional(CONF_ENTITY_NAMESPACE): string,
|
||||
vol.Optional(CONF_SCAN_INTERVAL): time_period
|
||||
})
|
||||
|
||||
|
|
|
@ -259,6 +259,7 @@ class TestSetup:
|
|||
assert setup.setup_component(self.hass, 'platform_conf', {
|
||||
'platform_conf': {
|
||||
# fail: no extra keys allowed
|
||||
'platform': 'whatever',
|
||||
'hello': 'world',
|
||||
'invalid': 'extra',
|
||||
}
|
||||
|
@ -284,6 +285,34 @@ class TestSetup:
|
|||
self.hass.data.pop(setup.DATA_SETUP)
|
||||
self.hass.config.components.remove('platform_conf')
|
||||
|
||||
def test_validate_platform_config_4(self):
|
||||
"""Test entity_namespace in PLATFORM_SCHEMA."""
|
||||
component_schema = PLATFORM_SCHEMA_BASE
|
||||
platform_schema = PLATFORM_SCHEMA
|
||||
loader.set_component(
|
||||
self.hass,
|
||||
'platform_conf',
|
||||
MockModule('platform_conf',
|
||||
platform_schema_base=component_schema))
|
||||
|
||||
loader.set_component(
|
||||
self.hass,
|
||||
'platform_conf.whatever',
|
||||
MockPlatform('whatever',
|
||||
platform_schema=platform_schema))
|
||||
|
||||
with assert_setup_component(1):
|
||||
assert setup.setup_component(self.hass, 'platform_conf', {
|
||||
'platform_conf': {
|
||||
# pass: entity_namespace accepted by PLATFORM_SCHEMA
|
||||
'platform': 'whatever',
|
||||
'entity_namespace': 'yummy',
|
||||
}
|
||||
})
|
||||
|
||||
self.hass.data.pop(setup.DATA_SETUP)
|
||||
self.hass.config.components.remove('platform_conf')
|
||||
|
||||
def test_component_not_found(self):
|
||||
"""setup_component should not crash if component doesn't exist."""
|
||||
assert not setup.setup_component(self.hass, 'non_existing')
|
||||
|
|
Loading…
Reference in New Issue