diff --git a/hassio/addons/addon.py b/hassio/addons/addon.py index 72293adcf6a..d41106f6e59 100644 --- a/hassio/addons/addon.py +++ b/hassio/addons/addon.py @@ -41,12 +41,12 @@ def __init__(self, config, loop, dock, data, slug): self.data = data self._id = slug - self.addon_docker = DockerAddon(config, loop, dock, self) + self.docker = DockerAddon(config, loop, dock, self) async def load(self): """Async initialize of object.""" if self.is_installed: - await self.addon_docker.attach() + await self.docker.attach() @property def slug(self): @@ -434,7 +434,7 @@ async def install(self, version=None): self.path_data.mkdir() version = version or self.last_version - if not await self.addon_docker.install(version): + if not await self.docker.install(version): return False self._set_install(version) @@ -443,7 +443,7 @@ async def install(self, version=None): @check_installed async def uninstall(self): """Remove a addon.""" - if not await self.addon_docker.remove(): + if not await self.docker.remove(): return False if self.path_data.is_dir(): @@ -459,7 +459,7 @@ async def state(self): if not self.is_installed: return STATE_NONE - if await self.addon_docker.is_running(): + if await self.docker.is_running(): return STATE_STARTED return STATE_STOPPED @@ -469,7 +469,7 @@ def start(self): Return a coroutine. """ - return self.addon_docker.run() + return self.docker.run() @check_installed def stop(self): @@ -477,22 +477,26 @@ def stop(self): Return a coroutine. """ - return self.addon_docker.stop() + return self.docker.stop() @check_installed async def update(self, version=None): """Update addon.""" version = version or self.last_version + last_state = await self.state() if version == self.version_installed: _LOGGER.warning( "Addon %s is already installed in %s", self._id, version) return False - if not await self.addon_docker.update(version): + if not await self.docker.update(version): return False - self._set_update(version) + + # restore state + if last_state == STATE_STARTED: + return await self.docker.run() return True @check_installed @@ -501,7 +505,7 @@ def restart(self): Return a coroutine. """ - return self.addon_docker.restart() + return self.docker.restart() @check_installed def logs(self): @@ -509,7 +513,7 @@ def logs(self): Return a coroutine. """ - return self.addon_docker.logs() + return self.docker.logs() @check_installed async def snapshot(self, tar_file): @@ -517,7 +521,7 @@ async def snapshot(self, tar_file): with TemporaryDirectory(dir=str(self.config.path_tmp)) as temp: # store local image if self.need_build and not await \ - self.addon_docker.export_image(Path(temp, "image.tar")): + self.docker.export_image(Path(temp, "image.tar")): return False data = { @@ -582,15 +586,15 @@ def _extract_tar(): # check version / restore image version = data[ATTR_VERSION] - if version != self.addon_docker.version: + if version != self.docker.version: image_file = Path(temp, "image.tar") if image_file.is_file(): - await self.addon_docker.import_image(image_file, version) + await self.docker.import_image(image_file, version) else: - if await self.addon_docker.install(version): - await self.addon_docker.cleanup() + if await self.docker.install(version): + await self.docker.cleanup() else: - await self.addon_docker.stop() + await self.docker.stop() # restore data def _restore_data(): diff --git a/hassio/addons/git.py b/hassio/addons/git.py index 5e9c02618c1..70c9fda497f 100644 --- a/hassio/addons/git.py +++ b/hassio/addons/git.py @@ -48,7 +48,8 @@ async def clone(self): try: _LOGGER.info("Clone addon %s repository", self.url) self.repo = await self.loop.run_in_executor( - None, git.Repo.clone_from, self.url, str(self.path)) + None, git.Repo.clone_from, self.url, str(self.path), + recursive=True) except (git.InvalidGitRepositoryError, git.NoSuchPathError, git.GitCommandError) as err: diff --git a/hassio/const.py b/hassio/const.py index c30893bdbb4..a6c5a3dcaad 100644 --- a/hassio/const.py +++ b/hassio/const.py @@ -1,7 +1,7 @@ """Const file for HassIO.""" from pathlib import Path -HASSIO_VERSION = '0.52' +HASSIO_VERSION = '0.53' URL_HASSIO_VERSION = ('https://raw.githubusercontent.com/home-assistant/' 'hassio/{}/version.json') diff --git a/hassio/dock/__init__.py b/hassio/dock/__init__.py index 7fb7adb4ddf..90d0c601df2 100644 --- a/hassio/dock/__init__.py +++ b/hassio/dock/__init__.py @@ -251,8 +251,6 @@ def _update(self, tag): Need run inside executor. """ - was_running = self._is_running() - _LOGGER.info( "Update docker %s with %s:%s", self.version, self.image, tag) @@ -260,11 +258,8 @@ def _update(self, tag): if not self._install(tag): return False - # run or cleanup container - if was_running: - self._run() - else: - self._stop() + # container + self._stop() # cleanup images self._cleanup() diff --git a/hassio/homeassistant.py b/hassio/homeassistant.py index 22511da66b1..ad0e34ce368 100644 --- a/hassio/homeassistant.py +++ b/hassio/homeassistant.py @@ -121,7 +121,10 @@ async def update(self, version=None): _LOGGER.warning("Version %s is already installed", version) return False - return await self.docker.update(version) + try: + return await self.docker.update(version) + finally: + await self.docker.run() def run(self): """Run HomeAssistant docker. diff --git a/version.json b/version.json index 9bb86483d68..8cec6cfd3d0 100644 --- a/version.json +++ b/version.json @@ -1,5 +1,5 @@ { - "hassio": "0.52", + "hassio": "0.53", "homeassistant": "0.51.2", "resinos": "1.0", "resinhup": "0.3",