mirror of
https://github.com/home-assistant/core
synced 2024-09-06 10:29:55 +02:00
Fix Lovelace resources health info (#33309)
* Fix Lovelace resources health info * Fix tests
This commit is contained in:
parent
4a2236fe85
commit
1477087c71
@ -234,7 +234,10 @@ async def create_yaml_resource_col(hass, yaml_resources):
|
||||
|
||||
async def system_health_info(hass):
|
||||
"""Get info for the info page."""
|
||||
return await hass.data[DOMAIN]["dashboards"][None].async_get_info()
|
||||
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())
|
||||
return health_info
|
||||
|
||||
|
||||
@callback
|
||||
|
@ -101,7 +101,7 @@ class LovelaceStorage(LovelaceConfig):
|
||||
return MODE_STORAGE
|
||||
|
||||
async def async_get_info(self):
|
||||
"""Return the YAML storage mode."""
|
||||
"""Return the Lovelace storage info."""
|
||||
if self._data is None:
|
||||
await self._load()
|
||||
|
||||
@ -213,7 +213,6 @@ def _config_info(mode, config):
|
||||
"""Generate info about the config."""
|
||||
return {
|
||||
"mode": mode,
|
||||
"resources": len(config.get("resources", [])),
|
||||
"views": len(config.get("views", [])),
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,10 @@ class ResourceYAMLCollection:
|
||||
"""Initialize a resource YAML collection."""
|
||||
self.data = data
|
||||
|
||||
async def async_get_info(self):
|
||||
"""Return the resources info for YAML mode."""
|
||||
return {"resources": len(self.async_items() or [])}
|
||||
|
||||
@callback
|
||||
def async_items(self) -> List[dict]:
|
||||
"""Return list of items in collection."""
|
||||
@ -55,6 +59,14 @@ class ResourceStorageCollection(collection.StorageCollection):
|
||||
)
|
||||
self.ll_config = ll_config
|
||||
|
||||
async def async_get_info(self):
|
||||
"""Return the resources info for YAML mode."""
|
||||
if not self.loaded:
|
||||
await self.async_load()
|
||||
self.loaded = True
|
||||
|
||||
return {"resources": len(self.async_items() or [])}
|
||||
|
||||
async def _async_load_data(self) -> Optional[dict]:
|
||||
"""Load the data."""
|
||||
data = await self.store.async_load()
|
||||
|
@ -165,7 +165,7 @@ async def test_system_health_info_autogen(hass):
|
||||
"""Test system health info endpoint."""
|
||||
assert await async_setup_component(hass, "lovelace", {})
|
||||
info = await get_system_health_info(hass, "lovelace")
|
||||
assert info == {"mode": "auto-gen"}
|
||||
assert info == {"dashboards": 1, "mode": "auto-gen", "resources": 0}
|
||||
|
||||
|
||||
async def test_system_health_info_storage(hass, hass_storage):
|
||||
@ -177,7 +177,7 @@ async def test_system_health_info_storage(hass, hass_storage):
|
||||
}
|
||||
assert await async_setup_component(hass, "lovelace", {})
|
||||
info = await get_system_health_info(hass, "lovelace")
|
||||
assert info == {"mode": "storage", "resources": 0, "views": 0}
|
||||
assert info == {"dashboards": 1, "mode": "storage", "resources": 0, "views": 0}
|
||||
|
||||
|
||||
async def test_system_health_info_yaml(hass):
|
||||
@ -188,7 +188,7 @@ async def test_system_health_info_yaml(hass):
|
||||
return_value={"views": [{"cards": []}]},
|
||||
):
|
||||
info = await get_system_health_info(hass, "lovelace")
|
||||
assert info == {"mode": "yaml", "resources": 0, "views": 1}
|
||||
assert info == {"dashboards": 1, "mode": "yaml", "resources": 0, "views": 1}
|
||||
|
||||
|
||||
async def test_system_health_info_yaml_not_found(hass):
|
||||
@ -196,8 +196,10 @@ async def test_system_health_info_yaml_not_found(hass):
|
||||
assert await async_setup_component(hass, "lovelace", {"lovelace": {"mode": "YAML"}})
|
||||
info = await get_system_health_info(hass, "lovelace")
|
||||
assert info == {
|
||||
"dashboards": 1,
|
||||
"mode": "yaml",
|
||||
"error": "{} not found".format(hass.config.path("ui-lovelace.yaml")),
|
||||
"resources": 0,
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user