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

View File

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

View File

@ -63,7 +63,7 @@ class APIHomeAssistant(CoreSysAttributes):
"""Return host information."""
return {
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_IP_ADDRESS: str(self.sys_homeassistant.ip_address),
ATTR_ARCH: self.sys_homeassistant.arch,
@ -83,7 +83,7 @@ class APIHomeAssistant(CoreSysAttributes):
if ATTR_IMAGE in body and ATTR_LAST_VERSION in body:
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:
self.sys_homeassistant.boot = body[ATTR_BOOT]
@ -130,7 +130,7 @@ class APIHomeAssistant(CoreSysAttributes):
async def update(self, request: web.Request) -> None:
"""Update Home Assistant."""
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))

View File

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

View File

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

View File

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

View File

@ -49,7 +49,7 @@ class Supervisor(CoreSysAttributes):
@property
def need_update(self) -> bool:
"""Return True if an update is available."""
return self.version != self.last_version
return self.version != self.latest_version
@property
def version(self) -> str:
@ -57,7 +57,7 @@ class Supervisor(CoreSysAttributes):
return self.instance.version
@property
def last_version(self) -> str:
def latest_version(self) -> str:
"""Return last available version of Home Assistant."""
return self.sys_updater.version_hassio
@ -101,7 +101,7 @@ class Supervisor(CoreSysAttributes):
async def update(self, version: Optional[str] = None) -> None:
"""Update Home Assistant version."""
version = version or self.last_version
version = version or self.latest_version
if version == self.sys_supervisor.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:
continue
if addon.version_installed == addon.last_version:
if addon.version_installed == addon.latest_version:
continue
if addon.test_update_schema():