From 766f89f3385882752b0febba7add6ff91cbe1205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Mon, 4 Jan 2021 18:02:46 +0100 Subject: [PATCH] Adjust system info for lovelace with multiple dashboards (#44796) --- homeassistant/components/lovelace/const.py | 1 + .../components/lovelace/system_health.py | 30 +++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/lovelace/const.py b/homeassistant/components/lovelace/const.py index a093c672dd6..e93649de451 100644 --- a/homeassistant/components/lovelace/const.py +++ b/homeassistant/components/lovelace/const.py @@ -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" diff --git a/homeassistant/components/lovelace/system_health.py b/homeassistant/components/lovelace/system_health.py index e0d1152a049..a148427c9bd 100644 --- a/homeassistant/components/lovelace/system_health.py +++ b/homeassistant/components/lovelace/system_health.py @@ -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