diff --git a/hassio_api/hassio/core.py b/hassio_api/hassio/core.py index 16a2c3873..f5295fd0f 100644 --- a/hassio_api/hassio/core.py +++ b/hassio_api/hassio/core.py @@ -35,7 +35,7 @@ class HassIO(object): self.host_controll = HostControll(self.loop) async def start(self): - """Start HassIO.""" + """Start HassIO orchestration.""" await self.supervisor.attach() _LOGGER.info( "Attach to supervisor image %s version %s", self.supervisor.image, @@ -50,22 +50,34 @@ class HassIO(object): # first start of supervisor? if self.config.homeassistant_tag is None: _LOGGER.info("No HomeAssistant docker found. Install it now") - - # read homeassistant tag and install it - current = None - while True: - current = await tools.fetch_current_versions(self.websession) - if current and HOMEASSISTANT_TAG in current: - resp = await self.homeassistant.install( - current[HOMEASSISTANT_TAG]) - if resp: - break - _LOGGER.warning("Can't fetch info from github. Retry in 60.") - await asyncio.sleep(60, loop=self.loop) - - self.config.homeassistant_tag = current[HOMEASSISTANT_TAG] + await self._setup_homeassistant() else: _LOGGER.info("HomeAssistant docker exists. Run it now") # run HomeAssistant await self.homeassistant.run() + + async def stop(self): + """Stop a running orchestration.""" + tasks = [self.websession.close()] + await asyncio.wait(tasks, loop=self.loop) + + self.loop.close() + + async def _setup_homeassistant(self): + """Install a homeassistant docker container.""" + current = None + while True: + # read homeassistant tag and install it + current = await tools.fetch_current_versions(self.websession) + if current and HOMEASSISTANT_TAG in current: + resp = await self.homeassistant.install( + current[HOMEASSISTANT_TAG]) + if resp: + break + _LOGGER.warning("Error on setup HomeAssistant. Retry in 60.") + await asyncio.sleep(60, loop=self.loop) + + # store version + self.config.homeassistant_tag = current[HOMEASSISTANT_TAG] + _LOGGER.info("HomeAssistant docker now exists.") diff --git a/hassio_api/hassio/dock/__init__.py b/hassio_api/hassio/dock/__init__.py index 938e23d1b..8e3751558 100644 --- a/hassio_api/hassio/dock/__init__.py +++ b/hassio_api/hassio/dock/__init__.py @@ -11,13 +11,12 @@ _LOGGER = logging.getLogger(__name__) class DockerBase(object): """Docker hassio wrapper.""" - def __init__(self, config, loop, dock, image=None, tag=None): + def __init__(self, config, loop, dock, image=None): """Initialize docker base wrapper.""" self.config = config self.loop = loop self.dock = dock self.image = image - self.tag = tag self.container = None self.version = None @@ -64,6 +63,8 @@ class DockerBase(object): if not self.container: try: self.container = self.dock.containers.get(self.docker_name) + self.version = get_version_from_env( + self.container.attrs['Config']['Env']) except docker.errors.DockerException: return False return self.container.status == 'running' diff --git a/hassio_api/hassio/dock/homeassistant.py b/hassio_api/hassio/dock/homeassistant.py index 8e37bf0a0..65e10bf53 100644 --- a/hassio_api/hassio/dock/homeassistant.py +++ b/hassio_api/hassio/dock/homeassistant.py @@ -16,10 +16,7 @@ class DockerHomeAssistant(DockerBase): def __init__(self, config, loop, dock): """Initialize docker homeassistant wrapper.""" - super().__init__( - config, loop, dock, image=config.homeassistant_image, - tag=config.homeassistant_tag - ) + super().__init__(config, loop, dock, image=config.homeassistant_image) @property def docker_name(self):