Fix script / automation repeat with count 0 fails (#65448)
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
parent
778cc6106a
commit
efb6fd1569
2 changed files with 39 additions and 1 deletions
|
@ -742,7 +742,7 @@ class _ScriptRun:
|
||||||
if saved_repeat_vars:
|
if saved_repeat_vars:
|
||||||
self._variables["repeat"] = saved_repeat_vars
|
self._variables["repeat"] = saved_repeat_vars
|
||||||
else:
|
else:
|
||||||
del self._variables["repeat"]
|
self._variables.pop("repeat", None) # Not set if count = 0
|
||||||
|
|
||||||
async def _async_choose_step(self) -> None:
|
async def _async_choose_step(self) -> None:
|
||||||
"""Choose a sequence."""
|
"""Choose a sequence."""
|
||||||
|
|
|
@ -1742,6 +1742,44 @@ async def test_repeat_count(hass, caplog, count):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_repeat_count_0(hass, caplog):
|
||||||
|
"""Test repeat action w/ count option."""
|
||||||
|
event = "test_event"
|
||||||
|
events = async_capture_events(hass, event)
|
||||||
|
count = 0
|
||||||
|
|
||||||
|
alias = "condition step"
|
||||||
|
sequence = cv.SCRIPT_SCHEMA(
|
||||||
|
{
|
||||||
|
"alias": alias,
|
||||||
|
"repeat": {
|
||||||
|
"count": count,
|
||||||
|
"sequence": {
|
||||||
|
"event": event,
|
||||||
|
"event_data_template": {
|
||||||
|
"first": "{{ repeat.first }}",
|
||||||
|
"index": "{{ repeat.index }}",
|
||||||
|
"last": "{{ repeat.last }}",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
script_obj = script.Script(hass, sequence, "Test Name", "test_domain")
|
||||||
|
|
||||||
|
await script_obj.async_run(context=Context())
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert len(events) == count
|
||||||
|
assert caplog.text.count(f"Repeating {alias}") == count
|
||||||
|
assert_action_trace(
|
||||||
|
{
|
||||||
|
"0": [{}],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("condition", ["while", "until"])
|
@pytest.mark.parametrize("condition", ["while", "until"])
|
||||||
async def test_repeat_condition_warning(hass, caplog, condition):
|
async def test_repeat_condition_warning(hass, caplog, condition):
|
||||||
"""Test warning on repeat conditions."""
|
"""Test warning on repeat conditions."""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue