Files
homelable/backend/app/api/routes/status.py
T
Pouzor 974e782057 fix: resolve all 64 mypy errors across backend
- Add dict[str, Any] / list[Any] type params throughout (fingerprint, models, schemas, scanner, status_checker)
- Add return type annotations to all route functions (nodes, edges, canvas, scan, auth, status, main)
- Fix no-any-return in security.py: cast pwd/jwt results to bool/str explicitly
- Fix canvas.py: use model_validate() for NodeResponse/EdgeResponse, rename db_node/db_edge upsert vars
- Fix scheduler.py: rename 'result' → 'check_result' to avoid type collision
- Fix get_db() return type: AsyncGenerator[AsyncSession, None]
- Add types-PyYAML for yaml import stubs
- Fix scanner.py: remove unnecessary type: ignore comment (nmap has stubs)
- Fix scan.py: wrap scalars().all() with list() for Sequence→list compatibility
2026-03-07 15:48:41 +01:00

34 lines
898 B
Python

import json
from fastapi import APIRouter, WebSocket, WebSocketDisconnect
router = APIRouter()
# Active WebSocket connections
_connections: list[WebSocket] = []
@router.websocket("/ws/status")
async def ws_status(websocket: WebSocket) -> None:
await websocket.accept()
_connections.append(websocket)
try:
while True:
await websocket.receive_text()
except WebSocketDisconnect:
_connections.remove(websocket)
async def broadcast_status(node_id: str, status: str, checked_at: str, response_time_ms: int | None = None) -> None:
payload = json.dumps({
"node_id": node_id,
"status": status,
"checked_at": checked_at,
"response_time_ms": response_time_ms,
})
for conn in list(_connections):
try:
await conn.send_text(payload)
except Exception:
_connections.remove(conn)