Add install to Tessie update platform (#106352)
This commit is contained in:
parent
728bef20d6
commit
b51a242fd4
3 changed files with 52 additions and 4 deletions
|
@ -1,6 +1,10 @@
|
||||||
"""Update platform for Tessie integration."""
|
"""Update platform for Tessie integration."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from tessie_api import schedule_software_update
|
||||||
|
|
||||||
from homeassistant.components.update import UpdateEntity, UpdateEntityFeature
|
from homeassistant.components.update import UpdateEntity, UpdateEntityFeature
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
@ -35,6 +39,16 @@ class TessieUpdateEntity(TessieEntity, UpdateEntity):
|
||||||
"""Initialize the Update."""
|
"""Initialize the Update."""
|
||||||
super().__init__(coordinator, "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
|
@property
|
||||||
def installed_version(self) -> str:
|
def installed_version(self) -> str:
|
||||||
"""Return the current app version."""
|
"""Return the current app version."""
|
||||||
|
@ -63,3 +77,12 @@ class TessieUpdateEntity(TessieEntity, UpdateEntity):
|
||||||
):
|
):
|
||||||
return self.get("vehicle_state_software_update_install_perc")
|
return self.get("vehicle_state_software_update_install_perc")
|
||||||
return False
|
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": {
|
"software_update": {
|
||||||
"download_perc": 100,
|
"download_perc": 100,
|
||||||
"expected_duration_sec": 2700,
|
"expected_duration_sec": 2700,
|
||||||
"install_perc": 10,
|
"install_perc": 1,
|
||||||
"status": "installing",
|
"status": "available",
|
||||||
"version": "2023.44.30.4"
|
"version": "2023.44.30.4"
|
||||||
},
|
},
|
||||||
"speed_limit_mode": {
|
"speed_limit_mode": {
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
"""Test the Tessie update platform."""
|
"""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 homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from .common import setup_platform
|
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 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…
Add table
Reference in a new issue