fix: batch ha metadata and improve mobile dashboard
Some checks failed
quality / test (3.11) (push) Has been cancelled
quality / test (3.13) (push) Has been cancelled

This commit is contained in:
2026-06-14 22:52:42 +02:00
parent 2ae5576b8f
commit d87d3abc00
9 changed files with 170 additions and 32 deletions

View File

@@ -108,6 +108,27 @@ def test_list_entity_metadata_calls_template_api() -> None:
}
def test_list_entity_metadata_batches_template_calls() -> None:
responses = []
for index in range(3):
response = _response()
response.text = (
f'[{{"entity_id":"sensor.test_{index}",'
f'"area_name":"Area {index}","device_name":"Device {index}"}}]'
)
responses.append(response)
client = HaClient(HaClientSettings(url="http://ha.local", token="test-token"))
client._session.post = Mock(side_effect=responses) # type: ignore[method-assign]
entity_ids = [f"sensor.test_{index}" for index in range(401)]
metadata = client.list_entity_metadata(entity_ids)
assert client._session.post.call_count == 3
assert metadata["sensor.test_0"]["area_name"] == "Area 0"
assert metadata["sensor.test_1"]["device_name"] == "Device 1"
assert metadata["sensor.test_2"]["device_name"] == "Device 2"
def test_get_logbook_filters_entity_and_period() -> None:
response = _response(payload=[{"entity_id": "light.office"}])
client = _client_with_response(response)

View File

@@ -3,6 +3,7 @@ from __future__ import annotations
from datetime import datetime, timezone
from app.ha.client import HaClient, HaClientSettings
from app.ha.exceptions import HaHttpError
from app.ha.reader import HaReader
@@ -150,3 +151,23 @@ def test_ha_reader_finds_automation_that_targets_entity() -> None:
assert len(matches) == 1
assert matches[0].entity_id == "automation.storage_light"
assert matches[0].enabled is True
def test_ha_reader_ignores_automation_configs_not_exposed_by_ha() -> None:
client = FakeHaClient()
client.list_entities = lambda: [ # type: ignore[method-assign]
{
"entity_id": "automation.storage_light",
"state": "on",
"attributes": {
"id": "123",
"friendly_name": "Storage light",
},
}
]
client.get_automation_config = lambda automation_id: (_ for _ in ()).throw( # type: ignore[method-assign]
HaHttpError(404, "Resource not found")
)
reader = HaReader(client)
assert reader.find_automations_for_entity("light.storage") == []