Add clear_skipped service to update entity (#70116)
This commit is contained in:
parent
9d016dd434
commit
d65e12ab6e
3 changed files with 56 additions and 1 deletions
|
@ -96,6 +96,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
{},
|
||||
async_skip,
|
||||
)
|
||||
component.async_register_entity_service(
|
||||
"clear_skipped",
|
||||
{},
|
||||
async_clear_skipped,
|
||||
)
|
||||
|
||||
websocket_api.async_register_command(hass, websocket_release_notes)
|
||||
|
||||
return True
|
||||
|
@ -153,6 +159,15 @@ async def async_skip(entity: UpdateEntity, service_call: ServiceCall) -> None:
|
|||
await entity.async_skip()
|
||||
|
||||
|
||||
async def async_clear_skipped(entity: UpdateEntity, service_call: ServiceCall) -> None:
|
||||
"""Service call wrapper to validate the call."""
|
||||
if entity.auto_update:
|
||||
raise HomeAssistantError(
|
||||
f"Clearing skipped update is not supported for {entity.name}"
|
||||
)
|
||||
await entity.async_clear_skipped()
|
||||
|
||||
|
||||
@dataclass
|
||||
class UpdateEntityDescription(EntityDescription):
|
||||
"""A class that describes update entities."""
|
||||
|
@ -276,6 +291,12 @@ class UpdateEntity(RestoreEntity):
|
|||
self.__skipped_version = latest_version
|
||||
self.async_write_ha_state()
|
||||
|
||||
@final
|
||||
async def async_clear_skipped(self) -> None:
|
||||
"""Clear the skipped version."""
|
||||
self.__skipped_version = None
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_install(
|
||||
self, version: str | None, backup: bool, **kwargs: Any
|
||||
) -> None:
|
||||
|
|
|
@ -25,3 +25,10 @@ skip:
|
|||
target:
|
||||
entity:
|
||||
domain: update
|
||||
|
||||
clear_skipped:
|
||||
name: Clear skipped update
|
||||
description: Removes the skipped version marker from an update.
|
||||
target:
|
||||
entity:
|
||||
domain: update
|
||||
|
|
|
@ -202,6 +202,21 @@ async def test_entity_with_no_install(
|
|||
assert state.attributes[ATTR_LATEST_VERSION] == "1.0.1"
|
||||
assert state.attributes[ATTR_SKIPPED_VERSION] == "1.0.1"
|
||||
|
||||
# We can clear the skipped marker again
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
"clear_skipped",
|
||||
{ATTR_ENTITY_ID: "update.update_no_install"},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
state = hass.states.get("update.update_no_install")
|
||||
assert state
|
||||
assert state.state == STATE_ON
|
||||
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
|
||||
|
||||
|
||||
async def test_entity_with_no_updates(
|
||||
hass: HomeAssistant,
|
||||
|
@ -279,7 +294,7 @@ async def test_entity_with_auto_update(
|
|||
blocking=True,
|
||||
)
|
||||
|
||||
# Should not be to skip the update
|
||||
# Should not be able to skip the update
|
||||
with pytest.raises(
|
||||
HomeAssistantError,
|
||||
match="Skipping update is not supported for Update with auto update",
|
||||
|
@ -291,6 +306,18 @@ async def test_entity_with_auto_update(
|
|||
blocking=True,
|
||||
)
|
||||
|
||||
# Should not be able to clear a skipped the update
|
||||
with pytest.raises(
|
||||
HomeAssistantError,
|
||||
match="Clearing skipped update is not supported for Update with auto update",
|
||||
):
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
"clear_skipped",
|
||||
{ATTR_ENTITY_ID: "update.update_with_auto_update"},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_with_updates_available(
|
||||
hass: HomeAssistant,
|
||||
|
|
Loading…
Add table
Reference in a new issue