Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce usage of executer threads in AVM Fritz!Tools #114570

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 15 additions & 9 deletions homeassistant/components/fritz/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,20 @@ def unregister_entity_updates() -> None:
)
return unregister_entity_updates

async def async_entity_states_update(self) -> dict:
"""Run registered entity update calls."""

def _entity_states_update() -> dict:
MartinHjelmare marked this conversation as resolved.
Show resolved Hide resolved
entity_states = {}
for key in list(self._entity_update_functions):
_LOGGER.debug("update entity %s", key)
entity_states[key] = self._entity_update_functions[key](
self.fritz_status, self.data["entity_states"].get(key)
)
return entity_states

return await self.hass.async_add_executor_job(_entity_states_update)

async def _async_update_data(self) -> UpdateCoordinatorDataType:
"""Update FritzboxTools data."""
entity_data: UpdateCoordinatorDataType = {
Expand All @@ -319,15 +333,7 @@ async def _async_update_data(self) -> UpdateCoordinatorDataType:
}
try:
await self.async_scan_devices()
for key in list(self._entity_update_functions):
_LOGGER.debug("update entity %s", key)
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),
)
entity_data["entity_states"] = await self.async_entity_states_update()
if self.has_call_deflections:
entity_data[
"call_deflections"
Expand Down