-
Notifications
You must be signed in to change notification settings - Fork 58
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
I've written some custom trigger decorators which wrap around the built-in triggers, like so:
# 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 custom_triggers.py
rather than the calling class file. This means that if I make a code change to garage_button_press
in the example above, it will reload garage.py
but not custom_triggers.py
, and as a result, duplicate trigger bindings will exist (one before the code change, one after).
I'm not clear why the bindings end up living in custom_triggers.py
, but that wouldn't be a problem if I could force all scripts to reload everytime one of them changes.
Alternatively, perhaps there's a more elegant way I could create my trigger wrapper which would cause the binding to live within garage.py
instead?
Beta Was this translation helpful? Give feedback.
All reactions
Ok, should be fixed with cb980a9.
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.
All reactions
-
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 touch custom_triggers.py
to force it to reload.
Beta Was this translation helpful? Give feedback.
All reactions
-
I opened issue #457.
Beta Was this translation helpful? Give feedback.
All reactions
-
Ok, should be fixed with cb980a9.
Beta Was this translation helpful? Give feedback.
All reactions
-
Amazing!! Thanks Craig, this will unlock some cool stuff.
Beta Was this translation helpful? Give feedback.