Refactor integration startup time tracking to reduce overhead (#110136)

* Refactor integration startup time tracking to reduce overhead

- Use monotonic time for watching integration startup time as it avoids incorrect values if time moves backwards because of ntp during startup and reduces many time conversions since we want durations in seconds and not local time

- Use loop scheduling instead of a task

- Moves all the dispatcher logic into the new _WatchPendingSetups

* websocket as well

* tweaks

* simplify logic

* preserve logic

* preserve logic

* lint

* adjust
This commit is contained in:
J. Nick Koston 2024-02-17 20:47:55 -06:00 committed by GitHub
parent 9bc130c131
commit def6c5c21c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 79 additions and 59 deletions

View file

@ -2,7 +2,6 @@
from __future__ import annotations
from collections.abc import Callable
import datetime as dt
from functools import lru_cache, partial
import json
import logging
@ -540,13 +539,12 @@ def handle_integration_setup_info(
hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any]
) -> None:
"""Handle integrations command."""
setup_time: dict[str, float] = hass.data[DATA_SETUP_TIME]
connection.send_result(
msg["id"],
[
{"domain": integration, "seconds": timedelta.total_seconds()}
for integration, timedelta in cast(
dict[str, dt.timedelta], hass.data[DATA_SETUP_TIME]
).items()
{"domain": integration, "seconds": seconds}
for integration, seconds in setup_time.items()
],
)