Reolink schedule update after firmware update (#104867)
This commit is contained in:
parent
8fd9761e7d
commit
39026e3b53
1 changed files with 19 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
"""Update entities for Reolink devices."""
|
"""Update entities for Reolink devices."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, Literal
|
from typing import Any, Literal
|
||||||
|
|
||||||
|
@ -13,9 +14,10 @@ from homeassistant.components.update import (
|
||||||
UpdateEntityFeature,
|
UpdateEntityFeature,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
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.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
from homeassistant.helpers.event import async_call_later
|
||||||
|
|
||||||
from . import ReolinkData
|
from . import ReolinkData
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
@ -23,6 +25,8 @@ from .entity import ReolinkBaseCoordinatorEntity
|
||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
POLL_AFTER_INSTALL = 120
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
@ -51,6 +55,7 @@ class ReolinkUpdateEntity(
|
||||||
super().__init__(reolink_data, reolink_data.firmware_coordinator)
|
super().__init__(reolink_data, reolink_data.firmware_coordinator)
|
||||||
|
|
||||||
self._attr_unique_id = f"{self._host.unique_id}"
|
self._attr_unique_id = f"{self._host.unique_id}"
|
||||||
|
self._cancel_update: CALLBACK_TYPE | None = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def installed_version(self) -> str | None:
|
def installed_version(self) -> str | None:
|
||||||
|
@ -100,3 +105,16 @@ class ReolinkUpdateEntity(
|
||||||
) from err
|
) from err
|
||||||
finally:
|
finally:
|
||||||
self.async_write_ha_state()
|
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…
Add table
Reference in a new issue