1
0
mirror of https://github.com/home-assistant/supervisor.git synced 2025-12-24 04:19:03 +00:00
Files
supervisor/hassio/core.py
Pascal Vizeli 1c49351e66 Refactory code / object handling (#289)
* Refactory code / object handling

* Next step

* fix lint

* Step 2

* Cleanup API code

* cleanup addons code

* cleanup data handling

* Cleanup addons data handling

* Cleanup docker api

* clean docker api p2

* next cleanup round

* cleanup start on snapshots

* update format strings

* fix setup

* fix lint

* fix lint

* fix lint

* fix tox

* Fix wrong import of datetime module

* Fix bug with attributes

* fix extraction

* Update core

* Update logs

* Expand scheduler

* add support for time interval objects

* next updates on tasks

* Fix some things

* Cleanup code / supervisor

* fix lint

* Fix some code styles

* rename stuff

* cleanup api call reload

* fix lock replacment

* fix lint

* fix lint

* fix bug

* fix wrong config links

* fix bugs

* fix bug

* Update version on startup

* Fix some bugs

* fix bug

* Fix snapshot

* Add wait boot options

* fix lint

* fix default config

* fix snapshot

* fix snapshot

* load snapshots on startup

* add log message at the end

* Some cleanups

* fix bug

* add logger

* add logger for supervisor update

* Add more logger
2018-01-02 21:21:29 +01:00

110 lines
3.2 KiB
Python

"""Main file for HassIO."""
import asyncio
import logging
from .coresys import CoreSysAttributes
from .const import (
STARTUP_SYSTEM, STARTUP_SERVICES, STARTUP_APPLICATION, STARTUP_INITIALIZE)
from .utils.dt import fetch_timezone
_LOGGER = logging.getLogger(__name__)
class HassIO(CoreSysAttributes):
"""Main object of hassio."""
def __init__(self, coresys):
"""Initialize hassio object."""
self.coresys = coresys
async def setup(self):
"""Setup HassIO orchestration."""
# update timezone
if self._config.timezone == 'UTC':
self._config.timezone = await fetch_timezone(self._websession)
# supervisor
await self._supervisor.load()
# hostcontrol
await self._host_control.load()
# Load homeassistant
await self._homeassistant.load()
# Load addons
await self._addons.load()
# rest api views
await self._api.load()
# load last available data
await self._updater.load()
# load last available data
await self._snapshots.load()
# start dns forwarding
self._loop.create_task(self._dns.start())
# start addon mark as initialize
await self._addons.auto_boot(STARTUP_INITIALIZE)
async def start(self):
"""Start HassIO orchestration."""
# on release channel, try update itself
# on beta channel, only read new versions
if not self._updater.beta_channel:
await self._supervisor.update()
else:
_LOGGER.info("Ignore Hass.io auto updates on beta mode")
# start api
await self._api.start()
_LOGGER.info("Start API on %s", self._docker.network.supervisor)
try:
# HomeAssistant is already running / supervisor have only reboot
if self._hardware.last_boot == self._config.last_boot:
_LOGGER.info("Hass.io reboot detected")
return
# start addon mark as system
await self._addons.auto_boot(STARTUP_SYSTEM)
# start addon mark as services
await self._addons.auto_boot(STARTUP_SERVICES)
# run HomeAssistant
if self._homeassistant.boot:
await self._homeassistant.run()
# start addon mark as application
await self._addons.auto_boot(STARTUP_APPLICATION)
# store new last boot
self._config.last_boot = self._hardware.last_boot
finally:
# Add core tasks into scheduler
await self._tasks.load()
# If landingpage / run upgrade in background
if self._homeassistant.version == 'landingpage':
self._loop.create_task(self._homeassistant.install())
_LOGGER.info("Hass.io is up and running")
async def stop(self):
"""Stop a running orchestration."""
# don't process scheduler anymore
self._scheduler.suspend = True
# process stop tasks
self._websession.close()
self._websession_ssl.close()
# process async stop tasks
await asyncio.wait(
[self._api.stop(), self._dns.stop()], loop=self._loop)