From 490ea547f957147d1d814255a013419b16b2dfbc Mon Sep 17 00:00:00 2001 From: pvizeli Date: Mon, 27 Mar 2017 14:44:08 +0200 Subject: [PATCH] Fix last lint --- hassio_api/hassio/__main__.py | 49 +++++------------------------------ hassio_api/hassio/core.py | 47 +++++++++++++++++++++++++++++++++ hassio_api/setup.py | 2 +- 3 files changed, 54 insertions(+), 44 deletions(-) create mode 100644 hassio_api/hassio/core.py diff --git a/hassio_api/hassio/__main__.py b/hassio_api/hassio/__main__.py index e79719f18..0425fb94e 100644 --- a/hassio_api/hassio/__main__.py +++ b/hassio_api/hassio/__main__.py @@ -2,55 +2,18 @@ import asyncio import logging -import aiohttp -import docker - import hassio.bootstrap as bootstrap -import hassio.tools as tools -from hassio.const import CONF_HOMEASSISTANT_TAG -from hassio.docker.homeassistant import DockerHomeAssistant +import hassio.core as core _LOGGER = logging.getLogger(__name__) -async def main(loop): - """Start HassIO.""" +if __name__ == "__main__": bootstrap.initialize_logging() - # init asyncio & aiohttp client - websession = aiohttp.ClientSession(loop=loop) - dock = docker.Client(base_url='unix://var/run/docker.sock', version='auto') - - # init system - config = bootstrap.initialize_system_data() - - # init HomeAssistant Docker - docker_hass = DockerHomeAssistant( - config, loop, dock, config.homeassistant_image, - config.homeassistant_tag - ) - - # first start of supervisor? - if config.homeassistant_tag is None: - _LOGGER.info("First start of supervisor, read version from github.") - - # read homeassistant tag and install it - current = None - while True: - current = await tools.fetch_current_versions(websession) - if current and CONF_HOMEASSISTANT_TAG in current: - if await docker_hass.install(current[CONF_HOMEASSISTANT_TAG]): - break - _LOGGER.warning("Can't fetch info from github. Retry in 60") - await asyncio.sleep(60, loop=loop) - - config.homeassistant_tag = current[CONF_HOMEASSISTANT_TAG] - - # run HomeAssistant - await docker_hass.run() - - -if __name__ == "__main__": loop = asyncio.get_event_loop() - loop.create_task(main(loop)) + _LOGGER.info("Start Hassio task") + loop.create_task(core.run_hassio(loop)) + loop.run_forever() + _LOGGER.info("Close Hassio") diff --git a/hassio_api/hassio/core.py b/hassio_api/hassio/core.py new file mode 100644 index 000000000..376bcfdc1 --- /dev/null +++ b/hassio_api/hassio/core.py @@ -0,0 +1,47 @@ +"""Main file for HassIO.""" +import asyncio +import logging + +import aiohttp +import docker + +import .bootstrap +import .tools +from .const import CONF_HOMEASSISTANT_TAG +from .docker.homeassistant import DockerHomeAssistant + +_LOGGER = logging.getLogger(__name__) + + +async def run_hassio(loop): + """Start HassIO.""" + websession = aiohttp.ClientSession(loop=loop) + dock = docker.Client(base_url='unix://var/run/docker.sock', version='auto') + + # init system + config = bootstrap.initialize_system_data() + + # init HomeAssistant Docker + docker_hass = DockerHomeAssistant( + config, loop, dock, config.homeassistant_image, + config.homeassistant_tag + ) + + # first start of supervisor? + if config.homeassistant_tag is None: + _LOGGER.info("First start of supervisor, read version from github.") + + # read homeassistant tag and install it + current = None + while True: + current = await tools.fetch_current_versions(websession) + if current and CONF_HOMEASSISTANT_TAG in current: + if await docker_hass.install(current[CONF_HOMEASSISTANT_TAG]): + break + _LOGGER.warning("Can't fetch info from github. Retry in 60") + await asyncio.sleep(60, loop=loop) + + config.homeassistant_tag = current[CONF_HOMEASSISTANT_TAG] + + # run HomeAssistant + await docker_hass.run() diff --git a/hassio_api/setup.py b/hassio_api/setup.py index f0406904b..2f65c1857 100644 --- a/hassio_api/setup.py +++ b/hassio_api/setup.py @@ -1,6 +1,6 @@ from setuptools import setup -VERSION = "1.5" +VERSION = "0.1" setup( name='HassIO',