Don't return resources in safe mode (#102865)

pull/102983/head
Paul Bottein 2023-10-27 11:30:37 +02:00 committed by GitHub
parent 8eaf38cd44
commit e0885ef109
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View File

@ -60,6 +60,9 @@ async def websocket_lovelace_resources(
"""Send Lovelace UI resources over WebSocket configuration."""
resources = hass.data[DOMAIN]["resources"]
if hass.config.safe_mode:
connection.send_result(msg["id"], [])
if not resources.loaded:
await resources.async_load()
resources.loaded = True

View File

@ -185,3 +185,26 @@ async def test_storage_resources_import_invalid(
"resources"
in hass_storage[dashboard.CONFIG_STORAGE_KEY_DEFAULT]["data"]["config"]
)
async def test_storage_resources_safe_mode(
hass: HomeAssistant, hass_ws_client, hass_storage: dict[str, Any]
) -> None:
"""Test defining resources in storage config."""
resource_config = [{**item, "id": uuid.uuid4().hex} for item in RESOURCE_EXAMPLES]
hass_storage[resources.RESOURCE_STORAGE_KEY] = {
"key": resources.RESOURCE_STORAGE_KEY,
"version": 1,
"data": {"items": resource_config},
}
assert await async_setup_component(hass, "lovelace", {})
client = await hass_ws_client(hass)
hass.config.safe_mode = True
# Fetch data
await client.send_json({"id": 5, "type": "lovelace/resources"})
response = await client.receive_json()
assert response["success"]
assert response["result"] == []