Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow split component definitions in packages #16177

Merged
merged 2 commits into from
Sep 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions homeassistant/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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")
Expand Down
18 changes: 18 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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