Skip to content

Strange behaviour of @event_trigger #439

Closed
@Michael-CGN

Description

@Michael-CGN

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions