Closed
Description
Trigger registers twice when using decorator in a module.
Test code
modules/dec_test.py:
def startup_with_note(note):
def inner_dec(func):
nonlocal note
@time_trigger('startup')
def inner(*args, **kwargs):
nonlocal note
log.info(f"NOTE: {note}")
return func(*args, **kwargs)
return inner
return inner_dec
script file:
import dec_test
@dec_test.startup_with_note('this is the note 1')
def at_startup():
log.info('startup 1')
logs:
2020-12-26 07:51:48 INFO (MainThread) [custom_components.pyscript.global_ctx] Reloaded /config/pyscript/scripts/test/dec_test_script.py
2020-12-26 07:51:48 INFO (MainThread) [custom_components.pyscript.modules.dec_test.inner] NOTE: this is the note 1
2020-12-26 07:51:48 INFO (MainThread) [custom_components.pyscript.modules.dec_test.inner] startup 1
2020-12-26 07:51:48 INFO (MainThread) [custom_components.pyscript.modules.dec_test.inner] NOTE: this is the note 1
2020-12-26 07:51:48 INFO (MainThread) [custom_components.pyscript.modules.dec_test.inner] startup 1
Moving the function out of the module and into the script file makes the log lines only show once.
Metadata
Metadata
Assignees
Labels
No labels