From 489c5b8188d1d1ff06608f50315577156b35a1c9 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Thu, 31 Mar 2016 21:11:14 -0700 Subject: [PATCH] bootstrap platform components: adjust instead of replace config --- homeassistant/bootstrap.py | 9 +++++++-- tests/test_bootstrap.py | 27 ++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/homeassistant/bootstrap.py b/homeassistant/bootstrap.py index 2545960dd75..ea7dd7765fc 100644 --- a/homeassistant/bootstrap.py +++ b/homeassistant/bootstrap.py @@ -23,7 +23,7 @@ from homeassistant.const import ( CONF_TEMPERATURE_UNIT, CONF_TIME_ZONE, EVENT_COMPONENT_LOADED, TEMP_CELCIUS, TEMP_FAHRENHEIT, __version__) from homeassistant.helpers import ( - event_decorators, service, config_per_platform) + event_decorators, service, config_per_platform, extract_domain_configs) from homeassistant.helpers.entity import Entity _LOGGER = logging.getLogger(__name__) @@ -116,7 +116,12 @@ def _setup_component(hass, domain, config): domain, ex, platform) return False - config = {domain: platforms} + # Create a copy of the configuration with all config for current + # component removed and add validated config back in. + filter_keys = extract_domain_configs(config, domain) + config = {key: value for key, value in config.items() + if key not in filter_keys} + config[domain] = platforms if not _handle_requirements(hass, component, domain): return False diff --git a/tests/test_bootstrap.py b/tests/test_bootstrap.py index d6a72fdd86e..4a50ae55393 100644 --- a/tests/test_bootstrap.py +++ b/tests/test_bootstrap.py @@ -14,7 +14,7 @@ import homeassistant.util.dt as dt_util from homeassistant.helpers.entity import Entity from homeassistant.helpers.config_validation import PLATFORM_SCHEMA -from tests.common import get_test_home_assistant, MockModule +from tests.common import get_test_home_assistant, MockModule, MockPlatform ORIG_TIMEZONE = dt_util.DEFAULT_TIME_ZONE @@ -302,3 +302,28 @@ class TestBootstrap: } }) assert not mock_process.called + + def test_component_setup_with_validation_and_dependency(self): + """Test all config is passed to dependencies.""" + + def config_check_setup(hass, config): + """Setup method that tests config is passed in.""" + if config.get('comp_a', {}).get('valid', False): + return True + raise Exception('Config not passed in: {}'.format(config)) + + loader.set_component('comp_a', + MockModule('comp_a', setup=config_check_setup)) + + loader.set_component('switch.platform_a', MockPlatform('comp_b', + ['comp_a'])) + + assert bootstrap.setup_component(self.hass, 'switch', { + 'comp_a': { + 'valid': True + }, + 'switch': { + 'platform': 'platform_a', + } + }) + assert 'comp_a' in self.hass.config.components