M8-T10: add WarmteLink serial worker manager

This commit is contained in:
2026-08-23 21:22:06 +02:00
parent afe653bafa
commit 4884a19e3d
6 changed files with 721 additions and 11 deletions
+38
View File
@@ -79,6 +79,44 @@ def test_source_profiles_and_crud_mask_secrets(auth_database):
engine.dispose()
def test_serial_source_reconciles_only_after_commit(auth_database, monkeypatch):
"""Creation and mutation trigger the worker manager after a successful commit."""
from app.api.routes.api import meter_sources
calls = []
monkeypatch.setattr(meter_sources.warmtelink_worker_manager, "reconcile", lambda: calls.append(True))
client, engine = _client(auth_database)
with client:
_login(client)
baseline = len(calls)
response = client.post("/api/energy/sources", headers={"X-CSRF-Token": _CSRF}, json={
"name": "Serial", "kind": "warmtelink_serial", "config": {"path": "/dev/ttyUSB0"},
})
assert response.status_code == 201
source_uuid = response.json()["uuid"]
assert len(calls) == baseline + 1
assert client.patch(f"/api/energy/sources/{source_uuid}", headers={"X-CSRF-Token": _CSRF}, json={"enabled": False}).status_code == 200
assert len(calls) == baseline + 2
engine.dispose()
def test_serial_source_commit_is_not_reported_as_failed_when_reconcile_raises(auth_database, monkeypatch):
from app.api.routes.api import meter_sources
client, engine = _client(auth_database)
with client:
_login(client)
monkeypatch.setattr(
meter_sources.warmtelink_worker_manager, "reconcile",
lambda: (_ for _ in ()).throw(RuntimeError()),
)
response = client.post("/api/energy/sources", headers={"X-CSRF-Token": _CSRF}, json={
"name": "Serial", "kind": "warmtelink_serial", "config": {"path": "/dev/ttyUSB0"},
})
assert response.status_code == 201
engine.dispose()
def test_binding_routes_and_atomic_meter_declaration(auth_database):
client, engine = _client(auth_database)
with client: