mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Adjust backup type of Update entity (#68553)
This commit is contained in:
parent
1c57e65cea
commit
44d3a7e459
@ -134,10 +134,7 @@ class DemoUpdate(UpdateEntity):
|
||||
self._attr_supported_features |= UpdateEntityFeature.PROGRESS
|
||||
|
||||
async def async_install(
|
||||
self,
|
||||
version: str | None = None,
|
||||
backup: bool | None = None,
|
||||
**kwargs: Any,
|
||||
self, version: str | None, backup: bool, **kwargs: Any
|
||||
) -> None:
|
||||
"""Install an update."""
|
||||
if self.supported_features & UpdateEntityFeature.PROGRESS:
|
||||
|
@ -170,10 +170,7 @@ class SupervisorOSUpdateEntity(HassioOSEntity, UpdateEntity):
|
||||
)
|
||||
|
||||
async def async_install(
|
||||
self,
|
||||
version: str | None = None,
|
||||
backup: bool | None = None,
|
||||
**kwargs: Any,
|
||||
self, version: str | None, backup: bool, **kwargs: Any
|
||||
) -> None:
|
||||
"""Install an update."""
|
||||
try:
|
||||
@ -214,10 +211,7 @@ class SupervisorSupervisorUpdateEntity(HassioSupervisorEntity, UpdateEntity):
|
||||
return "https://brands.home-assistant.io/hassio/icon.png"
|
||||
|
||||
async def async_install(
|
||||
self,
|
||||
version: str | None = None,
|
||||
backup: bool | None = None,
|
||||
**kwargs: Any,
|
||||
self, version: str | None, backup: bool, **kwargs: Any
|
||||
) -> None:
|
||||
"""Install an update."""
|
||||
try:
|
||||
@ -262,10 +256,7 @@ class SupervisorCoreUpdateEntity(HassioCoreEntity, UpdateEntity):
|
||||
return f"https://{'rc' if version.beta else 'www'}.home-assistant.io/latest-release-notes/"
|
||||
|
||||
async def async_install(
|
||||
self,
|
||||
version: str | None = None,
|
||||
backup: bool | None = None,
|
||||
**kwargs: Any,
|
||||
self, version: str | None, backup: bool, **kwargs: Any
|
||||
) -> None:
|
||||
"""Install an update."""
|
||||
try:
|
||||
|
@ -82,7 +82,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
SERVICE_INSTALL,
|
||||
{
|
||||
vol.Optional(ATTR_VERSION): cv.string,
|
||||
vol.Optional(ATTR_BACKUP): cv.boolean,
|
||||
vol.Optional(ATTR_BACKUP, default=False): cv.boolean,
|
||||
},
|
||||
async_install,
|
||||
[UpdateEntityFeature.INSTALL],
|
||||
@ -128,7 +128,7 @@ async def async_install(entity: UpdateEntity, service_call: ServiceCall) -> None
|
||||
|
||||
# If backup is requested, but not supported by the entity.
|
||||
if (
|
||||
backup := service_call.data.get(ATTR_BACKUP)
|
||||
backup := service_call.data[ATTR_BACKUP]
|
||||
) and not entity.supported_features & UpdateEntityFeature.BACKUP:
|
||||
raise HomeAssistantError(f"Backup is not supported for {entity.name}")
|
||||
|
||||
@ -245,10 +245,7 @@ class UpdateEntity(RestoreEntity):
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_install(
|
||||
self,
|
||||
version: str | None = None,
|
||||
backup: bool | None = None,
|
||||
**kwargs: Any,
|
||||
self, version: str | None, backup: bool, **kwargs: Any
|
||||
) -> None:
|
||||
"""Install an update.
|
||||
|
||||
@ -260,12 +257,7 @@ class UpdateEntity(RestoreEntity):
|
||||
"""
|
||||
await self.hass.async_add_executor_job(self.install, version, backup)
|
||||
|
||||
def install(
|
||||
self,
|
||||
version: str | None = None,
|
||||
backup: bool | None = None,
|
||||
**kwargs: Any,
|
||||
) -> None:
|
||||
def install(self, version: str | None, backup: bool, **kwargs: Any) -> None:
|
||||
"""Install an update.
|
||||
|
||||
Version can be specified to install a specific version. When `None`, the
|
||||
@ -323,9 +315,7 @@ class UpdateEntity(RestoreEntity):
|
||||
|
||||
@final
|
||||
async def async_install_with_progress(
|
||||
self,
|
||||
version: str | None = None,
|
||||
backup: bool | None = None,
|
||||
self, version: str | None, backup: bool
|
||||
) -> None:
|
||||
"""Install update and handle progress if needed.
|
||||
|
||||
|
@ -80,10 +80,7 @@ class WLEDUpdateEntity(WLEDEntity, UpdateEntity):
|
||||
|
||||
@wled_exception_handler
|
||||
async def async_install(
|
||||
self,
|
||||
version: str | None = None,
|
||||
backup: bool | None = None,
|
||||
**kwargs: Any,
|
||||
self, version: str | None, backup: bool, **kwargs: Any
|
||||
) -> None:
|
||||
"""Install an update."""
|
||||
if version is None:
|
||||
|
@ -117,10 +117,10 @@ async def test_update(hass: HomeAssistant) -> None:
|
||||
assert update.entity_category is EntityCategory.DIAGNOSTIC
|
||||
|
||||
with pytest.raises(NotImplementedError):
|
||||
await update.async_install()
|
||||
await update.async_install(version=None, backup=True)
|
||||
|
||||
with pytest.raises(NotImplementedError):
|
||||
update.install()
|
||||
update.install(version=None, backup=False)
|
||||
|
||||
update.install = MagicMock()
|
||||
await update.async_install(version="1.0.1", backup=True)
|
||||
|
@ -6,6 +6,7 @@ Call init before using it in your tests to ensure clean test data.
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.update import UpdateEntity, UpdateEntityFeature
|
||||
|
||||
@ -49,11 +50,7 @@ class MockUpdateEntity(MockEntity, UpdateEntity):
|
||||
"""Title of the software."""
|
||||
return self._handle("title")
|
||||
|
||||
def install(
|
||||
self,
|
||||
version: str | None = None,
|
||||
backup: bool | None = None,
|
||||
) -> None:
|
||||
def install(self, version: str | None, backup: bool, **kwargs: Any) -> None:
|
||||
"""Install an update."""
|
||||
if backup:
|
||||
_LOGGER.info("Creating backup before installing update")
|
||||
|
Loading…
x
Reference in New Issue
Block a user