Always reload all scripts? (Issue with custom decorators) #428
-
Is there a YAML config command that will force Pyscript to always reload all scripts, not just the script(s) that were changed? Context # file: custom_triggers.py
def zha_trigger(device_ieee, command=None):
def trigger_builder(func):
event_command_suffix = '' if not command else f' and command = "{command}"'
@event_trigger('zha_event', f'device_ieee=="{device_ieee}" {event_command_suffix}')
def event_trigger(**kwargs):
func(**kwargs)
return event_trigger
return trigger_builder I can use them like this: # file: garage.py
@zha_trigger('04:23:a1:b4:e2:23', 'toggle')
def garage_button_press(**kwargs):
pass These work perfectly! But the problem is that the triggers themselves are bound within I'm not clear why the bindings end up living in Alternatively, perhaps there's a more elegant way I could create my trigger wrapper which would cause the binding to live within |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
I hit the same issue myself. The only solution I found was to call "pyscript.reload" from the UI with global_ctx="*". I attempted to call this at the top of my relevant pyscript files in various forms, but it always seemed to end up in a continuous loop. If anyone has a better solution, I'd LOVE to hear it. I wonder if this could be considered a bug (bindings not reloading) and an issue should be opened. |
Beta Was this translation helpful? Give feedback.
-
Sorry I didn't see this earlier. This is definitely a bug - the trigger should be bound to the garage's context, not where the decorator is defined. The internals that implement this are pretty tricky - let me see how easy it is to fix it. Feel free to open as issue, or I can do it once I figure out how to fix it 😀. In the meantime, you could |
Beta Was this translation helpful? Give feedback.
-
I opened issue #457. |
Beta Was this translation helpful? Give feedback.
-
Ok, should be fixed with cb980a9. |
Beta Was this translation helpful? Give feedback.
-
Amazing!! Thanks Craig, this will unlock some cool stuff. |
Beta Was this translation helpful? Give feedback.
Ok, should be fixed with cb980a9.