Add shorthand notation for boolean conditions (#70120)

This commit is contained in:
Thomas Lovén 2022-04-18 22:09:09 +02:00 committed by GitHub
parent 8f4979ea17
commit b50f369fe4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 314 additions and 32 deletions

View file

@ -1508,6 +1508,42 @@ async def test_condition_basic(hass, caplog):
)
async def test_and_default_condition(hass, caplog):
"""Test that a list of conditions evaluates as AND."""
alias = "condition step"
sequence = cv.SCRIPT_SCHEMA(
[
{
"alias": alias,
"condition": [
{
"condition": "template",
"value_template": "{{ states.test.entity.state == 'hello' }}",
},
{
"condition": "numeric_state",
"entity_id": "sensor.temperature",
"below": 110,
},
],
},
]
)
script_obj = script.Script(hass, sequence, "Test Name", "test_domain")
hass.states.async_set("sensor.temperature", 100)
hass.states.async_set("test.entity", "hello")
await script_obj.async_run(context=Context())
await hass.async_block_till_done()
assert f"Test condition {alias}: True" in caplog.text
caplog.clear()
hass.states.async_set("sensor.temperature", 120)
await script_obj.async_run(context=Context())
await hass.async_block_till_done()
assert f"Test condition {alias}: False" in caplog.text
async def test_shorthand_template_condition(hass, caplog):
"""Test if we can use shorthand template conditions in a script."""
event = "test_event"