Add domain key config validation (#104242)

* Drop use of regex in helpers.extract_domain_configs

* Update test

* Revert test update

* Add domain_from_config_key helper

* Add validator

* Address review comment

* Update snapshots

* Inline domain_from_config_key in validator
This commit is contained in:
Erik Montnemery 2023-12-05 15:07:32 +01:00 committed by GitHub
parent 25bea91683
commit 3bcc6194ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 144 additions and 9 deletions

View file

@ -1631,3 +1631,19 @@ def test_platform_only_schema(
cv.platform_only_config_schema("test_domain")({"test_domain": {"foo": "bar"}})
assert expected_message in caplog.text
assert issue_registry.async_get_issue(HOMEASSISTANT_DOMAIN, expected_issue)
def test_domain() -> None:
"""Test domain."""
with pytest.raises(vol.Invalid):
cv.domain_key(5)
with pytest.raises(vol.Invalid):
cv.domain_key("")
with pytest.raises(vol.Invalid):
cv.domain_key("hue ")
with pytest.raises(vol.Invalid):
cv.domain_key("hue ")
assert cv.domain_key("hue") == "hue"
assert cv.domain_key("hue1") == "hue1"
assert cv.domain_key("hue 1") == "hue"
assert cv.domain_key("hue 1") == "hue"