Support templating for in state conditions (#88411)

This commit is contained in:
Erik Montnemery 2023-02-20 18:57:00 +01:00 committed by GitHub
parent 0b81c836ef
commit cc4a179ca8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 173 additions and 49 deletions

View file

@ -1376,3 +1376,28 @@ def test_language() -> None:
for value in ("en", "sv"):
assert schema(value)
def test_positive_time_period_template() -> None:
"""Test positive time period template validation."""
schema = vol.Schema(cv.positive_time_period_template)
with pytest.raises(vol.MultipleInvalid):
schema({})
with pytest.raises(vol.MultipleInvalid):
schema({5: 5})
with pytest.raises(vol.MultipleInvalid):
schema({"invalid": 5})
with pytest.raises(vol.MultipleInvalid):
schema("invalid")
# Time periods pass
schema("00:01")
schema("00:00:01")
schema("00:00:00.500")
schema({"minutes": 5})
# Templates are not evaluated and will pass
schema("{{ 'invalid' }}")
schema({"{{ 'invalid' }}": 5})
schema({"minutes": "{{ 'invalid' }}"})