Add setup time detail to diagnostics (#117766)
This commit is contained in:
parent
13ba8e62a9
commit
149120b749
4 changed files with 25 additions and 11 deletions
|
@ -24,6 +24,7 @@ from homeassistant.helpers.json import (
|
||||||
from homeassistant.helpers.system_info import async_get_system_info
|
from homeassistant.helpers.system_info import async_get_system_info
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
from homeassistant.loader import async_get_custom_components, async_get_integration
|
from homeassistant.loader import async_get_custom_components, async_get_integration
|
||||||
|
from homeassistant.setup import async_get_domain_setup_times
|
||||||
from homeassistant.util.json import format_unserializable_data
|
from homeassistant.util.json import format_unserializable_data
|
||||||
|
|
||||||
from .const import DOMAIN, REDACTED, DiagnosticsSubType, DiagnosticsType
|
from .const import DOMAIN, REDACTED, DiagnosticsSubType, DiagnosticsType
|
||||||
|
@ -178,17 +179,15 @@ async def _async_get_json_file_response(
|
||||||
"version": cc_obj.version,
|
"version": cc_obj.version,
|
||||||
"requirements": cc_obj.requirements,
|
"requirements": cc_obj.requirements,
|
||||||
}
|
}
|
||||||
|
payload = {
|
||||||
|
"home_assistant": hass_sys_info,
|
||||||
|
"custom_components": custom_components,
|
||||||
|
"integration_manifest": integration.manifest,
|
||||||
|
"setup_times": async_get_domain_setup_times(hass, domain),
|
||||||
|
"data": data,
|
||||||
|
}
|
||||||
try:
|
try:
|
||||||
json_data = json.dumps(
|
json_data = json.dumps(payload, indent=2, cls=ExtendedJSONEncoder)
|
||||||
{
|
|
||||||
"home_assistant": hass_sys_info,
|
|
||||||
"custom_components": custom_components,
|
|
||||||
"integration_manifest": integration.manifest,
|
|
||||||
"data": data,
|
|
||||||
},
|
|
||||||
indent=2,
|
|
||||||
cls=ExtendedJSONEncoder,
|
|
||||||
)
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
"Failed to serialize to JSON: %s/%s%s. Bad data at %s",
|
"Failed to serialize to JSON: %s/%s%s. Bad data at %s",
|
||||||
|
@ -197,7 +196,7 @@ async def _async_get_json_file_response(
|
||||||
f"/{DiagnosticsSubType.DEVICE.value}/{sub_id}"
|
f"/{DiagnosticsSubType.DEVICE.value}/{sub_id}"
|
||||||
if sub_id is not None
|
if sub_id is not None
|
||||||
else "",
|
else "",
|
||||||
format_unserializable_data(find_paths_unserializable_data(data)),
|
format_unserializable_data(find_paths_unserializable_data(payload)),
|
||||||
)
|
)
|
||||||
return web.Response(status=HTTPStatus.INTERNAL_SERVER_ERROR)
|
return web.Response(status=HTTPStatus.INTERNAL_SERVER_ERROR)
|
||||||
|
|
||||||
|
|
|
@ -811,3 +811,11 @@ def async_get_setup_timings(hass: core.HomeAssistant) -> dict[str, float]:
|
||||||
domain_timings[domain] = total_top_level + group_max
|
domain_timings[domain] = total_top_level + group_max
|
||||||
|
|
||||||
return domain_timings
|
return domain_timings
|
||||||
|
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def async_get_domain_setup_times(
|
||||||
|
hass: core.HomeAssistant, domain: str
|
||||||
|
) -> Mapping[str | None, dict[SetupPhases, float]]:
|
||||||
|
"""Return timing data for each integration."""
|
||||||
|
return _setup_times(hass).get(domain, {})
|
||||||
|
|
|
@ -93,6 +93,7 @@ async def test_download_diagnostics(
|
||||||
|
|
||||||
assert await _get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {
|
assert await _get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {
|
||||||
"home_assistant": hass_sys_info,
|
"home_assistant": hass_sys_info,
|
||||||
|
"setup_times": {},
|
||||||
"custom_components": {
|
"custom_components": {
|
||||||
"test": {
|
"test": {
|
||||||
"documentation": "http://example.com",
|
"documentation": "http://example.com",
|
||||||
|
@ -256,6 +257,7 @@ async def test_download_diagnostics(
|
||||||
"requirements": [],
|
"requirements": [],
|
||||||
},
|
},
|
||||||
"data": {"device": "info"},
|
"data": {"device": "info"},
|
||||||
|
"setup_times": {},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1102,6 +1102,11 @@ async def test_async_get_setup_timings(hass) -> None:
|
||||||
"sensor": 1,
|
"sensor": 1,
|
||||||
"filter": 2,
|
"filter": 2,
|
||||||
}
|
}
|
||||||
|
assert setup.async_get_domain_setup_times(hass, "filter") == {
|
||||||
|
"123456": {
|
||||||
|
setup.SetupPhases.PLATFORM_SETUP: 2,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_config_entry_from_yaml(
|
async def test_setup_config_entry_from_yaml(
|
||||||
|
|
Loading…
Add table
Reference in a new issue