Skip to content

kwargs for subsequent state triggers includes kwargs from previous trigger #512

Open
@rajeee

Description

@rajeee

When I define two function with the same state trigger source, the kwargs for the second trigger definition is merged with the first trigger definition and this leads to run time error. MVE below:

@state_trigger("pyscript.flag == 'on'", kwargs={"my_val": 'on'})
def print_flag(my_val):
    log.info(f"flag changed to: {my_val}")

@state_trigger("pyscript.flag == 'on'",  kwargs={"my_name": 'flag'})
def print_flag2(my_name):
    log.info(f"{my_name} has been turned on")
 
pyscript.flag = "off"
pyscript.flag = "on"

Only prints:

flag changed to: on

The log file shows:

2023-08-09 09:22:03.857 DEBUG (MainThread) [custom_components.pyscript.eval] jupyter_10.print_flag2: calling print_flag2(, {'trigger_type': 'state', 'var_name': 'pyscript.flag', 'value': 'on', 'old_value': 'off', 'context': <homeassistant.core.Context object at 0x7f4d6e5710>, 'my_val': 'on', 'my_name': 'flag'})
2023-08-09 09:22:03.858 ERROR (MainThread) [custom_components.pyscript.function] run_coro: got exception Traceback (most recent call last):
  File "/config/custom_components/pyscript/eval.py", line 726, in call
    raise TypeError(f"{self.name}() called with unexpected keyword arguments: {unexpected}")
TypeError: print_flag2() called with unexpected keyword arguments: my_val

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