Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rajeee opened this issue Aug 9, 2023 · 2 comments
Open

Comments

@rajeee
Copy link

rajeee commented Aug 9, 2023

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
Copy link
Author

rajeee commented Aug 15, 2023

@craigbarratt Any thoughts regarding this?

craigbarratt added a commit that referenced this issue Aug 15, 2023
@craigbarratt
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants