Prepare SillyHome Next 1.0.0 dashboard and API rework
This commit is contained in:
@@ -28,8 +28,10 @@ class FakeHaReader(HaReader):
|
||||
def __init__(self, entities: list[HaEntitySummary], history: dict[str, list[float]]) -> None:
|
||||
self._entities = entities
|
||||
self._history = history
|
||||
self.read_entities_calls = 0
|
||||
|
||||
def read_entities(self) -> list[HaEntitySummary]:
|
||||
self.read_entities_calls += 1
|
||||
return list(self._entities)
|
||||
|
||||
def discover(
|
||||
@@ -230,6 +232,36 @@ def test_summary_is_lightweight_and_uses_cached_entity_metadata(tmp_path: Path)
|
||||
assert "numeric_candidates" not in payload[0]
|
||||
|
||||
|
||||
def test_dashboard_overview_uses_cache_without_ha_roundtrip(tmp_path: Path) -> None:
|
||||
with TestClient(app) as client:
|
||||
_install_service(tmp_path)
|
||||
reader = app.state.ha_reader
|
||||
client.get("/v1/actuators/discovery")
|
||||
client.post("/v1/actuators", json={"actuator_entity_id": "light.abstellkammer"})
|
||||
calls_before = reader.read_entities_calls
|
||||
|
||||
response = client.get("/v1/actuators/dashboard")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert reader.read_entities_calls == calls_before
|
||||
payload = response.json()
|
||||
assert payload["cache"]["available"] is True
|
||||
assert payload["cache"]["entity_count"] == 4
|
||||
assert payload["actuators"][0]["friendly_name"] == "Abstellkammer Licht"
|
||||
assert payload["discovery_groups"]
|
||||
|
||||
|
||||
def test_discovery_reads_entities_once_and_reuses_them(tmp_path: Path) -> None:
|
||||
with TestClient(app) as client:
|
||||
_install_service(tmp_path)
|
||||
reader = app.state.ha_reader
|
||||
|
||||
response = client.get("/v1/actuators/discovery", params={"refresh": True})
|
||||
|
||||
assert response.status_code == 200
|
||||
assert reader.read_entities_calls == 1
|
||||
|
||||
|
||||
def test_context_options_returns_learnable_entities(tmp_path: Path) -> None:
|
||||
with TestClient(app) as client:
|
||||
_install_service(tmp_path)
|
||||
|
||||
Reference in New Issue
Block a user