Reolink schedule update after firmware update (#104867)
parent
450bc8dd2c
commit
742e2dbbe4
|
@ -1,6 +1,7 @@
|
|||
"""Update entities for Reolink devices."""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
import logging
|
||||
from typing import Any, Literal
|
||||
|
||||
|
@ -13,9 +14,10 @@ from homeassistant.components.update import (
|
|||
UpdateEntityFeature,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.event import async_call_later
|
||||
|
||||
from . import ReolinkData
|
||||
from .const import DOMAIN
|
||||
|
@ -23,6 +25,8 @@ from .entity import ReolinkBaseCoordinatorEntity
|
|||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
POLL_AFTER_INSTALL = 120
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
|
@ -51,6 +55,7 @@ class ReolinkUpdateEntity(
|
|||
super().__init__(reolink_data, reolink_data.firmware_coordinator)
|
||||
|
||||
self._attr_unique_id = f"{self._host.unique_id}"
|
||||
self._cancel_update: CALLBACK_TYPE | None = None
|
||||
|
||||
@property
|
||||
def installed_version(self) -> str | None:
|
||||
|
@ -100,3 +105,16 @@ class ReolinkUpdateEntity(
|
|||
) from err
|
||||
finally:
|
||||
self.async_write_ha_state()
|
||||
self._cancel_update = async_call_later(
|
||||
self.hass, POLL_AFTER_INSTALL, self._async_update_future
|
||||
)
|
||||
|
||||
async def _async_update_future(self, now: datetime | None = None) -> None:
|
||||
"""Request update."""
|
||||
await self.async_update()
|
||||
|
||||
async def async_will_remove_from_hass(self) -> None:
|
||||
"""Entity removed."""
|
||||
await super().async_will_remove_from_hass()
|
||||
if self._cancel_update is not None:
|
||||
self._cancel_update()
|
||||
|
|
Loading…
Reference in New Issue