From 41111a93c9c81fcfab4e00c36b465e3b8ada6e30 Mon Sep 17 00:00:00 2001 From: Dmitrii Amelin Date: Wed, 20 May 2026 00:04:39 +0200 Subject: [PATCH] fix state trigger hold on unrelated state updates --- .../pyscript/decorators/state.py | 2 +- tests/test_function.py | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/custom_components/pyscript/decorators/state.py b/custom_components/pyscript/decorators/state.py index 4c1b44a..f4adbec 100644 --- a/custom_components/pyscript/decorators/state.py +++ b/custom_components/pyscript/decorators/state.py @@ -281,7 +281,7 @@ async def _cycle(self) -> None: elif ident_values_changed(self.last_func_args, self.state_trig_ident): trig_ok = await self._is_trig_ok() else: - trig_ok = False + continue await self._check_new_state(trig_ok) except TimeoutError: await self._check_state_hold() diff --git a/tests/test_function.py b/tests/test_function.py index f87fbe1..b9f7b85 100644 --- a/tests/test_function.py +++ b/tests/test_function.py @@ -440,6 +440,13 @@ def func10d(var_name=None, value=None, trigger_type=None, context=None, old_valu log.info(f"func10d var = {var_name}, value = {value}, kwargs = {kwargs}") pyscript.done = [seq_num, var_name, kwargs] +@state_trigger("pyscript.f11var1 == 'playing'", state_hold=0.05) +def func11(var_name=None, value=None): + global seq_num + + seq_num += 1 + pyscript.done = [seq_num, var_name, value, pyscript.f11var1.position] + """, ) # initialize the trigger and active variables @@ -672,6 +679,19 @@ def func10d(var_name=None, value=None, trigger_type=None, context=None, old_valu hass.states.async_set("pyscript.f8bvar1", 30) hass.states.async_set("pyscript.f8bvar1", 31) + # + # check that state_hold isn't cancelled by unrelated attribute-only updates + # + seq_num += 1 + hass.states.async_set("pyscript.f11var1", "playing", {"position": 1}) + hass.states.async_set("pyscript.f11var1", "playing", {"position": 2}) + assert literal_eval(await wait_until_done(notify_q)) == [ + seq_num, + "pyscript.f11var1", + "playing", + 2, + ] + # # check that state_var.old is None first time #