Optimize KC processing and add reactive HAOS state updates
- Optimize KC frame processing: downsample to 160x90 with cv2.resize before rectangle extraction, pre-compute pixel coords, vectorize smoothing with numpy arrays - Add WebSocket event stream for server state changes: processor manager fires events on start/stop, new /api/v1/events/ws endpoint streams them to connected clients - Add HAOS EventStreamListener that triggers coordinator refresh on state changes for near-instant switch updates - Reduce HAOS polling interval from 10s to 3s for fresher FPS metrics - Fix overlay button tooltips: flatten nested JSON keys in locale files to match flat dot-notation lookup used by t() function Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -791,6 +791,44 @@ async def target_colors_ws(
|
||||
manager.remove_kc_ws_client(target_id, websocket)
|
||||
|
||||
|
||||
# ===== STATE CHANGE EVENT STREAM =====
|
||||
|
||||
|
||||
@router.websocket("/api/v1/events/ws")
|
||||
async def events_ws(
|
||||
websocket: WebSocket,
|
||||
token: str = Query(""),
|
||||
):
|
||||
"""WebSocket for real-time state change events. Auth via ?token=<api_key>."""
|
||||
authenticated = False
|
||||
cfg = get_config()
|
||||
if token and cfg.auth.api_keys:
|
||||
for _label, api_key in cfg.auth.api_keys.items():
|
||||
if secrets.compare_digest(token, api_key):
|
||||
authenticated = True
|
||||
break
|
||||
|
||||
if not authenticated:
|
||||
await websocket.close(code=4001, reason="Unauthorized")
|
||||
return
|
||||
|
||||
await websocket.accept()
|
||||
|
||||
manager = get_processor_manager()
|
||||
queue = manager.subscribe_events()
|
||||
|
||||
try:
|
||||
while True:
|
||||
event = await queue.get()
|
||||
await websocket.send_json(event)
|
||||
except WebSocketDisconnect:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
finally:
|
||||
manager.unsubscribe_events(queue)
|
||||
|
||||
|
||||
# ===== OVERLAY VISUALIZATION =====
|
||||
|
||||
@router.post("/api/v1/picture-targets/{target_id}/overlay/start", tags=["Visualization"])
|
||||
|
||||
Reference in New Issue
Block a user