mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-11-08 02:19:35 +00:00
* Add API layout for snapshot
* Update api
* Add support for export/import docker images
* Move restore into addon
* Add restore to addon
* Fix lint
* fix lint
* cleanup
* init object
* fix executor
* cleanup
* Change flow of init
* Revert "Change flow of init"
This reverts commit 6b3215e44c.
* allow restore from none
* forward working
* add size
* add context for snapshot
* add init function to set meta data
* update local addon on load
* add more validate and optimaze code
* Optimaze code for restore data
* add validate layer
* Add more function to snapshot / cleanup others
* finish snapshot function
* Cleanup config / optimaze code
* Finish snapshot on core
* Some improvments first object for api
* finish
* fix lint p1
* fix lint p2
* fix lint p3
* fix async with
* fix lint p4
* fix lint p5
* fix p6
* make staticmethod
* fix schema
* fix parse system data
* fix bugs
* fix get function
* extend snapshot/restore
* add type
* fix lint
* move to gz / xz is to slow
* move to gz / xz is to slow p2
* Fix config folder
* small compresslevel for more speed
* fix lint
* fix load
* fix tar stream
* fix tar stream p2
* fix parse
* fix partial
* fix start hass
* fix rep
* fix set
* fix real
* fix generator
* Cleanup old image
* add log
* fix lint
* fix lint p2
* fix load from tar
57 lines
1.3 KiB
Python
57 lines
1.3 KiB
Python
"""Schedule for HassIO."""
|
|
import logging
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
SEC = 'seconds'
|
|
REPEAT = 'repeat'
|
|
CALL = 'callback'
|
|
TASK = 'task'
|
|
|
|
|
|
class Scheduler(object):
|
|
"""Schedule task inside HassIO."""
|
|
|
|
def __init__(self, loop):
|
|
"""Initialize task schedule."""
|
|
self.loop = loop
|
|
self._data = {}
|
|
self.suspend = False
|
|
|
|
def register_task(self, coro_callback, seconds, repeat=True,
|
|
now=False):
|
|
"""Schedule a coroutine.
|
|
|
|
The coroutien need to be a callback without arguments.
|
|
"""
|
|
idx = hash(coro_callback)
|
|
|
|
# generate data
|
|
opts = {
|
|
CALL: coro_callback,
|
|
SEC: seconds,
|
|
REPEAT: repeat,
|
|
}
|
|
self._data[idx] = opts
|
|
|
|
# schedule task
|
|
if now:
|
|
self._run_task(idx)
|
|
else:
|
|
task = self.loop.call_later(seconds, self._run_task, idx)
|
|
self._data[idx][TASK] = task
|
|
|
|
return idx
|
|
|
|
def _run_task(self, idx):
|
|
"""Run a scheduled task."""
|
|
data = self._data.pop(idx)
|
|
|
|
if not self.suspend:
|
|
self.loop.create_task(data[CALL]())
|
|
|
|
if data[REPEAT]:
|
|
task = self.loop.call_later(data[SEC], self._run_task, idx)
|
|
data[TASK] = task
|
|
self._data[idx] = data
|