Home Assistant Unofficial Reference 2024.12.1
system_health.py
Go to the documentation of this file.
1 """Provide info to system health."""
2 
3 import asyncio
4 
5 from homeassistant.components import system_health
6 from homeassistant.const import CONF_MODE
7 from homeassistant.core import HomeAssistant, callback
8 
9 from .const import DOMAIN, MODE_AUTO, MODE_STORAGE, MODE_YAML
10 
11 
12 @callback
14  hass: HomeAssistant, register: system_health.SystemHealthRegistration
15 ) -> None:
16  """Register system health callbacks."""
17  register.async_register_info(system_health_info, "/config/lovelace")
18 
19 
20 async def system_health_info(hass):
21  """Get info for the info page."""
22  health_info = {"dashboards": len(hass.data[DOMAIN]["dashboards"])}
23  health_info.update(await hass.data[DOMAIN]["resources"].async_get_info())
24 
25  dashboards_info = await asyncio.gather(
26  *(
27  hass.data[DOMAIN]["dashboards"][dashboard].async_get_info()
28  for dashboard in hass.data[DOMAIN]["dashboards"]
29  )
30  )
31 
32  modes = set()
33  for dashboard in dashboards_info:
34  for key in dashboard:
35  if isinstance(dashboard[key], int):
36  health_info[key] = health_info.get(key, 0) + dashboard[key]
37  elif key == CONF_MODE:
38  modes.add(dashboard[key])
39  else:
40  health_info[key] = dashboard[key]
41 
42  if hass.data[DOMAIN][CONF_MODE] == MODE_YAML:
43  health_info[CONF_MODE] = MODE_YAML
44  elif MODE_STORAGE in modes:
45  health_info[CONF_MODE] = MODE_STORAGE
46  elif MODE_YAML in modes:
47  health_info[CONF_MODE] = MODE_YAML
48  else:
49  health_info[CONF_MODE] = MODE_AUTO
50 
51  return health_info
None async_register(HomeAssistant hass, system_health.SystemHealthRegistration register)