Open cjlapao opened 2 months ago
Possible race condition related to my issue #647 ? You can try instantiating f1 and f2 within the below function so they will be made on boot and after everything else is loaded, or for testing try tying them to a button through state trigger. It's the bare calls in the body of the file that may be the issue here.
@time_trigger
def run_on_startup_or_reload():
"""This function runs automatically once on startup or reload"""
pass
Adding them here
@time_trigger
def run_on_startup_or_reload():
log.debug("Running on startup or reload")
"""This function runs automatically once on startup or reload"""
f1 = on_change_from_within("light.office_wall_leds")
f2 = trigger_factory_test("light.office_wall_leds")
pass
then it makes even the one in the test_dev.py that used to work to fail The file is being correctly loaded as I added another one
@state_trigger("light.office_wall_leds")
def on_change_from_state(**args):
log.debug(f"{id} changed: {args} from_state")
In the test_dev.py and this is working
Even from a button it does not change the outcome
@state_trigger(development_button)
def switch_state_changed(**args):
log.debug(f"Button was pressed: {args}")
context = args["context"]
value = args["value"]
if value == "on_press":
run_on_startup_or_reload()
if value == "off_press":
pass
if value == "up_press":
pass
if value == "down_press":
pass
I am trying to write a module that contains some boilerplate code for state_triggers that I wan to call from some other files. If I define the factory in a module, the state seems to be set by the looks of the logs but it is never triggered. now if I define the same factory in the file I am calling then this is working as expected.
On my example I created these two files:
test_trigger.py
inside the modules folder andtest_dev.py
in the pyscript foldercontent of
test_trigger.py
and the test_dev.py
when the light changes state I see the change on f1 but not from f2, even if I commented out the f1
Do I need to use apps for this?