From 90ecd2e31cd7ce0ff19dec93e99d2fe41badf569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Lov=C3=A9n?= Date: Fri, 24 Aug 2018 20:39:37 +0200 Subject: [PATCH 1/2] Allow split component definitions in packages Two different configuration styles are described in https://www.home-assistant.io/docs/configuration/devices/#style-2-list-each-device-separately But only one is allowed in packages according to https://www.home-assistant.io/docs/configuration/packages/ This change allows "Style 2" configuration in packages. --- homeassistant/config.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/homeassistant/config.py b/homeassistant/config.py index 5474b283494e39..abcf027c49fe97 100644 --- a/homeassistant/config.py +++ b/homeassistant/config.py @@ -171,7 +171,7 @@ def _no_duplicate_auth_mfa_module(configs: Sequence[Dict[str, Any]]) \ PACKAGES_CONFIG_SCHEMA = vol.Schema({ cv.slug: vol.Schema( # Package names are slugs - {cv.slug: vol.Any(dict, list, None)}) # Only slugs for component names + {cv.string: vol.Any(dict, list, None)}) # Component configuration }) CUSTOMIZE_DICT_SCHEMA = vol.Schema({ @@ -662,7 +662,10 @@ def merge_packages_config(hass: HomeAssistant, config: Dict, packages: Dict, for comp_name, comp_conf in pack_conf.items(): if comp_name == CONF_CORE: continue - component = get_component(hass, comp_name) + # If component name is given with a trailing description, remove it + # when looking for component + domain = comp_name.split(' ')[0] + component = get_component(hass, domain) if component is None: _log_pkg_error(pack_name, comp_name, config, "does not exist") From e54bf0f7be40ed622d59060c00b987d0f876cb42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Lov=C3=A9n?= Date: Sun, 23 Sep 2018 21:02:37 +0200 Subject: [PATCH 2/2] Added test for split component definition in packages --- tests/test_config.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/test_config.py b/tests/test_config.py index e4a6798093ffbb..0e53bc0cdfb228 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -965,3 +965,21 @@ async def test_disallowed_duplicated_auth_mfa_module_config(hass): } with pytest.raises(Invalid): await config_util.async_process_ha_core_config(hass, core_config) + + +def test_merge_split_component_definition(hass): + """Test components with trailing description in packages are merged.""" + packages = { + 'pack_1': {'light one': {'l1': None}}, + 'pack_2': {'light two': {'l2': None}, + 'light three': {'l3': None}}, + } + config = { + config_util.CONF_CORE: {config_util.CONF_PACKAGES: packages}, + } + config_util.merge_packages_config(hass, config, packages) + + assert len(config) == 4 + assert len(config['light one']) == 1 + assert len(config['light two']) == 1 + assert len(config['light three']) == 1