Add json cache to lovelace config (#117843)

This commit is contained in:
J. Nick Koston 2024-05-24 02:07:43 -10:00 committed by GitHub
parent 2c09f72c33
commit 2308ff2cbf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 110 additions and 34 deletions

View file

@ -1,6 +1,7 @@
"""Test the Lovelace initialization."""
from collections.abc import Generator
import time
from typing import Any
from unittest.mock import MagicMock, patch
@ -180,6 +181,44 @@ async def test_lovelace_from_yaml(
assert len(events) == 1
# Make sure when the mtime changes, we reload the config
with (
patch(
"homeassistant.components.lovelace.dashboard.load_yaml_dict",
return_value={"hello": "yo3"},
),
patch(
"homeassistant.components.lovelace.dashboard.os.path.getmtime",
return_value=time.time(),
),
):
await client.send_json({"id": 9, "type": "lovelace/config", "force": False})
response = await client.receive_json()
assert response["success"]
assert response["result"] == {"hello": "yo3"}
assert len(events) == 2
# If the mtime is lower, preserve the cache
with (
patch(
"homeassistant.components.lovelace.dashboard.load_yaml_dict",
return_value={"hello": "yo4"},
),
patch(
"homeassistant.components.lovelace.dashboard.os.path.getmtime",
return_value=0,
),
):
await client.send_json({"id": 10, "type": "lovelace/config", "force": False})
response = await client.receive_json()
assert response["success"]
assert response["result"] == {"hello": "yo3"}
assert len(events) == 2
@pytest.mark.parametrize("url_path", ["test-panel", "test-panel-no-sidebar"])
async def test_dashboard_from_yaml(