Fix disabled condition within an automation action (#87213)

fixes undefined
This commit is contained in:
Karlie Meads 2023-02-02 16:35:02 -05:00 committed by GitHub
parent 11cb6b131f
commit e40a9822f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 1 deletions

View File

@ -757,7 +757,7 @@ class _ScriptRun:
with trace_path(condition_path):
for idx, cond in enumerate(conditions):
with trace_path(str(idx)):
if not cond(hass, variables):
if cond(hass, variables) is False:
return False
except exceptions.ConditionError as ex:
_LOGGER.warning("Error in '%s[%s]' evaluation: %s", name, idx, ex)

View File

@ -2915,6 +2915,45 @@ async def test_if(
assert_action_trace(expected_trace)
async def test_if_disabled(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test if action with a disabled condition."""
sequence = cv.SCRIPT_SCHEMA(
{
"if": {
"alias": "if condition",
"condition": "template",
"value_template": "{{ var == 1 }}",
"enabled": "false",
},
"then": {
"alias": "if then",
"event": "test_event",
"event_data": {"if": "then"},
},
"else": {
"alias": "if else",
"event": "test_event",
"event_data": {"if": "else"},
},
}
)
script_obj = script.Script(hass, sequence, "Test Name", "test_domain")
await script_obj.async_run(context=Context())
await hass.async_block_till_done()
expected_trace = {
"0": [{"result": {"choice": "then"}}],
"0/if": [{"result": {"result": True}}],
"0/if/condition/0": [{"result": {"result": None}}],
"0/then/0": [{"result": {"event": "test_event", "event_data": {"if": "then"}}}],
}
assert_action_trace(expected_trace)
async def test_if_condition_validation(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None: