Cleanup last_version with latest_version inside code (#1012)

* Cleanup last_version with latest_version inside code

* Fix property
This commit is contained in:
Pascal Vizeli 2019-04-07 15:04:16 +02:00 committed by GitHub
parent d7bb9013d4
commit 118da3c275
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 26 additions and 26 deletions

View File

@ -322,7 +322,7 @@ class Addon(CoreSysAttributes):
return self._mesh[ATTR_REPOSITORY] return self._mesh[ATTR_REPOSITORY]
@property @property
def last_version(self): def latest_version(self):
"""Return version of add-on.""" """Return version of add-on."""
if self._id in self._data.cache: if self._id in self._data.cache:
return self._data.cache[self._id][ATTR_VERSION] return self._data.cache[self._id][ATTR_VERSION]
@ -845,11 +845,11 @@ class Addon(CoreSysAttributes):
await self._install_apparmor() await self._install_apparmor()
try: try:
await self.instance.install(self.last_version, self.image_next) await self.instance.install(self.latest_version, self.image_next)
except DockerAPIError: except DockerAPIError:
raise AddonsError() from None raise AddonsError() from None
else: else:
self._set_install(self.image_next, self.last_version) self._set_install(self.image_next, self.latest_version)
@check_installed @check_installed
async def uninstall(self) -> None: async def uninstall(self) -> None:
@ -922,7 +922,7 @@ class Addon(CoreSysAttributes):
@check_installed @check_installed
async def update(self) -> None: async def update(self) -> None:
"""Update add-on.""" """Update add-on."""
if self.last_version == self.version_installed: if self.latest_version == self.version_installed:
_LOGGER.warning("No update available for add-on %s", self._id) _LOGGER.warning("No update available for add-on %s", self._id)
return return
@ -936,10 +936,10 @@ class Addon(CoreSysAttributes):
# Update instance # Update instance
last_state = await self.state() last_state = await self.state()
try: try:
await self.instance.update(self.last_version, self.image_next) await self.instance.update(self.latest_version, self.image_next)
except DockerAPIError: except DockerAPIError:
raise AddonsError() from None raise AddonsError() from None
self._set_update(self.image_next, self.last_version) self._set_update(self.image_next, self.latest_version)
# Setup/Fix AppArmor profile # Setup/Fix AppArmor profile
await self._install_apparmor() await self._install_apparmor()
@ -979,7 +979,7 @@ class Addon(CoreSysAttributes):
if not self.need_build: if not self.need_build:
_LOGGER.error("Can't rebuild a image based add-on") _LOGGER.error("Can't rebuild a image based add-on")
raise AddonsNotSupportedError() raise AddonsNotSupportedError()
if self.version_installed != self.last_version: if self.version_installed != self.latest_version:
_LOGGER.error("Version changed, use Update instead Rebuild") _LOGGER.error("Version changed, use Update instead Rebuild")
raise AddonsError() raise AddonsError()

View File

@ -135,7 +135,7 @@ class APIAddons(CoreSysAttributes):
ATTR_NAME: addon.name, ATTR_NAME: addon.name,
ATTR_SLUG: addon.slug, ATTR_SLUG: addon.slug,
ATTR_DESCRIPTON: addon.description, ATTR_DESCRIPTON: addon.description,
ATTR_VERSION: addon.last_version, ATTR_VERSION: addon.latest_version,
ATTR_INSTALLED: addon.version_installed, ATTR_INSTALLED: addon.version_installed,
ATTR_AVAILABLE: addon.available, ATTR_AVAILABLE: addon.available,
ATTR_DETACHED: addon.is_detached, ATTR_DETACHED: addon.is_detached,
@ -179,7 +179,7 @@ class APIAddons(CoreSysAttributes):
ATTR_VERSION: addon.version_installed, ATTR_VERSION: addon.version_installed,
ATTR_AUTO_UPDATE: addon.auto_update, ATTR_AUTO_UPDATE: addon.auto_update,
ATTR_REPOSITORY: addon.repository, ATTR_REPOSITORY: addon.repository,
ATTR_LAST_VERSION: addon.last_version, ATTR_LAST_VERSION: addon.latest_version,
ATTR_STATE: await addon.state(), ATTR_STATE: await addon.state(),
ATTR_PROTECTED: addon.protected, ATTR_PROTECTED: addon.protected,
ATTR_RATING: rating_security(addon), ATTR_RATING: rating_security(addon),
@ -315,7 +315,7 @@ class APIAddons(CoreSysAttributes):
"""Update add-on.""" """Update add-on."""
addon = self._extract_addon(request) addon = self._extract_addon(request)
if addon.last_version == addon.version_installed: if addon.latest_version == addon.version_installed:
raise APIError("No update available!") raise APIError("No update available!")
return asyncio.shield(addon.update()) return asyncio.shield(addon.update())

View File

@ -63,7 +63,7 @@ class APIHomeAssistant(CoreSysAttributes):
"""Return host information.""" """Return host information."""
return { return {
ATTR_VERSION: self.sys_homeassistant.version, ATTR_VERSION: self.sys_homeassistant.version,
ATTR_LAST_VERSION: self.sys_homeassistant.last_version, ATTR_LAST_VERSION: self.sys_homeassistant.latest_version,
ATTR_MACHINE: self.sys_homeassistant.machine, ATTR_MACHINE: self.sys_homeassistant.machine,
ATTR_IP_ADDRESS: str(self.sys_homeassistant.ip_address), ATTR_IP_ADDRESS: str(self.sys_homeassistant.ip_address),
ATTR_ARCH: self.sys_homeassistant.arch, ATTR_ARCH: self.sys_homeassistant.arch,
@ -83,7 +83,7 @@ class APIHomeAssistant(CoreSysAttributes):
if ATTR_IMAGE in body and ATTR_LAST_VERSION in body: if ATTR_IMAGE in body and ATTR_LAST_VERSION in body:
self.sys_homeassistant.image = body[ATTR_IMAGE] self.sys_homeassistant.image = body[ATTR_IMAGE]
self.sys_homeassistant.last_version = body[ATTR_LAST_VERSION] self.sys_homeassistant.latest_version = body[ATTR_LAST_VERSION]
if ATTR_BOOT in body: if ATTR_BOOT in body:
self.sys_homeassistant.boot = body[ATTR_BOOT] self.sys_homeassistant.boot = body[ATTR_BOOT]
@ -130,7 +130,7 @@ class APIHomeAssistant(CoreSysAttributes):
async def update(self, request: web.Request) -> None: async def update(self, request: web.Request) -> None:
"""Update Home Assistant.""" """Update Home Assistant."""
body = await api_validate(SCHEMA_VERSION, request) body = await api_validate(SCHEMA_VERSION, request)
version = body.get(ATTR_VERSION, self.sys_homeassistant.last_version) version = body.get(ATTR_VERSION, self.sys_homeassistant.latest_version)
await asyncio.shield(self.sys_homeassistant.update(version)) await asyncio.shield(self.sys_homeassistant.update(version))

View File

@ -74,7 +74,7 @@ class APISupervisor(CoreSysAttributes):
ATTR_SLUG: addon.slug, ATTR_SLUG: addon.slug,
ATTR_DESCRIPTON: addon.description, ATTR_DESCRIPTON: addon.description,
ATTR_STATE: await addon.state(), ATTR_STATE: await addon.state(),
ATTR_VERSION: addon.last_version, ATTR_VERSION: addon.latest_version,
ATTR_INSTALLED: addon.version_installed, ATTR_INSTALLED: addon.version_installed,
ATTR_REPOSITORY: addon.repository, ATTR_REPOSITORY: addon.repository,
ATTR_ICON: addon.with_icon, ATTR_ICON: addon.with_icon,

View File

@ -164,14 +164,14 @@ class HomeAssistant(JsonConfig, CoreSysAttributes):
return self.instance.version return self.instance.version
@property @property
def last_version(self) -> str: def latest_version(self) -> str:
"""Return last available version of Home Assistant.""" """Return last available version of Home Assistant."""
if self.is_custom_image: if self.is_custom_image:
return self._data.get(ATTR_LAST_VERSION) return self._data.get(ATTR_LAST_VERSION)
return self.sys_updater.version_homeassistant return self.sys_updater.version_homeassistant
@last_version.setter @latest_version.setter
def last_version(self, value: str): def latest_version(self, value: str):
"""Set last available version of Home Assistant.""" """Set last available version of Home Assistant."""
if value: if value:
self._data[ATTR_LAST_VERSION] = value self._data[ATTR_LAST_VERSION] = value
@ -246,10 +246,10 @@ class HomeAssistant(JsonConfig, CoreSysAttributes):
_LOGGER.info("Setup Home Assistant") _LOGGER.info("Setup Home Assistant")
while True: while True:
# read homeassistant tag and install it # read homeassistant tag and install it
if not self.last_version: if not self.latest_version:
await self.sys_updater.reload() await self.sys_updater.reload()
tag = self.last_version tag = self.latest_version
if tag: if tag:
with suppress(DockerAPIError): with suppress(DockerAPIError):
await self.instance.install(tag) await self.instance.install(tag)
@ -273,7 +273,7 @@ class HomeAssistant(JsonConfig, CoreSysAttributes):
@process_lock @process_lock
async def update(self, version=None) -> None: async def update(self, version=None) -> None:
"""Update HomeAssistant version.""" """Update HomeAssistant version."""
version = version or self.last_version version = version or self.latest_version
rollback = self.version if not self.error_state else None rollback = self.version if not self.error_state else None
running = await self.instance.is_running() running = await self.instance.is_running()
exists = await self.instance.exists() exists = await self.instance.exists()

View File

@ -417,7 +417,7 @@ class Snapshot(CoreSysAttributes):
if self.sys_homeassistant.is_custom_image: if self.sys_homeassistant.is_custom_image:
self.homeassistant[ATTR_IMAGE] = self.sys_homeassistant.image self.homeassistant[ATTR_IMAGE] = self.sys_homeassistant.image
self.homeassistant[ATTR_LAST_VERSION] = \ self.homeassistant[ATTR_LAST_VERSION] = \
self.sys_homeassistant.last_version self.sys_homeassistant.latest_version
# API/Proxy # API/Proxy
self.homeassistant[ATTR_PORT] = self.sys_homeassistant.api_port self.homeassistant[ATTR_PORT] = self.sys_homeassistant.api_port
@ -436,7 +436,7 @@ class Snapshot(CoreSysAttributes):
# Custom image # Custom image
if self.homeassistant.get(ATTR_IMAGE): if self.homeassistant.get(ATTR_IMAGE):
self.sys_homeassistant.image = self.homeassistant[ATTR_IMAGE] self.sys_homeassistant.image = self.homeassistant[ATTR_IMAGE]
self.sys_homeassistant.last_version = \ self.sys_homeassistant.latest_version = \
self.homeassistant[ATTR_LAST_VERSION] self.homeassistant[ATTR_LAST_VERSION]
# API/Proxy # API/Proxy

View File

@ -49,7 +49,7 @@ class Supervisor(CoreSysAttributes):
@property @property
def need_update(self) -> bool: def need_update(self) -> bool:
"""Return True if an update is available.""" """Return True if an update is available."""
return self.version != self.last_version return self.version != self.latest_version
@property @property
def version(self) -> str: def version(self) -> str:
@ -57,7 +57,7 @@ class Supervisor(CoreSysAttributes):
return self.instance.version return self.instance.version
@property @property
def last_version(self) -> str: def latest_version(self) -> str:
"""Return last available version of Home Assistant.""" """Return last available version of Home Assistant."""
return self.sys_updater.version_hassio return self.sys_updater.version_hassio
@ -101,7 +101,7 @@ class Supervisor(CoreSysAttributes):
async def update(self, version: Optional[str] = None) -> None: async def update(self, version: Optional[str] = None) -> None:
"""Update Home Assistant version.""" """Update Home Assistant version."""
version = version or self.last_version version = version or self.latest_version
if version == self.sys_supervisor.version: if version == self.sys_supervisor.version:
_LOGGER.warning("Version %s is already installed", version) _LOGGER.warning("Version %s is already installed", version)

View File

@ -93,7 +93,7 @@ class Tasks(CoreSysAttributes):
if not addon.is_installed or not addon.auto_update: if not addon.is_installed or not addon.auto_update:
continue continue
if addon.version_installed == addon.last_version: if addon.version_installed == addon.latest_version:
continue continue
if addon.test_update_schema(): if addon.test_update_schema():