You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just found some strange behaviour when using the event_trigger.
Having somehting like this:
@event_trigger("some_event", "action == 'some_action' and state=='finished'") def dummy(**kwargs): log.debug(f"{kwargs}")
a and triggering the event with event.fire("some_event") leads to the correct result - the function dummy isn't called and thus no log output.
Triggering the event with event.fire("some_event", action="some_action",state="finished") also works correctly and leads to a log output like this: {'trigger_type': 'event', 'event_type': 'some_event', 'context': <homeassistant.core.Context object at 0x7f7ced65ab40>, 'action': 'some_action', 'state': 'finished'}
BUT, each subsequent event without any arguements (event.fire("some_event")) now also triggers the function and shows an output like this: {'trigger_type': 'event', 'event_type': 'some_event', 'context': <homeassistant.core.Context object at 0x7f7ce9657e00>}
It seems the the str_expr of @event_trigger is not evaluated anymore. Giving some random arguments to the event like this event.fire("some_event", x="s")
also triggers the function.
But providing at least one of the arguments to be checked in the str_expr like here event.fire("some_event", action="s")
prevents the function from being called.
Thats pretty strange. I would expect the str_expr to return false if the arguments are not provided in the event instead of ingoring this and evaluating to true.
The text was updated successfully, but these errors were encountered:
Michael-CGN
changed the title
Strane behaviour of @event_trigger
Strange behaviour of @event_trigger
Feb 23, 2023
Thanks for the clear explanation - it's definitely a bug. Each event trigger creates a context for evaluating the expression, and the local symbol table is simply updated (not replaced) each time with the event parameters. Fix is to replace the local symbol table each time the expression is evaluated.
Thanks for the quick response and the bugfix. And a really BIG thank you for this amazing tool. Without pyscript home assistant would be useless for me :-)
Hi,
I just found some strange behaviour when using the event_trigger.
Having somehting like this:
@event_trigger("some_event", "action == 'some_action' and state=='finished'") def dummy(**kwargs): log.debug(f"{kwargs}")
a and triggering the event with
event.fire("some_event")
leads to the correct result - the function dummy isn't called and thus no log output.Triggering the event with
event.fire("some_event", action="some_action",state="finished")
also works correctly and leads to a log output like this:{'trigger_type': 'event', 'event_type': 'some_event', 'context': <homeassistant.core.Context object at 0x7f7ced65ab40>, 'action': 'some_action', 'state': 'finished'}
BUT, each subsequent event without any arguements (
event.fire("some_event")
) now also triggers the function and shows an output like this:{'trigger_type': 'event', 'event_type': 'some_event', 'context': <homeassistant.core.Context object at 0x7f7ce9657e00>}
It seems the the str_expr of @event_trigger is not evaluated anymore. Giving some random arguments to the event like this
event.fire("some_event", x="s")
also triggers the function.
But providing at least one of the arguments to be checked in the str_expr like here
event.fire("some_event", action="s")
prevents the function from being called.
Thats pretty strange. I would expect the str_expr to return false if the arguments are not provided in the event instead of ingoring this and evaluating to true.
The text was updated successfully, but these errors were encountered: