Merge pull request #929 from home-assistant/dev

Release 145
This commit is contained in:
Pascal Vizeli 2019-02-21 17:21:43 +01:00 committed by GitHub
commit 32c9198fb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 10 deletions

View File

@ -8,6 +8,7 @@ import re
import shutil import shutil
import tarfile import tarfile
from tempfile import TemporaryDirectory from tempfile import TemporaryDirectory
from typing import Dict, Any
import voluptuous as vol import voluptuous as vol
from voluptuous.humanize import humanize_error from voluptuous.humanize import humanize_error
@ -108,32 +109,34 @@ class Addon(CoreSysAttributes):
"""Return installed version.""" """Return installed version."""
return self._data.user.get(self._id, {}).get(ATTR_VERSION) return self._data.user.get(self._id, {}).get(ATTR_VERSION)
def _set_install(self, version): def _set_install(self, image: str, version: str) -> None:
"""Set addon as installed.""" """Set addon as installed."""
self._data.system[self._id] = deepcopy(self._data.cache[self._id]) self._data.system[self._id] = deepcopy(self._data.cache[self._id])
self._data.user[self._id] = { self._data.user[self._id] = {
ATTR_OPTIONS: {}, ATTR_OPTIONS: {},
ATTR_VERSION: version, ATTR_VERSION: version,
ATTR_IMAGE: self.image_name, ATTR_IMAGE: image,
} }
self.save_data() self.save_data()
def _set_uninstall(self): def _set_uninstall(self) -> None:
"""Set add-on as uninstalled.""" """Set add-on as uninstalled."""
self._data.system.pop(self._id, None) self._data.system.pop(self._id, None)
self._data.user.pop(self._id, None) self._data.user.pop(self._id, None)
self.save_data() self.save_data()
def _set_update(self, version): def _set_update(self, image: str, version: str) -> None:
"""Update version of add-on.""" """Update version of add-on."""
self._data.system[self._id] = deepcopy(self._data.cache[self._id]) self._data.system[self._id] = deepcopy(self._data.cache[self._id])
self._data.user[self._id][ATTR_VERSION] = version self._data.user[self._id][ATTR_VERSION] = version
self.save_data() self.save_data()
def _restore_data(self, user, system): def _restore_data(self, user: Dict[str, Any], system: Dict[str, Any], image: str) -> None:
"""Restore data to add-on.""" """Restore data to add-on."""
self._data.user[self._id] = deepcopy(user) self._data.user[self._id] = deepcopy(user)
self._data.system[self._id] = deepcopy(system) self._data.system[self._id] = deepcopy(system)
self._data.user[self._id][ATTR_IMAGE] = image
self.save_data() self.save_data()
@property @property
@ -725,7 +728,7 @@ class Addon(CoreSysAttributes):
self.last_version, self.image_name): self.last_version, self.image_name):
return False return False
self._set_install(self.last_version) self._set_install(self.image_name, self.last_version)
return True return True
@check_installed @check_installed
@ -805,7 +808,7 @@ class Addon(CoreSysAttributes):
if not await self.instance.update( if not await self.instance.update(
self.last_version, self.image_name): self.last_version, self.image_name):
return False return False
self._set_update(self.last_version) self._set_update(self.image_name, self.last_version)
# Setup/Fix AppArmor profile # Setup/Fix AppArmor profile
await self._install_apparmor() await self._install_apparmor()
@ -950,7 +953,7 @@ class Addon(CoreSysAttributes):
# Restore data or reload add-on # Restore data or reload add-on
_LOGGER.info("Restore config for addon %s", self._id) _LOGGER.info("Restore config for addon %s", self._id)
self._restore_data(data[ATTR_USER], data[ATTR_SYSTEM]) self._restore_data(data[ATTR_USER], data[ATTR_SYSTEM], self.image_name)
# Check version / restore image # Check version / restore image
version = data[ATTR_VERSION] version = data[ATTR_VERSION]
@ -961,7 +964,7 @@ class Addon(CoreSysAttributes):
if image_file.is_file(): if image_file.is_file():
await self.instance.import_image(image_file, version) await self.instance.import_image(image_file, version)
else: else:
if await self.instance.install(version): if await self.instance.install(version, self.image_name):
await self.instance.cleanup() await self.instance.cleanup()
else: else:
await self.instance.stop() await self.instance.stop()

View File

@ -2,7 +2,7 @@
from pathlib import Path from pathlib import Path
from ipaddress import ip_network from ipaddress import ip_network
HASSIO_VERSION = "144" HASSIO_VERSION = "145"
URL_HASSIO_ADDONS = "https://github.com/home-assistant/hassio-addons" URL_HASSIO_ADDONS = "https://github.com/home-assistant/hassio-addons"
URL_HASSIO_VERSION = "https://s3.amazonaws.com/hassio-version/{channel}.json" URL_HASSIO_VERSION = "https://s3.amazonaws.com/hassio-version/{channel}.json"