From 4255f2c62fe924f579f9971655c4eda5cdf89e80 Mon Sep 17 00:00:00 2001 From: emontnemery Date: Sat, 2 Feb 2019 18:31:28 +0100 Subject: [PATCH] Add entity_namespace to PLATFORM_SCHEMA (#20693) * Add entity_namespace to base platform schema * Add test * Fix --- homeassistant/helpers/config_validation.py | 4 ++- tests/test_setup.py | 29 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/homeassistant/helpers/config_validation.py b/homeassistant/helpers/config_validation.py index f3371a26725..b148a875398 100644 --- a/homeassistant/helpers/config_validation.py +++ b/homeassistant/helpers/config_validation.py @@ -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 }) diff --git a/tests/test_setup.py b/tests/test_setup.py index 6d2cc770013..6d0d2a35847 100644 --- a/tests/test_setup.py +++ b/tests/test_setup.py @@ -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')