Skip to content

Commit

Permalink
Reolink schedule update after firmware update (#104867)
Browse files Browse the repository at this point in the history
  • Loading branch information
starkillerOG committed Dec 1, 2023
1 parent 450bc8d commit 742e2db
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion homeassistant/components/reolink/update.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Update entities for Reolink devices."""
from __future__ import annotations

from datetime import datetime
import logging
from typing import Any, Literal

Expand All @@ -13,16 +14,19 @@
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
from .entity import ReolinkBaseCoordinatorEntity

LOGGER = logging.getLogger(__name__)

POLL_AFTER_INSTALL = 120


async def async_setup_entry(
hass: HomeAssistant,
Expand Down Expand Up @@ -51,6 +55,7 @@ def __init__(
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:
Expand Down Expand Up @@ -100,3 +105,16 @@ async def async_install(
) 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()

0 comments on commit 742e2db

Please sign in to comment.