Adjust system info for lovelace with multiple dashboards (#44796)

This commit is contained in:
Joakim Sørensen 2021-01-04 18:02:46 +01:00 committed by GitHub
parent de780c6d35
commit 766f89f338
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 2 deletions

View File

@ -16,6 +16,7 @@ DEFAULT_ICON = "hass:view-dashboard"
CONF_MODE = "mode"
MODE_YAML = "yaml"
MODE_STORAGE = "storage"
MODE_AUTO = "auto-gen"
LOVELACE_CONFIG_FILE = "ui-lovelace.yaml"
CONF_RESOURCES = "resources"

View File

@ -1,8 +1,10 @@
"""Provide info to system health."""
import asyncio
from homeassistant.components import system_health
from homeassistant.core import HomeAssistant, callback
from .const import DOMAIN
from .const import CONF_MODE, DOMAIN, MODE_AUTO, MODE_STORAGE, MODE_YAML
@callback
@ -16,6 +18,30 @@ def async_register(
async def system_health_info(hass):
"""Get info for the info page."""
health_info = {"dashboards": len(hass.data[DOMAIN]["dashboards"])}
health_info.update(await hass.data[DOMAIN]["dashboards"][None].async_get_info())
health_info.update(await hass.data[DOMAIN]["resources"].async_get_info())
dashboards_info = await asyncio.gather(
*[
hass.data[DOMAIN]["dashboards"][dashboard].async_get_info()
for dashboard in hass.data[DOMAIN]["dashboards"]
]
)
modes = set()
for dashboard in dashboards_info:
for key in dashboard:
if isinstance(dashboard[key], int):
health_info[key] = health_info.get(key, 0) + dashboard[key]
elif key == CONF_MODE:
modes.add(dashboard[key])
else:
health_info[key] = dashboard[key]
if MODE_STORAGE in modes:
health_info[CONF_MODE] = MODE_STORAGE
elif MODE_YAML in modes:
health_info[CONF_MODE] = MODE_YAML
else:
health_info[CONF_MODE] = MODE_AUTO
return health_info