mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Reduce usage of executer threads in AVM Fritz!Tools (#114570)
* call entity state update calls in one executer task * remove not needed wrapping * mark as "non-public" method * add guard against changes on _entity_update_functions
This commit is contained in:
parent
0732952b32
commit
98a1608604
@ -311,6 +311,17 @@ class FritzBoxTools(
|
|||||||
)
|
)
|
||||||
return unregister_entity_updates
|
return unregister_entity_updates
|
||||||
|
|
||||||
|
def _entity_states_update(self) -> dict:
|
||||||
|
"""Run registered entity update calls."""
|
||||||
|
entity_states = {}
|
||||||
|
for key in list(self._entity_update_functions):
|
||||||
|
if (update_fn := self._entity_update_functions.get(key)) is not None:
|
||||||
|
_LOGGER.debug("update entity %s", key)
|
||||||
|
entity_states[key] = update_fn(
|
||||||
|
self.fritz_status, self.data["entity_states"].get(key)
|
||||||
|
)
|
||||||
|
return entity_states
|
||||||
|
|
||||||
async def _async_update_data(self) -> UpdateCoordinatorDataType:
|
async def _async_update_data(self) -> UpdateCoordinatorDataType:
|
||||||
"""Update FritzboxTools data."""
|
"""Update FritzboxTools data."""
|
||||||
entity_data: UpdateCoordinatorDataType = {
|
entity_data: UpdateCoordinatorDataType = {
|
||||||
@ -319,15 +330,9 @@ class FritzBoxTools(
|
|||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
await self.async_scan_devices()
|
await self.async_scan_devices()
|
||||||
for key in list(self._entity_update_functions):
|
entity_data["entity_states"] = await self.hass.async_add_executor_job(
|
||||||
_LOGGER.debug("update entity %s", key)
|
self._entity_states_update
|
||||||
entity_data["entity_states"][
|
)
|
||||||
key
|
|
||||||
] = await self.hass.async_add_executor_job(
|
|
||||||
self._entity_update_functions[key],
|
|
||||||
self.fritz_status,
|
|
||||||
self.data["entity_states"].get(key),
|
|
||||||
)
|
|
||||||
if self.has_call_deflections:
|
if self.has_call_deflections:
|
||||||
entity_data[
|
entity_data[
|
||||||
"call_deflections"
|
"call_deflections"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user