mirror of
https://github.com/home-assistant/core.git
synced 2026-02-14 23:28:42 +00:00
Handle invalid data
This commit is contained in:
@@ -443,7 +443,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
panels_store = hass.data[DATA_PANELS_STORE] = Store[dict[str, dict[str, Any]]](
|
||||
hass, PANELS_STORAGE_VERSION, PANELS_STORAGE_KEY
|
||||
)
|
||||
hass.data[DATA_PANELS_CONFIG] = await panels_store.async_load() or {}
|
||||
loaded: Any = await panels_store.async_load()
|
||||
if not isinstance(loaded, dict):
|
||||
if loaded is not None:
|
||||
_LOGGER.warning("Ignoring invalid panel storage data")
|
||||
loaded = {}
|
||||
hass.data[DATA_PANELS_CONFIG] = loaded
|
||||
|
||||
websocket_api.async_register_command(hass, websocket_get_icons)
|
||||
websocket_api.async_register_command(hass, websocket_get_panels)
|
||||
|
||||
@@ -1421,3 +1421,28 @@ async def test_update_panel_hide_sidebar(
|
||||
msg = await ws_client.receive_json()
|
||||
assert msg["result"]["light"]["title"] == "light"
|
||||
assert msg["result"]["light"]["icon"] == "mdi:lamps"
|
||||
|
||||
|
||||
async def test_panels_config_invalid_storage(
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
hass_storage: dict[str, Any],
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test that corrupted panel storage is ignored with a warning."""
|
||||
hass_storage["frontend_panels"] = {
|
||||
"key": "frontend_panels",
|
||||
"version": 1,
|
||||
"data": "not_a_dict",
|
||||
}
|
||||
|
||||
assert await async_setup_component(hass, "frontend", {})
|
||||
assert "Ignoring invalid panel storage data" in caplog.text
|
||||
|
||||
client = await hass_ws_client(hass)
|
||||
|
||||
# Panels should still load with defaults
|
||||
await client.send_json({"id": 1, "type": "get_panels"})
|
||||
msg = await client.receive_json()
|
||||
assert msg["result"]["light"]["title"] == "light"
|
||||
assert msg["result"]["light"]["icon"] == "mdi:lamps"
|
||||
|
||||
Reference in New Issue
Block a user