Rename current_version to installed_version in Update platform (#69093)

This commit is contained in:
Franck Nijhof 2022-04-01 20:11:17 +02:00
parent d4a31b037f
commit 7fe6174bd9
No known key found for this signature in database
GPG key ID: D62583BA8AB11CA3
15 changed files with 121 additions and 117 deletions

View file

@ -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",
@ -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",
@ -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",
@ -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",
@ -104,7 +104,7 @@ class DemoUpdate(UpdateEntity):
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,
@ -114,7 +114,7 @@ class DemoUpdate(UpdateEntity):
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
@ -149,7 +149,7 @@ class DemoUpdate(UpdateEntity):
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()

View file

@ -116,8 +116,8 @@ class SupervisorAddonUpdateEntity(HassioAddonEntity, UpdateEntity):
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
@ -139,9 +139,12 @@ class SupervisorAddonUpdateEntity(HassioAddonEntity, UpdateEntity):
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
@ -182,7 +185,7 @@ class SupervisorOSUpdateEntity(HassioOSEntity, UpdateEntity):
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]
@ -226,7 +229,7 @@ class SupervisorSupervisorUpdateEntity(HassioSupervisorEntity, UpdateEntity):
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]
@ -271,7 +274,7 @@ class SupervisorCoreUpdateEntity(HassioCoreEntity, UpdateEntity):
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]

View file

@ -22,7 +22,7 @@ from .const import DATA_KEY_API, DATA_KEY_COORDINATOR, DOMAIN
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
@ -34,7 +34,7 @@ UPDATE_ENTITY_TYPES: tuple[PiHoleUpdateEntityDescription, ...] = (
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",
),
@ -43,7 +43,7 @@ UPDATE_ENTITY_TYPES: tuple[PiHoleUpdateEntityDescription, ...] = (
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",
),
@ -52,7 +52,7 @@ UPDATE_ENTITY_TYPES: tuple[PiHoleUpdateEntityDescription, ...] = (
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",
),
@ -100,10 +100,10 @@ class PiHoleUpdateEntity(PiHoleEntity, UpdateEntity):
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

View file

@ -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

View file

@ -28,8 +28,8 @@ from homeassistant.helpers.typing import ConfigType
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,
@ -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}")
@ -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
@ -183,9 +184,9 @@ class UpdateEntity(RestoreEntity):
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:
@ -256,7 +257,7 @@ class UpdateEntity(RestoreEntity):
"""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()
@ -305,7 +306,7 @@ class UpdateEntity(RestoreEntity):
@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
@ -314,11 +315,11 @@ class UpdateEntity(RestoreEntity):
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
@ -334,17 +335,17 @@ class UpdateEntity(RestoreEntity):
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,

View file

@ -22,7 +22,7 @@ SERVICE_SKIP: Final = "skip"
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"

View file

@ -5,7 +5,7 @@ from typing import Any
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
@ -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):

View file

@ -44,8 +44,8 @@ class WLEDUpdateEntity(WLEDEntity, UpdateEntity):
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)

View file

@ -5,8 +5,8 @@ import pytest
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,
@ -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!"
@ -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
@ -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!"
@ -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 (
@ -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 (

View file

@ -20,7 +20,7 @@ async def test_update(hass):
state = hass.states.get("update.pi_hole_core_update_available")
assert state.name == "Pi-Hole Core Update Available"
assert state.state == STATE_ON
assert state.attributes["current_version"] == "v5.5"
assert state.attributes["installed_version"] == "v5.5"
assert state.attributes["latest_version"] == "v5.6"
assert (
state.attributes["release_url"]
@ -30,7 +30,7 @@ async def test_update(hass):
state = hass.states.get("update.pi_hole_ftl_update_available")
assert state.name == "Pi-Hole FTL Update Available"
assert state.state == STATE_ON
assert state.attributes["current_version"] == "v5.10"
assert state.attributes["installed_version"] == "v5.10"
assert state.attributes["latest_version"] == "v5.11"
assert (
state.attributes["release_url"]
@ -40,7 +40,7 @@ async def test_update(hass):
state = hass.states.get("update.pi_hole_web_update_available")
assert state.name == "Pi-Hole Web Update Available"
assert state.state == STATE_ON
assert state.attributes["current_version"] == "v5.7"
assert state.attributes["installed_version"] == "v5.7"
assert state.attributes["latest_version"] == "v5.8"
assert (
state.attributes["release_url"]
@ -61,20 +61,20 @@ async def test_update_no_versions(hass):
state = hass.states.get("update.pi_hole_core_update_available")
assert state.name == "Pi-Hole Core Update Available"
assert state.state == STATE_UNKNOWN
assert state.attributes["current_version"] is None
assert state.attributes["installed_version"] is None
assert state.attributes["latest_version"] is None
assert state.attributes["release_url"] is None
state = hass.states.get("update.pi_hole_ftl_update_available")
assert state.name == "Pi-Hole FTL Update Available"
assert state.state == STATE_UNKNOWN
assert state.attributes["current_version"] is None
assert state.attributes["installed_version"] is None
assert state.attributes["latest_version"] is None
assert state.attributes["release_url"] is None
state = hass.states.get("update.pi_hole_web_update_available")
assert state.name == "Pi-Hole Web Update Available"
assert state.state == STATE_UNKNOWN
assert state.attributes["current_version"] is None
assert state.attributes["installed_version"] is None
assert state.attributes["latest_version"] is None
assert state.attributes["release_url"] is None

View file

@ -17,8 +17,8 @@ from homeassistant.components.update import (
)
from homeassistant.components.update.const import (
ATTR_AUTO_UPDATE,
ATTR_CURRENT_VERSION,
ATTR_IN_PROGRESS,
ATTR_INSTALLED_VERSION,
ATTR_LATEST_VERSION,
ATTR_RELEASE_SUMMARY,
ATTR_RELEASE_URL,
@ -51,14 +51,14 @@ async def test_update(hass: HomeAssistant) -> None:
update = MockUpdateEntity()
update.hass = hass
update._attr_current_version = "1.0.0"
update._attr_installed_version = "1.0.0"
update._attr_latest_version = "1.0.1"
update._attr_release_summary = "Summary"
update._attr_release_url = "https://example.com"
update._attr_title = "Title"
assert update.entity_category is EntityCategory.DIAGNOSTIC
assert update.current_version == "1.0.0"
assert update.installed_version == "1.0.0"
assert update.latest_version == "1.0.1"
assert update.release_summary == "Summary"
assert update.release_url == "https://example.com"
@ -67,7 +67,7 @@ async def test_update(hass: HomeAssistant) -> None:
assert update.state == STATE_ON
assert update.state_attributes == {
ATTR_AUTO_UPDATE: False,
ATTR_CURRENT_VERSION: "1.0.0",
ATTR_INSTALLED_VERSION: "1.0.0",
ATTR_IN_PROGRESS: False,
ATTR_LATEST_VERSION: "1.0.1",
ATTR_RELEASE_SUMMARY: "Summary",
@ -77,27 +77,27 @@ async def test_update(hass: HomeAssistant) -> None:
}
# Test no update available
update._attr_current_version = "1.0.0"
update._attr_installed_version = "1.0.0"
update._attr_latest_version = "1.0.0"
assert update.state is STATE_OFF
# Test state becomes unknown if current version is unknown
update._attr_current_version = None
# Test state becomes unknown if installed version is unknown
update._attr_installed_version = None
update._attr_latest_version = "1.0.0"
assert update.state is None
# Test state becomes unknown if latest version is unknown
update._attr_current_version = "1.0.0"
update._attr_installed_version = "1.0.0"
update._attr_latest_version = None
assert update.state is None
# Test no update if new version is not an update
update._attr_current_version = "1.0.0"
update._attr_installed_version = "1.0.0"
update._attr_latest_version = "0.9.0"
assert update.state is STATE_OFF
# Test update if new version is not considered a valid version
update._attr_current_version = "1.0.0"
update._attr_installed_version = "1.0.0"
update._attr_latest_version = "awesome_update"
assert update.state is STATE_ON
@ -159,7 +159,7 @@ async def test_entity_with_no_install(
state = hass.states.get("update.update_no_install")
assert state
assert state.state == STATE_ON
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"
# Should not be able to install as the entity doesn't support that
@ -175,7 +175,7 @@ async def test_entity_with_no_install(
state = hass.states.get("update.update_no_install")
assert state
assert state.state == STATE_ON
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_SKIPPED_VERSION] is None
@ -190,7 +190,7 @@ async def test_entity_with_no_install(
state = hass.states.get("update.update_no_install")
assert state
assert state.state == STATE_OFF
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_SKIPPED_VERSION] == "1.0.1"
@ -210,7 +210,7 @@ async def test_entity_with_no_updates(
state = hass.states.get("update.no_update")
assert state
assert state.state == STATE_OFF
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"
# Should not be able to skip when there is no update available
@ -259,7 +259,7 @@ async def test_entity_with_auto_update(
state = hass.states.get("update.update_with_auto_update")
assert state
assert state.state == STATE_ON
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_SKIPPED_VERSION] is None
@ -300,7 +300,7 @@ async def test_entity_with_updates_available(
state = hass.states.get("update.update_available")
assert state
assert state.state == STATE_ON
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_SKIPPED_VERSION] is None
@ -316,7 +316,7 @@ async def test_entity_with_updates_available(
state = hass.states.get("update.update_available")
assert state
assert state.state == STATE_OFF
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_SKIPPED_VERSION] == "1.0.1"
@ -332,7 +332,7 @@ async def test_entity_with_updates_available(
state = hass.states.get("update.update_available")
assert state
assert state.state == STATE_OFF
assert state.attributes[ATTR_CURRENT_VERSION] == "1.0.1"
assert state.attributes[ATTR_INSTALLED_VERSION] == "1.0.1"
assert state.attributes[ATTR_LATEST_VERSION] == "1.0.1"
assert state.attributes[ATTR_SKIPPED_VERSION] is None
assert "Installed latest update" in caplog.text
@ -353,7 +353,7 @@ async def test_entity_with_unknown_version(
state = hass.states.get("update.update_unknown")
assert state
assert state.state == STATE_UNKNOWN
assert state.attributes[ATTR_CURRENT_VERSION] == "1.0.0"
assert state.attributes[ATTR_INSTALLED_VERSION] == "1.0.0"
assert state.attributes[ATTR_LATEST_VERSION] is None
assert state.attributes[ATTR_SKIPPED_VERSION] is None
@ -391,7 +391,7 @@ async def test_entity_with_specific_version(
state = hass.states.get("update.update_specific_version")
assert state
assert state.state == STATE_OFF
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"
# Update to a specific version
@ -406,7 +406,7 @@ async def test_entity_with_specific_version(
state = hass.states.get("update.update_specific_version")
assert state
assert state.state == STATE_ON
assert state.attributes[ATTR_CURRENT_VERSION] == "0.9.9"
assert state.attributes[ATTR_INSTALLED_VERSION] == "0.9.9"
assert state.attributes[ATTR_LATEST_VERSION] == "1.0.0"
assert "Installed update with version: 0.9.9" in caplog.text
@ -421,7 +421,7 @@ async def test_entity_with_specific_version(
state = hass.states.get("update.update_specific_version")
assert state
assert state.state == STATE_OFF
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 "Installed latest update" in caplog.text
@ -455,7 +455,7 @@ async def test_entity_with_backup_support(
state = hass.states.get("update.update_backup")
assert state
assert state.state == STATE_ON
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"
# Without a backup
@ -472,7 +472,7 @@ async def test_entity_with_backup_support(
state = hass.states.get("update.update_backup")
assert state
assert state.state == STATE_OFF
assert state.attributes[ATTR_CURRENT_VERSION] == "1.0.1"
assert state.attributes[ATTR_INSTALLED_VERSION] == "1.0.1"
assert state.attributes[ATTR_LATEST_VERSION] == "1.0.1"
assert "Creating backup before installing update" not in caplog.text
assert "Installed latest update" in caplog.text
@ -493,7 +493,7 @@ async def test_entity_with_backup_support(
state = hass.states.get("update.update_backup")
assert state
assert state.state == STATE_ON
assert state.attributes[ATTR_CURRENT_VERSION] == "0.9.8"
assert state.attributes[ATTR_INSTALLED_VERSION] == "0.9.8"
assert state.attributes[ATTR_LATEST_VERSION] == "1.0.1"
assert "Creating backup before installing update" in caplog.text
assert "Installed update with version: 0.9.8" in caplog.text
@ -514,7 +514,7 @@ async def test_entity_already_in_progress(
state = hass.states.get("update.update_already_in_progress")
assert state
assert state.state == STATE_ON
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_IN_PROGRESS] == 50
@ -559,14 +559,14 @@ async def test_entity_without_progress_support(
assert len(events) == 2
assert events[0].data.get("old_state").attributes[ATTR_IN_PROGRESS] is False
assert events[0].data.get("old_state").attributes[ATTR_CURRENT_VERSION] == "1.0.0"
assert events[0].data.get("old_state").attributes[ATTR_INSTALLED_VERSION] == "1.0.0"
assert events[0].data.get("new_state").attributes[ATTR_IN_PROGRESS] is True
assert events[0].data.get("new_state").attributes[ATTR_CURRENT_VERSION] == "1.0.0"
assert events[0].data.get("new_state").attributes[ATTR_INSTALLED_VERSION] == "1.0.0"
assert events[1].data.get("old_state").attributes[ATTR_IN_PROGRESS] is True
assert events[1].data.get("old_state").attributes[ATTR_CURRENT_VERSION] == "1.0.0"
assert events[1].data.get("old_state").attributes[ATTR_INSTALLED_VERSION] == "1.0.0"
assert events[1].data.get("new_state").attributes[ATTR_IN_PROGRESS] is False
assert events[1].data.get("new_state").attributes[ATTR_CURRENT_VERSION] == "1.0.1"
assert events[1].data.get("new_state").attributes[ATTR_INSTALLED_VERSION] == "1.0.1"
async def test_entity_without_progress_support_raising(
@ -602,14 +602,14 @@ async def test_entity_without_progress_support_raising(
assert len(events) == 2
assert events[0].data.get("old_state").attributes[ATTR_IN_PROGRESS] is False
assert events[0].data.get("old_state").attributes[ATTR_CURRENT_VERSION] == "1.0.0"
assert events[0].data.get("old_state").attributes[ATTR_INSTALLED_VERSION] == "1.0.0"
assert events[0].data.get("new_state").attributes[ATTR_IN_PROGRESS] is True
assert events[0].data.get("new_state").attributes[ATTR_CURRENT_VERSION] == "1.0.0"
assert events[0].data.get("new_state").attributes[ATTR_INSTALLED_VERSION] == "1.0.0"
assert events[1].data.get("old_state").attributes[ATTR_IN_PROGRESS] is True
assert events[1].data.get("old_state").attributes[ATTR_CURRENT_VERSION] == "1.0.0"
assert events[1].data.get("old_state").attributes[ATTR_INSTALLED_VERSION] == "1.0.0"
assert events[1].data.get("new_state").attributes[ATTR_IN_PROGRESS] is False
assert events[1].data.get("new_state").attributes[ATTR_CURRENT_VERSION] == "1.0.0"
assert events[1].data.get("new_state").attributes[ATTR_INSTALLED_VERSION] == "1.0.0"
async def test_restore_state(
@ -638,7 +638,7 @@ async def test_restore_state(
state = hass.states.get("update.update_available")
assert state
assert state.state == STATE_OFF
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_SKIPPED_VERSION] == "1.0.1"

View file

@ -6,8 +6,8 @@ from datetime import timedelta
from homeassistant.components.recorder.models import StateAttributes, States
from homeassistant.components.recorder.util import session_scope
from homeassistant.components.update.const import (
ATTR_CURRENT_VERSION,
ATTR_IN_PROGRESS,
ATTR_INSTALLED_VERSION,
ATTR_RELEASE_SUMMARY,
DOMAIN,
)
@ -52,4 +52,4 @@ async def test_exclude_attributes(
for state in states:
assert ATTR_IN_PROGRESS not in state.attributes
assert ATTR_RELEASE_SUMMARY not in state.attributes
assert ATTR_CURRENT_VERSION in state.attributes
assert ATTR_INSTALLED_VERSION in state.attributes

View file

@ -1,7 +1,7 @@
"""Test the update significant change platform."""
from homeassistant.components.update.const import (
ATTR_CURRENT_VERSION,
ATTR_IN_PROGRESS,
ATTR_INSTALLED_VERSION,
ATTR_LATEST_VERSION,
ATTR_RELEASE_SUMMARY,
ATTR_RELEASE_URL,
@ -23,7 +23,7 @@ async def test_significant_change(hass: HomeAssistant) -> None:
assert not async_check_significant_change(hass, STATE_ON, {}, STATE_ON, {})
attrs = {
ATTR_CURRENT_VERSION: "1.0.0",
ATTR_INSTALLED_VERSION: "1.0.0",
ATTR_IN_PROGRESS: False,
ATTR_LATEST_VERSION: "1.0.1",
ATTR_RELEASE_SUMMARY: "Fixes!",
@ -38,7 +38,7 @@ async def test_significant_change(hass: HomeAssistant) -> None:
STATE_ON,
attrs,
STATE_ON,
attrs.copy() | {ATTR_CURRENT_VERSION: "1.0.1"},
attrs.copy() | {ATTR_INSTALLED_VERSION: "1.0.1"},
)
assert async_check_significant_change(

View file

@ -11,7 +11,7 @@ from homeassistant.components.update import (
UpdateEntityFeature,
)
from homeassistant.components.update.const import (
ATTR_CURRENT_VERSION,
ATTR_INSTALLED_VERSION,
ATTR_LATEST_VERSION,
ATTR_RELEASE_SUMMARY,
ATTR_RELEASE_URL,
@ -46,7 +46,7 @@ async def test_update_available(
assert state
assert state.attributes.get(ATTR_DEVICE_CLASS) == UpdateDeviceClass.FIRMWARE
assert state.state == STATE_ON
assert state.attributes[ATTR_CURRENT_VERSION] == "0.8.5"
assert state.attributes[ATTR_INSTALLED_VERSION] == "0.8.5"
assert state.attributes[ATTR_LATEST_VERSION] == "0.12.0"
assert state.attributes[ATTR_RELEASE_SUMMARY] is None
assert (
@ -79,7 +79,7 @@ async def test_update_information_available(
assert state
assert state.attributes.get(ATTR_DEVICE_CLASS) == UpdateDeviceClass.FIRMWARE
assert state.state == STATE_UNKNOWN
assert state.attributes[ATTR_CURRENT_VERSION] is None
assert state.attributes[ATTR_INSTALLED_VERSION] is None
assert state.attributes[ATTR_LATEST_VERSION] is None
assert state.attributes[ATTR_RELEASE_SUMMARY] is None
assert state.attributes[ATTR_RELEASE_URL] is None
@ -110,7 +110,7 @@ async def test_no_update_available(
assert state
assert state.state == STATE_OFF
assert state.attributes.get(ATTR_DEVICE_CLASS) == UpdateDeviceClass.FIRMWARE
assert state.attributes[ATTR_CURRENT_VERSION] == "0.12.0-b2"
assert state.attributes[ATTR_INSTALLED_VERSION] == "0.12.0-b2"
assert state.attributes[ATTR_LATEST_VERSION] == "0.12.0-b2"
assert state.attributes[ATTR_RELEASE_SUMMARY] is None
assert (
@ -169,7 +169,7 @@ async def test_update_stay_stable(
state = hass.states.get("update.wled_rgb_light_firmware")
assert state
assert state.state == STATE_ON
assert state.attributes[ATTR_CURRENT_VERSION] == "0.8.5"
assert state.attributes[ATTR_INSTALLED_VERSION] == "0.8.5"
assert state.attributes[ATTR_LATEST_VERSION] == "0.12.0"
await hass.services.async_call(
@ -198,7 +198,7 @@ async def test_update_beta_to_stable(
state = hass.states.get("update.wled_rgbw_light_firmware")
assert state
assert state.state == STATE_ON
assert state.attributes[ATTR_CURRENT_VERSION] == "0.8.6b4"
assert state.attributes[ATTR_INSTALLED_VERSION] == "0.8.6b4"
assert state.attributes[ATTR_LATEST_VERSION] == "0.8.6"
await hass.services.async_call(
@ -226,7 +226,7 @@ async def test_update_stay_beta(
state = hass.states.get("update.wled_rgb_light_firmware")
assert state
assert state.state == STATE_ON
assert state.attributes[ATTR_CURRENT_VERSION] == "0.8.6b1"
assert state.attributes[ATTR_INSTALLED_VERSION] == "0.8.6b1"
assert state.attributes[ATTR_LATEST_VERSION] == "0.8.6b2"
await hass.services.async_call(

View file

@ -26,9 +26,9 @@ class MockUpdateEntity(MockEntity, UpdateEntity):
return self._handle("auto_update")
@property
def current_version(self) -> str | None:
"""Version currently in use."""
return self._handle("current_version")
def installed_version(self) -> str | None:
"""Version currently installed and in use."""
return self._handle("installed_version")
@property
def in_progress(self) -> bool | int | None:
@ -61,10 +61,10 @@ class MockUpdateEntity(MockEntity, UpdateEntity):
_LOGGER.info("Creating backup before installing update")
if version is not None:
self._values["current_version"] = version
self._values["installed_version"] = version
_LOGGER.info(f"Installed update with version: {version}")
else:
self._values["current_version"] = self.latest_version
self._values["installed_version"] = self.latest_version
_LOGGER.info("Installed latest update")
def release_notes(self) -> str | None:
@ -83,28 +83,28 @@ def init(empty=False):
MockUpdateEntity(
name="No Update",
unique_id="no_update",
current_version="1.0.0",
installed_version="1.0.0",
latest_version="1.0.0",
supported_features=UpdateEntityFeature.INSTALL,
),
MockUpdateEntity(
name="Update Available",
unique_id="update_available",
current_version="1.0.0",
installed_version="1.0.0",
latest_version="1.0.1",
supported_features=UpdateEntityFeature.INSTALL,
),
MockUpdateEntity(
name="Update Unknown",
unique_id="update_unknown",
current_version="1.0.0",
installed_version="1.0.0",
latest_version=None,
supported_features=UpdateEntityFeature.INSTALL,
),
MockUpdateEntity(
name="Update Specific Version",
unique_id="update_specific_version",
current_version="1.0.0",
installed_version="1.0.0",
latest_version="1.0.0",
supported_features=UpdateEntityFeature.INSTALL
| UpdateEntityFeature.SPECIFIC_VERSION,
@ -112,7 +112,7 @@ def init(empty=False):
MockUpdateEntity(
name="Update Backup",
unique_id="update_backup",
current_version="1.0.0",
installed_version="1.0.0",
latest_version="1.0.1",
supported_features=UpdateEntityFeature.INSTALL
| UpdateEntityFeature.SPECIFIC_VERSION
@ -121,7 +121,7 @@ def init(empty=False):
MockUpdateEntity(
name="Update Already in Progress",
unique_id="update_already_in_progres",
current_version="1.0.0",
installed_version="1.0.0",
latest_version="1.0.1",
in_progress=50,
supported_features=UpdateEntityFeature.INSTALL
@ -130,20 +130,20 @@ def init(empty=False):
MockUpdateEntity(
name="Update No Install",
unique_id="no_install",
current_version="1.0.0",
installed_version="1.0.0",
latest_version="1.0.1",
),
MockUpdateEntity(
name="Update with release notes",
unique_id="with_release_notes",
current_version="1.0.0",
installed_version="1.0.0",
latest_version="1.0.1",
supported_features=UpdateEntityFeature.RELEASE_NOTES,
),
MockUpdateEntity(
name="Update with auto update",
unique_id="with_auto_update",
current_version="1.0.0",
installed_version="1.0.0",
latest_version="1.0.1",
auto_update=True,
supported_features=UpdateEntityFeature.INSTALL,