1
mirror of https://github.com/home-assistant/core synced 2024-09-28 03:04:04 +02:00

Fix rest schema (#81857)

This commit is contained in:
epenet 2022-11-11 17:08:26 +01:00 committed by GitHub
parent b5dfe8c6b9
commit 1baa5c12c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -91,9 +91,8 @@ COMBINED_SCHEMA = vol.Schema(
CONFIG_SCHEMA = vol.Schema(
{
DOMAIN: vol.All(
# convert empty dict to empty list
lambda x: [] if x == {} else x,
cv.ensure_list,
cv.remove_falsy,
[COMBINED_SCHEMA],
)
},

View File

@ -418,3 +418,19 @@ async def test_empty_config(hass: HomeAssistant) -> None:
{DOMAIN: {}},
)
assert_setup_component(0, DOMAIN)
async def test_config_schema_via_packages(hass: HomeAssistant) -> None:
"""Test configuration via packages."""
packages = {
"pack_dict": {"rest": {}},
"pack_11": {"rest": {"resource": "http://url1"}},
"pack_list": {"rest": [{"resource": "http://url2"}]},
}
config = {hass_config.CONF_CORE: {hass_config.CONF_PACKAGES: packages}}
await hass_config.merge_packages_config(hass, config, packages)
assert len(config) == 2
assert len(config["rest"]) == 2
assert config["rest"][0]["resource"] == "http://url1"
assert config["rest"][1]["resource"] == "http://url2"