custom-components / pyscript

Pyscript adds rich Python scripting to HASS
Apache License 2.0
874 stars 46 forks source link

Disabling scripts via # leading character does not happen on reload #404

Closed mattokar closed 1 year ago

mattokar commented 1 year ago

Renaming light.py in scripts to #light.py does not disable this automation on reload. Only when I restart HA.

ALERTua commented 1 year ago

can you specify the full path to the script you want to disable? I just tested, renaming /config/pyscript/my_script.py to /config/pyscript/#my_script.py instantly disabled all automations described in it.

mattokar commented 1 year ago

/storage/docker/ha/config/pyscript/scripts/#toiletLight.py

mattokar commented 1 year ago

I just tested again. These are logs:

2022-11-19 15:18:22.618 INFO (MainThread) [custom_components.pyscript.global_ctx] Loaded /config/pyscript/scripts/toilietLight.py
2022-11-19 15:18:35.143 INFO (MainThread) [custom_components.pyscript.modules.lighting.handle_lights] Motion detected by binary_sensor.toilet_sensor_occupancy
2022-11-19 15:18:35.144 INFO (MainThread) [custom_components.pyscript.modules.lighting.handle_lights] Turning on the light switch.toilet_switch_light
2022-11-19 15:19:28.727 INFO (MainThread) [custom_components.pyscript.modules.lighting.handle_lights] Turning off the light switch.toilet_switch_light
2022-11-19 15:19:47.882 INFO (MainThread) [custom_components.pyscript] Unloaded /config/pyscript/scripts/toilietLight.py
2022-11-19 15:19:58.299 INFO (MainThread) [custom_components.pyscript.modules.lighting.handle_lights] Motion detected by binary_sensor.toilet_sensor_occupancy
2022-11-19 15:19:58.299 INFO (MainThread) [custom_components.pyscript.modules.lighting.handle_lights] Turning on the light switch.toilet_switch_light
2022-11-19 15:20:47.691 INFO (MainThread) [custom_components.pyscript.modules.lighting.handle_lights] Turning off the light switch.toilet_switch_light

I tried 3 minutes later around 15:22 and lights did not turned on, also no logs are present. Seems like unloading takes some time and script is active for few seconds only?

craigbarratt commented 1 year ago

The unloading and disabling of all triggers in the script context should be immediate. To debug this it would be helpful to have a small, self-contained example that shows the problem (eg, I don't know how the lighting module creates the triggers and how light.py calls that module).

ALERTua commented 1 year ago

@matustokar could you please update or close the issue? Thank you