mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00: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):
|
async def system_health_info(hass):
|
||||||
"""Get info for the info page."""
|
"""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
|
@callback
|
||||||
|
@ -101,7 +101,7 @@ class LovelaceStorage(LovelaceConfig):
|
|||||||
return MODE_STORAGE
|
return MODE_STORAGE
|
||||||
|
|
||||||
async def async_get_info(self):
|
async def async_get_info(self):
|
||||||
"""Return the YAML storage mode."""
|
"""Return the Lovelace storage info."""
|
||||||
if self._data is None:
|
if self._data is None:
|
||||||
await self._load()
|
await self._load()
|
||||||
|
|
||||||
@ -213,7 +213,6 @@ def _config_info(mode, config):
|
|||||||
"""Generate info about the config."""
|
"""Generate info about the config."""
|
||||||
return {
|
return {
|
||||||
"mode": mode,
|
"mode": mode,
|
||||||
"resources": len(config.get("resources", [])),
|
|
||||||
"views": len(config.get("views", [])),
|
"views": len(config.get("views", [])),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +34,10 @@ class ResourceYAMLCollection:
|
|||||||
"""Initialize a resource YAML collection."""
|
"""Initialize a resource YAML collection."""
|
||||||
self.data = data
|
self.data = data
|
||||||
|
|
||||||
|
async def async_get_info(self):
|
||||||
|
"""Return the resources info for YAML mode."""
|
||||||
|
return {"resources": len(self.async_items() or [])}
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_items(self) -> List[dict]:
|
def async_items(self) -> List[dict]:
|
||||||
"""Return list of items in collection."""
|
"""Return list of items in collection."""
|
||||||
@ -55,6 +59,14 @@ class ResourceStorageCollection(collection.StorageCollection):
|
|||||||
)
|
)
|
||||||
self.ll_config = ll_config
|
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]:
|
async def _async_load_data(self) -> Optional[dict]:
|
||||||
"""Load the data."""
|
"""Load the data."""
|
||||||
data = await self.store.async_load()
|
data = await self.store.async_load()
|
||||||
|
@ -165,7 +165,7 @@ async def test_system_health_info_autogen(hass):
|
|||||||
"""Test system health info endpoint."""
|
"""Test system health info endpoint."""
|
||||||
assert await async_setup_component(hass, "lovelace", {})
|
assert await async_setup_component(hass, "lovelace", {})
|
||||||
info = await get_system_health_info(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):
|
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", {})
|
assert await async_setup_component(hass, "lovelace", {})
|
||||||
info = await get_system_health_info(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):
|
async def test_system_health_info_yaml(hass):
|
||||||
@ -188,7 +188,7 @@ async def test_system_health_info_yaml(hass):
|
|||||||
return_value={"views": [{"cards": []}]},
|
return_value={"views": [{"cards": []}]},
|
||||||
):
|
):
|
||||||
info = await get_system_health_info(hass, "lovelace")
|
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):
|
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"}})
|
assert await async_setup_component(hass, "lovelace", {"lovelace": {"mode": "YAML"}})
|
||||||
info = await get_system_health_info(hass, "lovelace")
|
info = await get_system_health_info(hass, "lovelace")
|
||||||
assert info == {
|
assert info == {
|
||||||
|
"dashboards": 1,
|
||||||
"mode": "yaml",
|
"mode": "yaml",
|
||||||
"error": "{} not found".format(hass.config.path("ui-lovelace.yaml")),
|
"error": "{} not found".format(hass.config.path("ui-lovelace.yaml")),
|
||||||
|
"resources": 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user