pyscript
pyscript copied to clipboard
kwargs for subsequent state triggers includes kwargs from previous trigger
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
@craigbarratt Any thoughts regarding this?
Sorry about the delay. Definitely a bug - thanks for reporting. Just pushed a fix 7a81413.