Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename current_version to installed_version in Update platform #69093

Merged
merged 1 commit into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions homeassistant/components/demo/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def async_setup_platform(
unique_id="update_no_install",
name="Demo Update No Install",
title="Awesomesoft Inc.",
current_version="1.0.0",
installed_version="1.0.0",
latest_version="1.0.1",
release_summary="Awesome update, fixing everything!",
release_url="https://www.example.com/release/1.0.1",
Expand All @@ -41,14 +41,14 @@ async def async_setup_platform(
unique_id="update_2_date",
name="Demo No Update",
title="AdGuard Home",
current_version="1.0.0",
installed_version="1.0.0",
latest_version="1.0.0",
),
DemoUpdate(
unique_id="update_addon",
name="Demo add-on",
title="AdGuard Home",
current_version="1.0.0",
installed_version="1.0.0",
latest_version="1.0.1",
release_summary="Awesome update, fixing everything!",
release_url="https://www.example.com/release/1.0.1",
Expand All @@ -57,7 +57,7 @@ async def async_setup_platform(
unique_id="update_light_bulb",
name="Demo Living Room Bulb Update",
title="Philips Lamps Firmware",
current_version="1.93.3",
installed_version="1.93.3",
latest_version="1.94.2",
release_summary="Added support for effects",
release_url="https://www.example.com/release/1.93.3",
Expand All @@ -67,7 +67,7 @@ async def async_setup_platform(
unique_id="update_support_progress",
name="Demo Update with Progress",
title="Philips Lamps Firmware",
current_version="1.93.3",
installed_version="1.93.3",
latest_version="1.94.2",
support_progress=True,
release_summary="Added support for effects",
Expand Down Expand Up @@ -104,7 +104,7 @@ def __init__(
unique_id: str,
name: str,
title: str | None,
current_version: str | None,
installed_version: str | None,
latest_version: str | None,
release_summary: str | None = None,
release_url: str | None = None,
Expand All @@ -114,7 +114,7 @@ def __init__(
device_class: UpdateDeviceClass | None = None,
) -> None:
"""Initialize the Demo select entity."""
self._attr_current_version = current_version
self._attr_installed_version = installed_version
self._attr_device_class = device_class
self._attr_latest_version = latest_version
self._attr_name = name or DEVICE_DEFAULT_NAME
Expand Down Expand Up @@ -149,7 +149,7 @@ async def async_install(
await _fake_install()

self._attr_in_progress = False
self._attr_current_version = (
self._attr_installed_version = (
version if version is not None else self.latest_version
)
self.async_write_ha_state()
Expand Down
17 changes: 10 additions & 7 deletions homeassistant/components/hassio/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ def latest_version(self) -> str | None:
return self._addon_data[ATTR_VERSION_LATEST]

@property
def current_version(self) -> str | None:
"""Version currently in use."""
def installed_version(self) -> str | None:
"""Version installed and in use."""
return self._addon_data[ATTR_VERSION]

@property
Expand All @@ -139,9 +139,12 @@ def _strip_release_notes(self) -> str | None:
if (notes := self._addon_data[ATTR_CHANGELOG]) is None:
return None

if f"# {self.latest_version}" in notes and f"# {self.current_version}" in notes:
if (
f"# {self.latest_version}" in notes
and f"# {self.installed_version}" in notes
):
# Split the release notes to only what is between the versions if we can
new_notes = notes.split(f"# {self.current_version}")[0]
new_notes = notes.split(f"# {self.installed_version}")[0]
if f"# {self.latest_version}" in new_notes:
# Make sure the latest version is still there.
# This can be False if the order of the release notes are not correct
Expand Down Expand Up @@ -182,7 +185,7 @@ def latest_version(self) -> str:
return self.coordinator.data[DATA_KEY_OS][ATTR_VERSION_LATEST]

@property
def current_version(self) -> str:
def installed_version(self) -> str:
"""Return native value of entity."""
return self.coordinator.data[DATA_KEY_OS][ATTR_VERSION]

Expand Down Expand Up @@ -226,7 +229,7 @@ def latest_version(self) -> str:
return self.coordinator.data[DATA_KEY_SUPERVISOR][ATTR_VERSION_LATEST]

@property
def current_version(self) -> str:
def installed_version(self) -> str:
"""Return native value of entity."""
return self.coordinator.data[DATA_KEY_SUPERVISOR][ATTR_VERSION]

Expand Down Expand Up @@ -271,7 +274,7 @@ def latest_version(self) -> str:
return self.coordinator.data[DATA_KEY_CORE][ATTR_VERSION_LATEST]

@property
def current_version(self) -> str:
def installed_version(self) -> str:
"""Return native value of entity."""
return self.coordinator.data[DATA_KEY_CORE][ATTR_VERSION]

Expand Down
14 changes: 7 additions & 7 deletions homeassistant/components/pi_hole/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class PiHoleUpdateEntityDescription(UpdateEntityDescription):
"""Describes PiHole update entity."""

current_version: Callable[[dict], str | None] = lambda api: None
installed_version: Callable[[dict], str | None] = lambda api: None
latest_version: Callable[[dict], str | None] = lambda api: None
release_base_url: str | None = None
title: str | None = None
Expand All @@ -34,7 +34,7 @@ class PiHoleUpdateEntityDescription(UpdateEntityDescription):
name="Core Update Available",
title="Pi-hole Core",
entity_category=EntityCategory.DIAGNOSTIC,
current_version=lambda versions: versions.get("core_current"),
installed_version=lambda versions: versions.get("core_current"),
latest_version=lambda versions: versions.get("core_latest"),
release_base_url="https://github.com/pi-hole/pi-hole/releases/tag",
),
Expand All @@ -43,7 +43,7 @@ class PiHoleUpdateEntityDescription(UpdateEntityDescription):
name="Web Update Available",
title="Pi-hole Web interface",
entity_category=EntityCategory.DIAGNOSTIC,
current_version=lambda versions: versions.get("web_current"),
installed_version=lambda versions: versions.get("web_current"),
latest_version=lambda versions: versions.get("web_latest"),
release_base_url="https://github.com/pi-hole/AdminLTE/releases/tag",
),
Expand All @@ -52,7 +52,7 @@ class PiHoleUpdateEntityDescription(UpdateEntityDescription):
name="FTL Update Available",
title="Pi-hole FTL DNS",
entity_category=EntityCategory.DIAGNOSTIC,
current_version=lambda versions: versions.get("FTL_current"),
installed_version=lambda versions: versions.get("FTL_current"),
latest_version=lambda versions: versions.get("FTL_latest"),
release_base_url="https://github.com/pi-hole/FTL/releases/tag",
),
Expand Down Expand Up @@ -100,10 +100,10 @@ def __init__(
self._attr_title = description.title

@property
def current_version(self) -> str | None:
"""Version currently in use."""
def installed_version(self) -> str | None:
"""Version installed and in use."""
if isinstance(self.api.versions, dict):
return self.entity_description.current_version(self.api.versions)
return self.entity_description.installed_version(self.api.versions)
return None

@property
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/synology_dsm/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ class SynoDSMUpdateEntity(SynologyDSMBaseEntity, UpdateEntity):
_attr_title = "Synology DSM"

@property
def current_version(self) -> str | None:
"""Version currently in use."""
def installed_version(self) -> str | None:
"""Version installed and in use."""
return self._api.information.version_string # type: ignore[no-any-return]

@property
def latest_version(self) -> str | None:
"""Latest version available for install."""
if not self._api.upgrade.update_available:
return self.current_version
return self.installed_version
return self._api.upgrade.available_version # type: ignore[no-any-return]

@property
Expand Down
29 changes: 15 additions & 14 deletions homeassistant/components/update/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
from .const import (
ATTR_AUTO_UPDATE,
ATTR_BACKUP,
ATTR_CURRENT_VERSION,
ATTR_IN_PROGRESS,
ATTR_INSTALLED_VERSION,
ATTR_LATEST_VERSION,
ATTR_RELEASE_SUMMARY,
ATTR_RELEASE_URL,
Expand Down Expand Up @@ -117,7 +117,8 @@ async def async_install(entity: UpdateEntity, service_call: ServiceCall) -> None
"""Service call wrapper to validate the call."""
# If version is not specified, but no update is available.
if (version := service_call.data.get(ATTR_VERSION)) is None and (
entity.current_version == entity.latest_version or entity.latest_version is None
entity.installed_version == entity.latest_version
or entity.latest_version is None
):
raise HomeAssistantError(f"No update available for {entity.name}")

Expand Down Expand Up @@ -165,7 +166,7 @@ class UpdateEntity(RestoreEntity):

entity_description: UpdateEntityDescription
_attr_auto_update: bool = False
_attr_current_version: str | None = None
_attr_installed_version: str | None = None
_attr_device_class: UpdateDeviceClass | str | None
_attr_in_progress: bool | int = False
_attr_latest_version: str | None = None
Expand All @@ -183,9 +184,9 @@ def auto_update(self) -> bool:
return self._attr_auto_update

@property
def current_version(self) -> str | None:
"""Version currently in use."""
return self._attr_current_version
def installed_version(self) -> str | None:
"""Version installed and in use."""
return self._attr_installed_version

@property
def device_class(self) -> UpdateDeviceClass | str | None:
Expand Down Expand Up @@ -256,7 +257,7 @@ async def async_skip(self) -> None:
"""Skip the current offered version to update."""
if (latest_version := self.latest_version) is None:
raise HomeAssistantError(f"Cannot skip an unknown version for {self.name}")
if self.current_version == latest_version:
if self.installed_version == latest_version:
raise HomeAssistantError(f"No update available to skip for {self.name}")
self.__skipped_version = latest_version
self.async_write_ha_state()
Expand Down Expand Up @@ -305,7 +306,7 @@ def release_notes(self) -> str | None:
@final
def state(self) -> str | None:
"""Return the entity state."""
if (current_version := self.current_version) is None or (
if (installed_version := self.installed_version) is None or (
latest_version := self.latest_version
) is None:
return None
Expand All @@ -314,11 +315,11 @@ def state(self) -> str | None:
return STATE_OFF

try:
newer = AwesomeVersion(latest_version) > current_version
newer = AwesomeVersion(latest_version) > installed_version
return STATE_ON if newer else STATE_OFF
except AwesomeVersionCompareException:
# Can't compare versions, fallback to exact match
return STATE_OFF if latest_version == current_version else STATE_ON
return STATE_OFF if latest_version == installed_version else STATE_ON

@final
@property
Expand All @@ -334,17 +335,17 @@ def state_attributes(self) -> dict[str, Any] | None:
else:
in_progress = self.__in_progress

# Clear skipped version in case it matches the current version or
# the latest version diverged.
# Clear skipped version in case it matches the current installed
# version or the latest version diverged.
if (
self.__skipped_version == self.current_version
self.__skipped_version == self.installed_version
or self.__skipped_version != self.latest_version
):
self.__skipped_version = None

return {
ATTR_AUTO_UPDATE: self.auto_update,
ATTR_CURRENT_VERSION: self.current_version,
ATTR_INSTALLED_VERSION: self.installed_version,
ATTR_IN_PROGRESS: in_progress,
ATTR_LATEST_VERSION: self.latest_version,
ATTR_RELEASE_SUMMARY: release_summary,
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/update/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class UpdateEntityFeature(IntEnum):

ATTR_AUTO_UPDATE: Final = "auto_update"
ATTR_BACKUP: Final = "backup"
ATTR_CURRENT_VERSION: Final = "current_version"
ATTR_INSTALLED_VERSION: Final = "installed_version"
ATTR_IN_PROGRESS: Final = "in_progress"
ATTR_LATEST_VERSION: Final = "latest_version"
ATTR_RELEASE_SUMMARY: Final = "release_summary"
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/update/significant_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from homeassistant.core import HomeAssistant, callback

from .const import ATTR_CURRENT_VERSION, ATTR_LATEST_VERSION
from .const import ATTR_INSTALLED_VERSION, ATTR_LATEST_VERSION


@callback
Expand All @@ -21,7 +21,7 @@ def async_check_significant_change(
if old_state != new_state:
return True

if old_attrs.get(ATTR_CURRENT_VERSION) != new_attrs.get(ATTR_CURRENT_VERSION):
if old_attrs.get(ATTR_INSTALLED_VERSION) != new_attrs.get(ATTR_INSTALLED_VERSION):
return True

if old_attrs.get(ATTR_LATEST_VERSION) != new_attrs.get(ATTR_LATEST_VERSION):
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/wled/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def __init__(self, coordinator: WLEDDataUpdateCoordinator) -> None:
self._attr_unique_id = coordinator.data.info.mac_address

@property
def current_version(self) -> str | None:
"""Version currently in use."""
def installed_version(self) -> str | None:
"""Version currently installed and in use."""
if (version := self.coordinator.data.info.version) is None:
return None
return str(version)
Expand Down
12 changes: 6 additions & 6 deletions tests/components/demo/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

from homeassistant.components.update import DOMAIN, SERVICE_INSTALL, UpdateDeviceClass
from homeassistant.components.update.const import (
ATTR_CURRENT_VERSION,
ATTR_IN_PROGRESS,
ATTR_INSTALLED_VERSION,
ATTR_LATEST_VERSION,
ATTR_RELEASE_SUMMARY,
ATTR_RELEASE_URL,
Expand All @@ -31,7 +31,7 @@ def test_setup_params(hass: HomeAssistant) -> None:
assert state
assert state.state == STATE_ON
assert state.attributes[ATTR_TITLE] == "Awesomesoft Inc."
assert state.attributes[ATTR_CURRENT_VERSION] == "1.0.0"
assert state.attributes[ATTR_INSTALLED_VERSION] == "1.0.0"
assert state.attributes[ATTR_LATEST_VERSION] == "1.0.1"
assert (
state.attributes[ATTR_RELEASE_SUMMARY] == "Awesome update, fixing everything!"
Expand All @@ -42,7 +42,7 @@ def test_setup_params(hass: HomeAssistant) -> None:
assert state
assert state.state == STATE_OFF
assert state.attributes[ATTR_TITLE] == "AdGuard Home"
assert state.attributes[ATTR_CURRENT_VERSION] == "1.0.0"
assert state.attributes[ATTR_INSTALLED_VERSION] == "1.0.0"
assert state.attributes[ATTR_LATEST_VERSION] == "1.0.0"
assert state.attributes[ATTR_RELEASE_SUMMARY] is None
assert state.attributes[ATTR_RELEASE_URL] is None
Expand All @@ -51,7 +51,7 @@ def test_setup_params(hass: HomeAssistant) -> None:
assert state
assert state.state == STATE_ON
assert state.attributes[ATTR_TITLE] == "AdGuard Home"
assert state.attributes[ATTR_CURRENT_VERSION] == "1.0.0"
assert state.attributes[ATTR_INSTALLED_VERSION] == "1.0.0"
assert state.attributes[ATTR_LATEST_VERSION] == "1.0.1"
assert (
state.attributes[ATTR_RELEASE_SUMMARY] == "Awesome update, fixing everything!"
Expand All @@ -62,7 +62,7 @@ def test_setup_params(hass: HomeAssistant) -> None:
assert state
assert state.state == STATE_ON
assert state.attributes[ATTR_TITLE] == "Philips Lamps Firmware"
assert state.attributes[ATTR_CURRENT_VERSION] == "1.93.3"
assert state.attributes[ATTR_INSTALLED_VERSION] == "1.93.3"
assert state.attributes[ATTR_LATEST_VERSION] == "1.94.2"
assert state.attributes[ATTR_RELEASE_SUMMARY] == "Added support for effects"
assert (
Expand All @@ -74,7 +74,7 @@ def test_setup_params(hass: HomeAssistant) -> None:
assert state
assert state.state == STATE_ON
assert state.attributes[ATTR_TITLE] == "Philips Lamps Firmware"
assert state.attributes[ATTR_CURRENT_VERSION] == "1.93.3"
assert state.attributes[ATTR_INSTALLED_VERSION] == "1.93.3"
assert state.attributes[ATTR_LATEST_VERSION] == "1.94.2"
assert state.attributes[ATTR_RELEASE_SUMMARY] == "Added support for effects"
assert (
Expand Down
Loading