pyscript icon indicating copy to clipboard operation
pyscript copied to clipboard

kwargs for subsequent state triggers includes kwargs from previous trigger

Open rajeee opened this issue 2 years ago • 2 comments

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

rajeee avatar Aug 09 '23 14:08 rajeee

@craigbarratt Any thoughts regarding this?

rajeee avatar Aug 15 '23 13:08 rajeee

Sorry about the delay. Definitely a bug - thanks for reporting. Just pushed a fix 7a81413.

craigbarratt avatar Aug 15 '23 17:08 craigbarratt