mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Add install to Tessie update platform (#106352)
This commit is contained in:
parent
728bef20d6
commit
b51a242fd4
@ -1,6 +1,10 @@
|
||||
"""Update platform for Tessie integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from tessie_api import schedule_software_update
|
||||
|
||||
from homeassistant.components.update import UpdateEntity, UpdateEntityFeature
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
@ -35,6 +39,16 @@ class TessieUpdateEntity(TessieEntity, UpdateEntity):
|
||||
"""Initialize the Update."""
|
||||
super().__init__(coordinator, "update")
|
||||
|
||||
@property
|
||||
def supported_features(self) -> UpdateEntityFeature:
|
||||
"""Flag supported features."""
|
||||
if self.get("vehicle_state_software_update_status") in (
|
||||
TessieUpdateStatus.AVAILABLE,
|
||||
TessieUpdateStatus.SCHEDULED,
|
||||
):
|
||||
return self._attr_supported_features | UpdateEntityFeature.INSTALL
|
||||
return self._attr_supported_features
|
||||
|
||||
@property
|
||||
def installed_version(self) -> str:
|
||||
"""Return the current app version."""
|
||||
@ -63,3 +77,12 @@ class TessieUpdateEntity(TessieEntity, UpdateEntity):
|
||||
):
|
||||
return self.get("vehicle_state_software_update_install_perc")
|
||||
return False
|
||||
|
||||
async def async_install(
|
||||
self, version: str | None, backup: bool, **kwargs: Any
|
||||
) -> None:
|
||||
"""Install an update."""
|
||||
await self.run(schedule_software_update, in_seconds=0)
|
||||
self.set(
|
||||
("vehicle_state_software_update_status", TessieUpdateStatus.INSTALLING)
|
||||
)
|
||||
|
@ -248,8 +248,8 @@
|
||||
"software_update": {
|
||||
"download_perc": 100,
|
||||
"expected_duration_sec": 2700,
|
||||
"install_perc": 10,
|
||||
"status": "installing",
|
||||
"install_perc": 1,
|
||||
"status": "available",
|
||||
"version": "2023.44.30.4"
|
||||
},
|
||||
"speed_limit_mode": {
|
||||
|
@ -1,5 +1,12 @@
|
||||
"""Test the Tessie update platform."""
|
||||
from homeassistant.const import STATE_ON
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.components.update import (
|
||||
ATTR_IN_PROGRESS,
|
||||
DOMAIN as UPDATE_DOMAIN,
|
||||
SERVICE_INSTALL,
|
||||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_ON
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .common import setup_platform
|
||||
@ -14,4 +21,22 @@ async def test_updates(hass: HomeAssistant) -> None:
|
||||
|
||||
assert len(hass.states.async_all("update")) == 1
|
||||
|
||||
assert hass.states.get("update.test").state == STATE_ON
|
||||
entity_id = "update.test"
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get(ATTR_IN_PROGRESS) is False
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.tessie.update.schedule_software_update"
|
||||
) as mock_update:
|
||||
await hass.services.async_call(
|
||||
UPDATE_DOMAIN,
|
||||
SERVICE_INSTALL,
|
||||
{ATTR_ENTITY_ID: [entity_id]},
|
||||
blocking=True,
|
||||
)
|
||||
mock_update.assert_called_once()
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get(ATTR_IN_PROGRESS) == 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user