mirror of
https://github.com/home-assistant/core
synced 2024-10-04 07:58:43 +02:00
Fix disabled condition within an automation action (#87213)
fixes undefined
This commit is contained in:
parent
11cb6b131f
commit
e40a9822f5
@ -757,7 +757,7 @@ class _ScriptRun:
|
|||||||
with trace_path(condition_path):
|
with trace_path(condition_path):
|
||||||
for idx, cond in enumerate(conditions):
|
for idx, cond in enumerate(conditions):
|
||||||
with trace_path(str(idx)):
|
with trace_path(str(idx)):
|
||||||
if not cond(hass, variables):
|
if cond(hass, variables) is False:
|
||||||
return False
|
return False
|
||||||
except exceptions.ConditionError as ex:
|
except exceptions.ConditionError as ex:
|
||||||
_LOGGER.warning("Error in '%s[%s]' evaluation: %s", name, idx, ex)
|
_LOGGER.warning("Error in '%s[%s]' evaluation: %s", name, idx, ex)
|
||||||
|
@ -2915,6 +2915,45 @@ async def test_if(
|
|||||||
assert_action_trace(expected_trace)
|
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(
|
async def test_if_condition_validation(
|
||||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
) -> None:
|
) -> None:
|
||||||
|
Loading…
Reference in New Issue
Block a user