mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Update ZHA storage every 10 minutes (#39710)
This commit is contained in:
parent
8af64456ec
commit
f2d21ea735
@ -26,6 +26,7 @@ from homeassistant.helpers.entity_registry import (
|
|||||||
async_entries_for_device,
|
async_entries_for_device,
|
||||||
async_get_registry as get_ent_reg,
|
async_get_registry as get_ent_reg,
|
||||||
)
|
)
|
||||||
|
from homeassistant.helpers.event import async_track_time_interval
|
||||||
|
|
||||||
from . import discovery, typing as zha_typing
|
from . import discovery, typing as zha_typing
|
||||||
from .const import (
|
from .const import (
|
||||||
@ -117,6 +118,7 @@ class ZHAGateway:
|
|||||||
self.debug_enabled = False
|
self.debug_enabled = False
|
||||||
self._log_relay_handler = LogRelayHandler(hass, self)
|
self._log_relay_handler = LogRelayHandler(hass, self)
|
||||||
self._config_entry = config_entry
|
self._config_entry = config_entry
|
||||||
|
self._unsubs = []
|
||||||
|
|
||||||
async def async_initialize(self):
|
async def async_initialize(self):
|
||||||
"""Initialize controller and connect radio."""
|
"""Initialize controller and connect radio."""
|
||||||
@ -186,6 +188,13 @@ class ZHAGateway:
|
|||||||
"available" if zha_device.available else "unavailable",
|
"available" if zha_device.available else "unavailable",
|
||||||
delta_msg,
|
delta_msg,
|
||||||
)
|
)
|
||||||
|
# update the last seen time for devices every 10 minutes to avoid thrashing
|
||||||
|
# writes and shutdown issues where storage isn't updated
|
||||||
|
self._unsubs.append(
|
||||||
|
async_track_time_interval(
|
||||||
|
self._hass, self.async_update_device_storage, timedelta(minutes=10)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_load_groups(self) -> None:
|
def async_load_groups(self) -> None:
|
||||||
@ -515,7 +524,7 @@ class ZHAGateway:
|
|||||||
if device.status is DeviceStatus.INITIALIZED:
|
if device.status is DeviceStatus.INITIALIZED:
|
||||||
device.update_available(available)
|
device.update_available(available)
|
||||||
|
|
||||||
async def async_update_device_storage(self):
|
async def async_update_device_storage(self, *_):
|
||||||
"""Update the devices in the store."""
|
"""Update the devices in the store."""
|
||||||
for device in self.devices.values():
|
for device in self.devices.values():
|
||||||
self.zha_storage.async_update_device(device)
|
self.zha_storage.async_update_device(device)
|
||||||
@ -626,6 +635,8 @@ class ZHAGateway:
|
|||||||
async def shutdown(self):
|
async def shutdown(self):
|
||||||
"""Stop ZHA Controller Application."""
|
"""Stop ZHA Controller Application."""
|
||||||
_LOGGER.debug("Shutting down ZHA ControllerApplication")
|
_LOGGER.debug("Shutting down ZHA ControllerApplication")
|
||||||
|
for unsubscribe in self._unsubs:
|
||||||
|
unsubscribe()
|
||||||
await self.application_controller.shutdown()
|
await self.application_controller.shutdown()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user