Closed
Description
Methods decorated with @time_trigger('shutdown')
should be run:
- When Home Assistant is shutting down
- Any time a script/app is reloaded (either all shutdown methods, or those in a specific global context if reload is called with one)
- When implemented, if Feature Request: Automatic reloading for existing scripts? #74 detects a deleted or commented out file, it should run
shutdown
for that global context before unloading the script. - Basically, any time the methods in that context will either not be loaded again or if the next step is to run
startup
again.
Use Case:
This is mostly for cleanup tasks.
If there is a script that, say, counts the number of lights on and reports it in pyscript.lights_on_count, the shutdown
function could send "unavailable" as the state letting the rest of the system know that this sensor is no longer being updated.
Any method that doesn't execute and complete immediately could be cleaned up with this. For instance:
@time_trigger('startup')
def counter():
task.unique('counter')
cnt = 0
while True:
log.info(cnt)
task.sleep(1)
Even if this method is commented out and reload is called, the script continues to count. A shutdown like this:
@time_trigger('shutdown')
def stop_counter():
task.unique('counter')
log.info('stopping counter')
would be able to stop the counter if this was desired.
If an async connection is made to another server, that connection could be closed.
Metadata
Metadata
Assignees
Labels
No labels