mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Add update platform to Tessie (#106093)
* Add version platform * Add strings and test * Remove potential for None * Dont show progress when no update is running * Return None for no update * Add comment * Remove future feature * WIP * Fix statuses * update fixture * Remove entity name * Remove name correctly * Use False for in_progress
This commit is contained in:
parent
f263da843a
commit
13908cf5a6
@ -20,6 +20,7 @@ PLATFORMS = [
|
||||
Platform.SELECT,
|
||||
Platform.SENSOR,
|
||||
Platform.SWITCH,
|
||||
Platform.UPDATE,
|
||||
]
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -36,3 +36,13 @@ class TessieClimateKeeper(StrEnum):
|
||||
ON = "on"
|
||||
DOG = "dog"
|
||||
CAMP = "camp"
|
||||
|
||||
|
||||
class TessieUpdateStatus(StrEnum):
|
||||
"""Tessie Update Statuses."""
|
||||
|
||||
AVAILABLE = "available"
|
||||
DOWNLOADING = "downloading"
|
||||
INSTALLING = "installing"
|
||||
WIFI_WAIT = "downloading_wifi_wait"
|
||||
SCHEDULED = "scheduled"
|
||||
|
64
homeassistant/components/tessie/update.py
Normal file
64
homeassistant/components/tessie/update.py
Normal file
@ -0,0 +1,64 @@
|
||||
"""Update platform for Tessie integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.components.update import UpdateEntity, UpdateEntityFeature
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN, TessieUpdateStatus
|
||||
from .coordinator import TessieDataUpdateCoordinator
|
||||
from .entity import TessieEntity
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Set up the Tessie Update platform from a config entry."""
|
||||
coordinators = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
async_add_entities(TessieUpdateEntity(coordinator) for coordinator in coordinators)
|
||||
|
||||
|
||||
class TessieUpdateEntity(TessieEntity, UpdateEntity):
|
||||
"""Tessie Updates entity."""
|
||||
|
||||
_attr_supported_features = UpdateEntityFeature.PROGRESS
|
||||
_attr_name = None
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: TessieDataUpdateCoordinator,
|
||||
) -> None:
|
||||
"""Initialize the Update."""
|
||||
super().__init__(coordinator, "update")
|
||||
|
||||
@property
|
||||
def installed_version(self) -> str:
|
||||
"""Return the current app version."""
|
||||
# Discard build from version number
|
||||
return self.coordinator.data["vehicle_state_car_version"].split(" ")[0]
|
||||
|
||||
@property
|
||||
def latest_version(self) -> str | None:
|
||||
"""Return the latest version."""
|
||||
# Dont show an update when its not in a state that can be actioned
|
||||
if self.get("vehicle_state_software_update_status") in (
|
||||
TessieUpdateStatus.AVAILABLE,
|
||||
TessieUpdateStatus.SCHEDULED,
|
||||
TessieUpdateStatus.INSTALLING,
|
||||
TessieUpdateStatus.DOWNLOADING,
|
||||
TessieUpdateStatus.WIFI_WAIT,
|
||||
):
|
||||
return self.get("vehicle_state_software_update_version")
|
||||
return None
|
||||
|
||||
@property
|
||||
def in_progress(self) -> bool | int | None:
|
||||
"""Update installation progress."""
|
||||
if (
|
||||
self.get("vehicle_state_software_update_status")
|
||||
== TessieUpdateStatus.INSTALLING
|
||||
):
|
||||
return self.get("vehicle_state_software_update_install_perc")
|
||||
return False
|
@ -246,11 +246,11 @@
|
||||
"service_mode": false,
|
||||
"service_mode_plus": false,
|
||||
"software_update": {
|
||||
"download_perc": 0,
|
||||
"download_perc": 100,
|
||||
"expected_duration_sec": 2700,
|
||||
"install_perc": 1,
|
||||
"status": "",
|
||||
"version": " "
|
||||
"install_perc": 10,
|
||||
"status": "installing",
|
||||
"version": "2023.44.30.4"
|
||||
},
|
||||
"speed_limit_mode": {
|
||||
"active": false,
|
||||
|
17
tests/components/tessie/test_update.py
Normal file
17
tests/components/tessie/test_update.py
Normal file
@ -0,0 +1,17 @@
|
||||
"""Test the Tessie update platform."""
|
||||
from homeassistant.const import STATE_ON
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .common import setup_platform
|
||||
|
||||
|
||||
async def test_updates(hass: HomeAssistant) -> None:
|
||||
"""Tests that the updates are correct."""
|
||||
|
||||
assert len(hass.states.async_all("update")) == 0
|
||||
|
||||
await setup_platform(hass)
|
||||
|
||||
assert len(hass.states.async_all("update")) == 1
|
||||
|
||||
assert hass.states.get("update.test").state == STATE_ON
|
Loading…
x
Reference in New Issue
Block a user