mirror of
https://github.com/natekspencer/hacs-oasis_mini.git
synced 2025-11-16 00:53:50 -05:00
Add update entity
This commit is contained in:
76
custom_components/oasis_mini/update.py
Normal file
76
custom_components/oasis_mini/update.py
Normal file
@@ -0,0 +1,76 @@
|
||||
"""Oasis Mini update entity."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.update import (
|
||||
UpdateDeviceClass,
|
||||
UpdateEntity,
|
||||
UpdateEntityDescription,
|
||||
UpdateEntityFeature,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import OasisMiniCoordinator
|
||||
from .entity import OasisMiniEntity
|
||||
|
||||
SCAN_INTERVAL = timedelta(hours=6)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Set up Oasis Mini updates using config entry."""
|
||||
coordinator: OasisMiniCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
if coordinator.device.access_token:
|
||||
async_add_entities(
|
||||
[OasisMiniUpdateEntity(coordinator, entry, DESCRIPTOR)], True
|
||||
)
|
||||
|
||||
|
||||
DESCRIPTOR = UpdateEntityDescription(
|
||||
key="software", device_class=UpdateDeviceClass.FIRMWARE
|
||||
)
|
||||
|
||||
|
||||
class OasisMiniUpdateEntity(OasisMiniEntity, UpdateEntity):
|
||||
"""Oasis Mini update entity."""
|
||||
|
||||
_attr_supported_features = (
|
||||
UpdateEntityFeature.INSTALL | UpdateEntityFeature.PROGRESS
|
||||
)
|
||||
|
||||
@property
|
||||
def in_progress(self) -> bool | int:
|
||||
"""Update installation progress."""
|
||||
if self.device.status_code == 11:
|
||||
return self.device.download_progress
|
||||
return False
|
||||
|
||||
@property
|
||||
def installed_version(self) -> str:
|
||||
"""Version installed and in use."""
|
||||
return self.device.software_version
|
||||
|
||||
@property
|
||||
def should_poll(self) -> bool:
|
||||
"""Set polling to True."""
|
||||
return True
|
||||
|
||||
async def async_install(
|
||||
self, version: str | None, backup: bool, **kwargs: Any
|
||||
) -> None:
|
||||
"""Install an update."""
|
||||
await self.device.async_upgrade()
|
||||
|
||||
async def async_update(self) -> None:
|
||||
"""Update the entity."""
|
||||
software = await self.device.async_cloud_get_latest_software_details()
|
||||
self._attr_latest_version = software["version"]
|
||||
self._attr_release_summary = software["description"]
|
||||
self._attr_release_url = f"https://app.grounded.so/software/{software['id']}"
|
||||
Reference in New Issue
Block a user