Refactor radar system

This commit is contained in:
Ayzen
2026-10-05 16:46:28 +03:00
parent 515049d2ed
commit 8f097dfa2e
179 changed files with 8212 additions and 6676 deletions
+25 -8
View File
@@ -26,7 +26,7 @@ def _controller(request: Request) -> WebController:
return request.app.state.controller
async def _run_action(func, *args) -> None:
async def _run_action(func, *args):
"""Run a (blocking) controller control call off the event loop, mapping failures to 400.
The control methods run the desktop action synchronously and raise ``ValueError``
@@ -35,7 +35,7 @@ async def _run_action(func, *args) -> None:
keeps the async event loop free while the GUI thread does the work.
"""
try:
await asyncio.to_thread(func, *args)
return await asyncio.to_thread(func, *args)
except (ValueError, WebActionError) as exc:
logger.warning("Web UI action failed: %s", exc)
raise HTTPException(status_code=400, detail=str(exc)) from exc
@@ -75,7 +75,7 @@ async def post_start_recording(
request: Request,
path: str = Body("", embed=True),
name: str = Body("", embed=True),
count: int = Body(..., embed=True),
count: int = Body(..., embed=True, strict=True, ge=1),
) -> dict:
logger.info("Web UI request: start with disk recording (count=%s)", count)
controller = _controller(request)
@@ -129,13 +129,27 @@ async def get_live_settings(request: Request) -> list:
return _controller(request).current_live_settings()
@router.post("/api/display_combo")
async def post_display_combo(
request: Request,
input_pos: int = Body(..., embed=True, strict=True, ge=0),
output_pos: int = Body(..., embed=True, strict=True, ge=0),
) -> dict:
controller = _controller(request)
await _run_action(controller.select_combo, input_pos, output_pos)
return controller.status()
@router.post("/api/next_combo")
async def post_next_combo(request: Request) -> dict:
controller = _controller(request)
await _run_action(controller.next_combo)
return controller.status()
@router.post("/api/live_settings")
async def post_live_settings(request: Request, fields: dict = Body(default={})) -> list:
try:
return _controller(request).apply_live_settings(fields)
except ValueError as exc:
logger.warning("Web UI rejected live settings update: %s", exc)
raise HTTPException(status_code=400, detail=str(exc)) from exc
return await _run_action(_controller(request).apply_live_settings, fields)
@router.websocket("/ws")
@@ -147,6 +161,9 @@ async def ws(websocket: WebSocket) -> None:
broadcaster.register(queue)
logger.info("Web UI client connected")
try:
frame = await asyncio.to_thread(websocket.app.state.controller.peek_frame)
if frame is not None:
await websocket.send_json(frame)
while True:
await websocket.send_json(await queue.get())
except WebSocketDisconnect: