AUFGERAUMT: Root auf 10 sichtbare Elemente reduziert
Der Nutzer hat recht: Der Ordner war voller Entwicklungs-Muell. Jetzt ist sauber getrennt: ROOT (was der Nutzer sieht und braucht): - run.py = das Programm - hms_app/ = der Anwendungscode - HMS MediaEngine.app = macOS Doppelklick-Starter - HMS-Start.vbs = Windows Doppelklick-Starter - HMS-Install.vbs = Windows Erst-Installation - HMS-Mac-Install.command = macOS Homebrew-Installation - HMS-Portable-Install.command = macOS Portable-Installation (16GB-Fix) - installer_gui.py = grafischer Installer - launcher.pyw + launcher_core.py = interne Start-Logik - LIESMICH.txt = 10-Zeilen-Kurzanleitung - .gitignore _entwicklung/ (alles andere, NICHT benoetigt): - packages/ apps/ native/ plugins/ tools/ schemas/ tests/ docs/ build/ fixture_profiles/ - PLAN.md STATUS.md ERRORS.md TEST_REPORT.md CHANGELOG.md README.md - pyproject.toml uv.lock setup_*.sh/ps1 make_mac_app.py Diese Trennung gilt ab sofort fuer alle Commits. Der Nutzer kann _entwicklung/ loeschen wenn er Platz braucht - die App laeuft ohne. Verifiziert: App startet nach Aufraeumen unveraendert (Health 200).
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
"""hms_control_server – minimaler Control Core (PLAN.md §6.1B, §36 Nr. 9).
|
||||
|
||||
FastAPI-REST + WebSocket für denselben Parametersatz, den Art-Net bedient.
|
||||
Autoritative Instanz ist die ParameterEngine; alle Quellen laufen über sie.
|
||||
"""
|
||||
|
||||
from hms_control_server.app import create_app
|
||||
|
||||
__all__ = ["create_app"]
|
||||
@@ -0,0 +1,10 @@
|
||||
"""Control-Core-Start (Entwicklung): python -m hms_control_server"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import uvicorn
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Phase 0: Development-Start. Produktion startet über den Launcher,
|
||||
# bindet 127.0.0.1 und wählt freie Ports (§3.1, §9.2).
|
||||
uvicorn.run("hms_control_server.app:app", host="127.0.0.1", port=8000)
|
||||
@@ -0,0 +1,433 @@
|
||||
"""FastAPI-Anwendung des Control Core.
|
||||
|
||||
Endpunkte:
|
||||
- GET /api/v1/system/health
|
||||
- GET /api/v1/system/identity (node_id, display_name, roles; nicht vertraulich)
|
||||
- GET /api/v1/system/capabilities
|
||||
- GET /api/v1/parameters
|
||||
- POST /api/v1/commands (parameter.set mit Revision-Prüfung und Idempotenz)
|
||||
- POST /api/v1/commands/{command_id}/release
|
||||
- GET /api/v1/diagnostics
|
||||
- GET /api/v1/cluster/nodes
|
||||
- GET /api/v1/projects, POST/GET/PUT/DELETE /api/v1/projects/{id}
|
||||
- POST /api/v1/media/import
|
||||
- GET /api/v1/media
|
||||
- GET /api/v1/plugins
|
||||
- GET /api/v1/artnet/status
|
||||
- WS /ws (State-Snapshot + Updates)
|
||||
|
||||
Commands folgen §23.2: command_id, type, expected_revision, actor, payload.
|
||||
Node-Identität: persistente node_id aus userdata/identity (§3.6, §6.3);
|
||||
im Dev-Modus ohne App-Root wird eine ephemeral-Identität erzeugt.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import uuid
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import FastAPI, HTTPException, UploadFile, WebSocket, WebSocketDisconnect
|
||||
from hms_capabilities.probe import CapabilityReport
|
||||
from hms_cluster.registry import NodeRegistry
|
||||
from hms_domain.identity import NodeIdentity, NodeRole
|
||||
from hms_domain.model import (
|
||||
Project,
|
||||
)
|
||||
from hms_media import ImportStatus, MediaLibrary
|
||||
from hms_parameter.engine import (
|
||||
ControlSource,
|
||||
ParameterEngine,
|
||||
RevisionConflict,
|
||||
)
|
||||
from hms_persistence import Database
|
||||
from hms_persistence.state_store import ProjectStateStore
|
||||
from hms_protocol.idempotency import IdempotencyRegistry
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class SetParameterCommand(BaseModel):
|
||||
"""parameter.set-Command (§23.2)."""
|
||||
|
||||
command_id: str = Field(default_factory=lambda: str(uuid.uuid4()))
|
||||
type: str = "parameter.set"
|
||||
expected_revision: int | None = None
|
||||
actor: dict = Field(default_factory=lambda: {"type": "web", "id": "operator-session"})
|
||||
payload: dict
|
||||
|
||||
|
||||
class ReleaseCommand(BaseModel):
|
||||
source: str = "web"
|
||||
|
||||
|
||||
class CreateProjectBody(BaseModel):
|
||||
name: str = "Neues Projekt"
|
||||
|
||||
|
||||
def _builtin_plugin_dir() -> Path:
|
||||
"""Löst das Builtin-Plugin-Verzeichnis robust auf (§14.2).
|
||||
|
||||
Sucht vom aktuellen Arbeitsverzeichnis aus über bekannte Kandidaten;
|
||||
im Entwickungsbaum ist das Repo-Root die Basis.
|
||||
"""
|
||||
candidates = [
|
||||
Path.cwd() / "plugins" / "builtin",
|
||||
Path(__file__).resolve().parents[3] / "plugins" / "builtin",
|
||||
]
|
||||
for candidate in candidates:
|
||||
if candidate.is_dir():
|
||||
return candidate
|
||||
return candidates[0]
|
||||
|
||||
|
||||
def _discover_builtin_plugins(mgr, builtin_dir: Path) -> list[str]:
|
||||
"""Entdeckt Plugins je Kategorie-Unterverzeichnis (§14.2)."""
|
||||
errors: list[str] = []
|
||||
for category in sorted(builtin_dir.iterdir()):
|
||||
if not category.is_dir():
|
||||
continue
|
||||
errors.extend(mgr.discover(category))
|
||||
return errors
|
||||
|
||||
|
||||
class _State:
|
||||
def __init__(self, identity: NodeIdentity, data_dir: Path | None = None) -> None:
|
||||
self.identity = identity
|
||||
self.engine = ParameterEngine()
|
||||
self.registry = IdempotencyRegistry()
|
||||
self.report = CapabilityReport()
|
||||
self.nodes = NodeRegistry()
|
||||
self.subscribers: list[asyncio.Queue] = []
|
||||
# Persistenz und Projekt-Verwaltung (§24, §6.4)
|
||||
self.data_dir = data_dir or Path("/tmp/hms-dev-data")
|
||||
self.database = Database(self.data_dir / "database" / "hms.db")
|
||||
self.database.open()
|
||||
self.database.migrate(backup_dir=self.data_dir / "backups")
|
||||
self.state_store = ProjectStateStore()
|
||||
self.media_library = MediaLibrary(self.data_dir / "media")
|
||||
|
||||
|
||||
def create_app(identity: NodeIdentity | None = None) -> FastAPI:
|
||||
"""Erzeugt die Control-Core-App.
|
||||
|
||||
identity: produktiv vom Launcher geladene persistente Identität
|
||||
(userdata/identity). Ohne Angabe gilt Dev-Modus mit ephemeral-Identität
|
||||
(jede App-Instanz erhält eine eigene ID; für Showbetrieb unzulässig).
|
||||
"""
|
||||
if identity is None:
|
||||
identity = NodeIdentity.ephemeral(
|
||||
"Dev Node", frozenset({NodeRole.RENDER_NODE, NodeRole.COORDINATOR})
|
||||
)
|
||||
app = FastAPI(title="HMS MediaEngine Control Core", version="0.1.0")
|
||||
state = _State(identity)
|
||||
# Eigene Node in die Registry eintragen (§6.3)
|
||||
state.nodes.register(
|
||||
node_id=identity.node_id,
|
||||
display_name=identity.display_name,
|
||||
roles=tuple(r.value for r in identity.roles),
|
||||
)
|
||||
|
||||
def _broadcast(event: dict) -> None:
|
||||
for queue in list(state.subscribers):
|
||||
queue.put_nowait(event)
|
||||
|
||||
# ---------- System (§23.1) ----------
|
||||
|
||||
@app.get("/api/v1/system/health")
|
||||
async def health() -> dict:
|
||||
return {
|
||||
"status": "ok",
|
||||
"phase": 5,
|
||||
"node_id": state.identity.node_id,
|
||||
"revision": state.engine.revision,
|
||||
}
|
||||
|
||||
@app.get("/api/v1/system/identity")
|
||||
async def system_identity() -> dict:
|
||||
"""Nicht vertrauliche Selbstauskunft (§27.1: keine Tokens/Secrets)."""
|
||||
return {
|
||||
"node_id": state.identity.node_id,
|
||||
"display_name": state.identity.display_name,
|
||||
"roles": sorted(r.value for r in state.identity.roles),
|
||||
"renders_locally": state.identity.renders_locally,
|
||||
"is_coordinator": state.identity.is_coordinator,
|
||||
}
|
||||
|
||||
@app.get("/api/v1/system/capabilities")
|
||||
async def capabilities() -> dict:
|
||||
return state.report.as_dict()
|
||||
|
||||
@app.get("/api/v1/parameters")
|
||||
async def parameters() -> dict:
|
||||
snap = state.engine.snapshot()
|
||||
return {"revision": snap.revision, "values": snap.as_dict()}
|
||||
|
||||
@app.get("/api/v1/diagnostics")
|
||||
async def diagnostics() -> dict:
|
||||
return {
|
||||
"renderer": "not_connected",
|
||||
"artnet": "not_started",
|
||||
"revision": state.engine.revision,
|
||||
"node_id": state.identity.node_id,
|
||||
"state_revision": state.state_store.state_revision,
|
||||
"project_revision": state.state_store.project_revision,
|
||||
}
|
||||
|
||||
# ---------- Commands (§23.2) ----------
|
||||
|
||||
@app.post("/api/v1/commands")
|
||||
async def post_command(cmd: SetParameterCommand) -> dict:
|
||||
if cmd.type != "parameter.set":
|
||||
raise HTTPException(status_code=400, detail=f"unknown command type {cmd.type!r}")
|
||||
if not state.registry.register(cmd.command_id):
|
||||
prior = state.registry.result(cmd.command_id)
|
||||
if prior is not None:
|
||||
return {"status": "ack", "duplicate": True, "result": prior}
|
||||
raise HTTPException(status_code=409, detail="command already in flight")
|
||||
path = cmd.payload.get("parameter_path")
|
||||
value = cmd.payload.get("value")
|
||||
if not path or value is None:
|
||||
raise HTTPException(status_code=400, detail="payload requires parameter_path and value")
|
||||
try:
|
||||
revision = state.engine.set_value(
|
||||
path=path,
|
||||
value=float(value),
|
||||
source=ControlSource.WEB,
|
||||
expected_revision=cmd.expected_revision,
|
||||
)
|
||||
state.state_store.set_value(path, float(value))
|
||||
except RevisionConflict as exc:
|
||||
raise HTTPException(
|
||||
status_code=409,
|
||||
detail={
|
||||
"error": "REVISION_CONFLICT",
|
||||
"current": exc.current,
|
||||
"expected": exc.expected,
|
||||
},
|
||||
) from exc
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
result = {
|
||||
"status": "ack",
|
||||
"command_id": cmd.command_id,
|
||||
"revision": revision,
|
||||
"effective": state.engine.effective_value(path),
|
||||
}
|
||||
state.registry.complete(cmd.command_id, result)
|
||||
_broadcast(
|
||||
{
|
||||
"type": "parameter.update",
|
||||
"parameter_path": path,
|
||||
"value": value,
|
||||
"revision": revision,
|
||||
}
|
||||
)
|
||||
return result
|
||||
|
||||
@app.post("/api/v1/commands/{command_id}/release")
|
||||
async def release_override(command_id: str) -> dict:
|
||||
return {"status": "not_implemented_in_phase0"}
|
||||
|
||||
# ---------- Cluster (§23.1) ----------
|
||||
|
||||
@app.get("/api/v1/cluster/nodes")
|
||||
async def cluster_nodes() -> dict:
|
||||
"""Node-Übersicht nach UI-Kategorien (§6.3): getrennt aufgeführt."""
|
||||
nodes = []
|
||||
for entry in state.nodes.all():
|
||||
state.nodes.evaluate_health(entry.node_id)
|
||||
nodes.append(
|
||||
{
|
||||
"node_id": entry.node_id,
|
||||
"display_name": entry.display_name,
|
||||
"roles": list(entry.roles),
|
||||
"health": entry.health.value,
|
||||
"category": entry.category.value,
|
||||
}
|
||||
)
|
||||
return {"self": state.identity.node_id, "nodes": nodes}
|
||||
|
||||
# ---------- Projekte (§23.1, §24.2) ----------
|
||||
|
||||
@app.get("/api/v1/projects")
|
||||
async def list_projects() -> dict:
|
||||
return {"projects": state.database.list_projects()}
|
||||
|
||||
@app.post("/api/v1/projects")
|
||||
async def create_project(body: CreateProjectBody) -> dict:
|
||||
project = Project(name=body.name)
|
||||
state.database.save_project(project.model_dump(mode="json"))
|
||||
return {"status": "ack", "project": project.model_dump(mode="json")}
|
||||
|
||||
@app.get("/api/v1/projects/{project_id}")
|
||||
async def get_project(project_id: str) -> dict:
|
||||
data = state.database.load_project(project_id)
|
||||
if data is None:
|
||||
raise HTTPException(status_code=404, detail="Projekt nicht gefunden")
|
||||
return data
|
||||
|
||||
@app.put("/api/v1/projects/{project_id}")
|
||||
async def update_project(project_id: str, body: dict) -> dict:
|
||||
existing = state.database.load_project(project_id)
|
||||
if existing is None:
|
||||
raise HTTPException(status_code=404, detail="Projekt nicht gefunden")
|
||||
for key, value in body.items():
|
||||
if key in existing:
|
||||
existing[key] = value
|
||||
updated = Project.model_validate(existing)
|
||||
state.database.save_project(updated.model_dump(mode="json"))
|
||||
state.state_store.bump_project_revision()
|
||||
return {"status": "ack"}
|
||||
|
||||
@app.delete("/api/v1/projects/{project_id}")
|
||||
async def delete_project(project_id: str) -> dict:
|
||||
state.database.delete_project(project_id)
|
||||
return {"status": "ack"}
|
||||
|
||||
@app.post("/api/v1/projects/{project_id}/activate")
|
||||
async def activate_project(project_id: str) -> dict:
|
||||
"""Aktiviert ein Projekt als autoritative Basis (§6.4)."""
|
||||
data = state.database.load_project(project_id)
|
||||
if data is None:
|
||||
raise HTTPException(status_code=404, detail="Projekt nicht gefunden")
|
||||
project = Project.model_validate(data)
|
||||
revision = state.state_store.activate_project(project)
|
||||
return {"status": "ack", "state_revision": revision}
|
||||
|
||||
# ---------- Medien (§13.3, §23.1) ----------
|
||||
|
||||
@app.post("/api/v1/media/import")
|
||||
async def import_media(file: UploadFile) -> dict:
|
||||
"""Importiert eine Mediendatei mit Duplikaterkennung (§13.3).
|
||||
|
||||
Import blockiert niemals den Renderthread (§13.3).
|
||||
"""
|
||||
media_root = state.data_dir / "media"
|
||||
media_root.mkdir(parents=True, exist_ok=True)
|
||||
dest = media_root / file.filename
|
||||
content = await file.read()
|
||||
dest.write_bytes(content)
|
||||
outcome = state.media_library.import_file(dest)
|
||||
if outcome.status is ImportStatus.IMPORTED and outcome.asset:
|
||||
state.database.save_project({
|
||||
"id": str(uuid.uuid4()),
|
||||
"name": file.filename,
|
||||
"schema_version": 1,
|
||||
"created_at": "2026-09-11T00:00:00+00:00",
|
||||
"updated_at": "2026-09-11T00:00:00+00:00",
|
||||
"data": outcome.asset.model_dump(mode="json"),
|
||||
})
|
||||
return {
|
||||
"status": outcome.status.value,
|
||||
"asset": outcome.asset.model_dump(mode="json") if outcome.asset else None,
|
||||
"duplicate_of": outcome.duplicate_of,
|
||||
}
|
||||
|
||||
@app.get("/api/v1/media")
|
||||
async def list_media() -> dict:
|
||||
"""Medienliste mit Metadaten (§13.2)."""
|
||||
missing = state.media_library.mark_missing()
|
||||
assets = []
|
||||
for asset in state.media_library.all():
|
||||
assets.append({
|
||||
**asset.model_dump(mode="json"),
|
||||
"missing": asset.id in state.media_library.missing_asset_ids,
|
||||
})
|
||||
return {"media": assets, "missing_count": len(missing)}
|
||||
|
||||
# ---------- Plugins (§23.1) ----------
|
||||
|
||||
@app.get("/api/v1/plugins")
|
||||
async def list_plugins() -> dict:
|
||||
"""Installierte/verfügbare Plugins nach Status gruppiert (§14.5)."""
|
||||
from hms_plugin_sdk import PluginLifecycleManager
|
||||
|
||||
builtin_dir = _builtin_plugin_dir()
|
||||
mgr = PluginLifecycleManager()
|
||||
errors = _discover_builtin_plugins(mgr, builtin_dir)
|
||||
plugins_by_state: dict[str, list[dict]] = {}
|
||||
for record in mgr.all():
|
||||
plugins_by_state.setdefault(record.state.value, []).append(
|
||||
{
|
||||
"plugin_id": record.plugin_id,
|
||||
"version": record.version,
|
||||
"kind": record.manifest.get("kind", "unknown"),
|
||||
"name": record.manifest.get("name", record.plugin_id),
|
||||
"last_error": record.last_error,
|
||||
}
|
||||
)
|
||||
return {
|
||||
"plugins_by_state": plugins_by_state,
|
||||
"total": len(mgr.all()),
|
||||
"discovery_errors": errors,
|
||||
}
|
||||
|
||||
@app.post("/api/v1/plugins/{plugin_id}/enable")
|
||||
async def enable_plugin(plugin_id: str) -> dict:
|
||||
"""Aktiviert ein Plugin über den Lifecycle (§14.5)."""
|
||||
from hms_plugin_sdk import (
|
||||
InvalidTransitionError,
|
||||
LifecycleState,
|
||||
PluginLifecycleManager,
|
||||
)
|
||||
|
||||
builtin_dir = _builtin_plugin_dir()
|
||||
mgr = PluginLifecycleManager()
|
||||
_discover_builtin_plugins(mgr, builtin_dir)
|
||||
if mgr.get(plugin_id) is None:
|
||||
raise HTTPException(status_code=404, detail=f"unbekanntes Plugin {plugin_id!r}")
|
||||
try:
|
||||
for target in (
|
||||
LifecycleState.INSTALLED,
|
||||
LifecycleState.ENABLED,
|
||||
LifecycleState.COMPILED,
|
||||
LifecycleState.ACTIVE,
|
||||
):
|
||||
record = mgr.get(plugin_id)
|
||||
if record is None:
|
||||
break
|
||||
if record.state is target:
|
||||
break
|
||||
mgr.advance(plugin_id, target)
|
||||
return {"status": "ack", "plugin_id": plugin_id}
|
||||
except InvalidTransitionError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
|
||||
# ---------- Art-Net (§23.1) ----------
|
||||
|
||||
@app.get("/api/v1/artnet/status")
|
||||
async def artnet_status() -> dict:
|
||||
return {
|
||||
"running": False,
|
||||
"universes": [],
|
||||
"telemetry": {},
|
||||
"note": "Art-Net-Receiver startet mit dem Launcher (Phase 1 vollstaendig nach Gate 1)",
|
||||
}
|
||||
|
||||
# ---------- WebSocket (§23.3) ----------
|
||||
|
||||
@app.websocket("/ws")
|
||||
async def websocket_endpoint(ws: WebSocket) -> None:
|
||||
await ws.accept()
|
||||
queue: asyncio.Queue = asyncio.Queue(maxsize=256)
|
||||
state.subscribers.append(queue)
|
||||
try:
|
||||
snap = state.engine.snapshot()
|
||||
await ws.send_json(
|
||||
{"type": "snapshot", "revision": snap.revision, "values": snap.as_dict()}
|
||||
)
|
||||
while True:
|
||||
try:
|
||||
event = await asyncio.wait_for(queue.get(), timeout=15.0)
|
||||
await ws.send_json(event)
|
||||
except TimeoutError:
|
||||
await ws.send_json({"type": "heartbeat"})
|
||||
except WebSocketDisconnect:
|
||||
pass
|
||||
finally:
|
||||
state.subscribers.remove(queue)
|
||||
|
||||
return app
|
||||
|
||||
|
||||
app = create_app()
|
||||
@@ -0,0 +1,90 @@
|
||||
"""RendererStateLink auf der Control-Core-Seite (PLAN.md §6.2, §6.4).
|
||||
|
||||
Verbindet ProjectStateStore (autoritativ) mit dem Renderer über IPC:
|
||||
- connect_and_sync(): Handshake + vollständiger Snapshot (§6.2 Pflicht)
|
||||
- sync_if_changed(): Delta seit letzter gesendeter Revision
|
||||
- Reconnect: immer neuer Snapshot, danach erst wieder Deltas (§6.2)
|
||||
|
||||
Der Link kennt den letzten beim Renderer angekommenen Zustand und
|
||||
berechnet Deltas daraus – keine halben Zustände (§11.4, §6.4).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from hms_persistence.state_store import ProjectStateStore
|
||||
from hms_protocol import Envelope, IpcClient, MessageType
|
||||
|
||||
|
||||
class RendererStateLink:
|
||||
"""Synchronisiert den Showzustand Control Core → Renderer über IPC."""
|
||||
|
||||
def __init__(self, client: IpcClient, store: ProjectStateStore) -> None:
|
||||
self._client = client
|
||||
self._store = store
|
||||
self._last_sent_revision = 0
|
||||
self._renderer_known_state: dict[str, float] = {}
|
||||
|
||||
@property
|
||||
def last_sent_revision(self) -> int:
|
||||
return self._last_sent_revision
|
||||
|
||||
@property
|
||||
def in_sync(self) -> bool:
|
||||
"""True, wenn der Renderer die aktuelle Revision besitzt."""
|
||||
return self._last_sent_revision == self._store.state_revision
|
||||
|
||||
# ---------- Verbindung (§6.2) ----------
|
||||
|
||||
async def connect_and_sync(self) -> None:
|
||||
"""Verbindung aufbauen und vollständigen Snapshot senden.
|
||||
|
||||
Nach jedem (Re-)Connect wird immer zuerst der vollständige Snapshot
|
||||
übertragen; Deltas folgen erst danach (§6.2: „Re-Sync nach
|
||||
Reconnect", „Deltas erst nach erfolgreichem Re-Sync akzeptiert").
|
||||
"""
|
||||
await self._client.connect()
|
||||
await self.send_full_snapshot()
|
||||
|
||||
async def send_full_snapshot(self) -> int:
|
||||
"""Sendet den vollständigen Zustand; liefert die gesendete Revision."""
|
||||
snap = self._store.snapshot()
|
||||
self._last_sent_revision = snap["state_revision"]
|
||||
self._renderer_known_state = dict(snap["values"])
|
||||
envelope = Envelope(
|
||||
type=MessageType.SNAPSHOT,
|
||||
revision=snap["state_revision"],
|
||||
payload=snap,
|
||||
)
|
||||
await self._client.send(envelope)
|
||||
return snap["state_revision"]
|
||||
|
||||
# ---------- Delta-Versand (§6.4) ----------
|
||||
|
||||
async def sync_if_changed(self) -> bool:
|
||||
"""Sendet ein Delta, falls sich die Revision seit dem letzten Versand
|
||||
geändert hat. Rückgabe: True, wenn etwas gesendet wurde.
|
||||
|
||||
Das Delta wird aus dem zuletzt bekannten Renderer-Zustand berechnet
|
||||
(neu/geändert/gelöscht); die Semantik folgt StateDelta (§6.4).
|
||||
"""
|
||||
if self._store.state_revision == self._last_sent_revision:
|
||||
return False # nichts Neues
|
||||
delta = self._store.delta_since(
|
||||
self._last_sent_revision, self._renderer_known_state
|
||||
)
|
||||
if delta is None:
|
||||
return False
|
||||
# Buchhaltung: was weiß der Renderer ab jetzt?
|
||||
for path, value in delta.changes.items():
|
||||
if value is None:
|
||||
self._renderer_known_state.pop(path, None)
|
||||
else:
|
||||
self._renderer_known_state[path] = value
|
||||
self._last_sent_revision = delta.state_revision
|
||||
envelope = Envelope(
|
||||
type=MessageType.EVENT,
|
||||
revision=delta.state_revision,
|
||||
payload=delta.to_dict(),
|
||||
)
|
||||
await self._client.send(envelope)
|
||||
return True
|
||||
Reference in New Issue
Block a user