99import logging
1010import os
1111from threading import Event
12- from typing import Any , cast
12+ from typing import Any , Optional , cast
1313
1414import uvicorn
1515import yaml
@@ -322,7 +322,7 @@ def capabilities() -> CapabilitiesResponse:
322322 @app .get ("/api/control/flow/state" , response_model = FlowState )
323323 def flow_state_legacy () -> FlowState :
324324 """Legacy endpoint - calls Flow controller directly."""
325- flow : FlowWeb | None = CONTROLLERS .get ("flow" )
325+ flow : Optional [ FlowWeb ] = CONTROLLERS .get ("flow" )
326326 if flow is None :
327327 raise HTTPException (status_code = 503 , detail = "Flow controller unavailable" )
328328
@@ -351,7 +351,7 @@ def flow_state_legacy() -> FlowState:
351351 @app .post ("/api/control/flow/set_pressure" )
352352 def flow_set_pressure_legacy (req : FlowSetPressureRequest ):
353353 """Legacy endpoint - calls Flow controller directly."""
354- flow : FlowWeb | None = CONTROLLERS .get ("flow" )
354+ flow : Optional [ FlowWeb ] = CONTROLLERS .get ("flow" )
355355 if flow is None :
356356 raise HTTPException (status_code = 503 , detail = "Flow controller unavailable" )
357357 ok = flow .set_pressure (req .index , req .pressure_mbar )
@@ -362,7 +362,7 @@ def flow_set_pressure_legacy(req: FlowSetPressureRequest):
362362 @app .post ("/api/control/flow/set_flow" )
363363 def flow_set_flow_legacy (req : FlowSetFlowRequest ):
364364 """Legacy endpoint - calls Flow controller directly."""
365- flow : FlowWeb | None = CONTROLLERS .get ("flow" )
365+ flow : Optional [ FlowWeb ] = CONTROLLERS .get ("flow" )
366366 if flow is None :
367367 raise HTTPException (status_code = 503 , detail = "Flow controller unavailable" )
368368 ok = flow .set_flow (req .index , req .flow_ul_hr )
@@ -373,7 +373,7 @@ def flow_set_flow_legacy(req: FlowSetFlowRequest):
373373 @app .post ("/api/control/flow/set_mode" )
374374 def flow_set_mode_legacy (req : FlowSetModeRequest ):
375375 """Legacy endpoint - calls Flow controller directly."""
376- flow : FlowWeb | None = CONTROLLERS .get ("flow" )
376+ flow : Optional [ FlowWeb ] = CONTROLLERS .get ("flow" )
377377 if flow is None :
378378 raise HTTPException (status_code = 503 , detail = "Flow controller unavailable" )
379379 from config import CONTROL_MODE_UI_TO_FIRMWARE
@@ -387,7 +387,7 @@ def flow_set_mode_legacy(req: FlowSetModeRequest):
387387 @app .post ("/api/control/flow/set_pi_consts" )
388388 def flow_set_pi_legacy (req : FlowSetPIRequest ):
389389 """Legacy endpoint - calls Flow controller directly."""
390- flow : FlowWeb | None = CONTROLLERS .get ("flow" )
390+ flow : Optional [ FlowWeb ] = CONTROLLERS .get ("flow" )
391391 if flow is None :
392392 raise HTTPException (status_code = 503 , detail = "Flow controller unavailable" )
393393 ok = flow .set_flow_pi_consts (req .index , [req .p , req .i ])
@@ -398,7 +398,7 @@ def flow_set_pi_legacy(req: FlowSetPIRequest):
398398 @app .get ("/api/control/heater/state" , response_model = HeaterState )
399399 def heater_state_legacy ():
400400 """Legacy endpoint - calls Heater controllers directly."""
401- heaters : list [heater_web ] | None = CONTROLLERS .get ("heaters" )
401+ heaters : Optional [ list [heater_web ]] = CONTROLLERS .get ("heaters" )
402402 if heaters is None :
403403 raise HTTPException (status_code = 503 , detail = "Heaters unavailable" )
404404
@@ -425,7 +425,7 @@ def heater_state_legacy():
425425 @app .post ("/api/control/heater/set_temp" )
426426 def heater_set_temp_legacy (req : HeaterSetTempRequest ):
427427 """Legacy endpoint - calls Heater controller directly."""
428- heaters : list [heater_web ] | None = CONTROLLERS .get ("heaters" )
428+ heaters : Optional [ list [heater_web ]] = CONTROLLERS .get ("heaters" )
429429 if heaters is None or req .index >= len (heaters ):
430430 raise HTTPException (status_code = 503 , detail = "Heaters unavailable" )
431431 heaters [req .index ].set_temp (req .temp_c )
@@ -434,7 +434,7 @@ def heater_set_temp_legacy(req: HeaterSetTempRequest):
434434 @app .post ("/api/control/heater/pid" )
435435 def heater_set_pid_legacy (req : HeaterSetPidRequest ):
436436 """Legacy endpoint - calls Heater controller directly."""
437- heaters : list [heater_web ] | None = CONTROLLERS .get ("heaters" )
437+ heaters : Optional [ list [heater_web ]] = CONTROLLERS .get ("heaters" )
438438 if heaters is None or req .index >= len (heaters ):
439439 raise HTTPException (status_code = 503 , detail = "Heaters unavailable" )
440440 heaters [req .index ].set_pid_running (1 if req .enabled else 0 )
@@ -444,7 +444,7 @@ def heater_set_pid_legacy(req: HeaterSetPidRequest):
444444 @app .post ("/api/control/heater/stir" )
445445 def heater_set_stir_legacy (req : HeaterSetStirRequest ):
446446 """Legacy endpoint - calls Heater controller directly."""
447- heaters : list [heater_web ] | None = CONTROLLERS .get ("heaters" )
447+ heaters : Optional [ list [heater_web ]] = CONTROLLERS .get ("heaters" )
448448 if heaters is None or req .index >= len (heaters ):
449449 raise HTTPException (status_code = 503 , detail = "Heaters unavailable" )
450450 heaters [req .index ].set_stir_running (1 if req .enabled else 0 )
@@ -454,7 +454,7 @@ def heater_set_stir_legacy(req: HeaterSetStirRequest):
454454 @app .post ("/api/control/heater/power_limit" )
455455 def heater_set_power_limit_legacy (req : HeaterSetPowerLimitRequest ):
456456 """Legacy endpoint - calls Heater controller directly."""
457- heaters : list [heater_web ] | None = CONTROLLERS .get ("heaters" )
457+ heaters : Optional [ list [heater_web ]] = CONTROLLERS .get ("heaters" )
458458 if heaters is None or req .index >= len (heaters ):
459459 raise HTTPException (status_code = 503 , detail = "Heaters unavailable" )
460460 heaters [req .index ].set_heat_power_limit_pc (req .power_limit_pc )
@@ -463,7 +463,7 @@ def heater_set_power_limit_legacy(req: HeaterSetPowerLimitRequest):
463463 @app .post ("/api/control/heater/autotune" )
464464 def heater_set_autotune_legacy (req : HeaterSetAutotuneRequest ):
465465 """Legacy endpoint - calls Heater controller directly."""
466- heaters : list [heater_web ] | None = CONTROLLERS .get ("heaters" )
466+ heaters : Optional [ list [heater_web ]] = CONTROLLERS .get ("heaters" )
467467 if heaters is None or req .index >= len (heaters ):
468468 raise HTTPException (status_code = 503 , detail = "Heaters unavailable" )
469469 heaters [req .index ].autotune_target_temp = req .temp_c
@@ -473,7 +473,7 @@ def heater_set_autotune_legacy(req: HeaterSetAutotuneRequest):
473473 @app .get ("/api/streams/camera/snapshot" )
474474 def camera_snapshot_legacy ():
475475 """Legacy endpoint - uses Camera controller directly (snapshot is synchronous)."""
476- cam : Camera | None = CONTROLLERS .get ("camera" )
476+ cam : Optional [ Camera ] = CONTROLLERS .get ("camera" )
477477 if cam is None :
478478 raise HTTPException (status_code = 503 , detail = "Camera unavailable" )
479479 try :
@@ -491,7 +491,7 @@ def camera_snapshot_legacy():
491491 @app .post ("/api/control/camera/set_resolution" )
492492 def camera_set_resolution_legacy (req : CameraResolutionRequest ):
493493 """Legacy endpoint - calls Camera controller directly."""
494- cam : Camera | None = CONTROLLERS .get ("camera" )
494+ cam : Optional [ Camera ] = CONTROLLERS .get ("camera" )
495495 if cam is None :
496496 raise HTTPException (status_code = 503 , detail = "Camera unavailable" )
497497 params : dict [str , Any ] = {}
@@ -506,7 +506,7 @@ def camera_set_resolution_legacy(req: CameraResolutionRequest):
506506 @app .post ("/api/control/camera/set_snapshot_resolution" )
507507 def camera_set_snapshot_resolution_legacy (req : CameraSnapshotResolutionRequest ):
508508 """Legacy endpoint - calls Camera controller directly."""
509- cam : Camera | None = CONTROLLERS .get ("camera" )
509+ cam : Optional [ Camera ] = CONTROLLERS .get ("camera" )
510510 if cam is None :
511511 raise HTTPException (status_code = 503 , detail = "Camera unavailable" )
512512 params : dict [str , Any ] = {"mode" : req .mode }
@@ -519,7 +519,7 @@ def camera_set_snapshot_resolution_legacy(req: CameraSnapshotResolutionRequest):
519519 @app .post ("/api/control/camera/roi" )
520520 def camera_set_roi_legacy (req : CameraROIRequest ):
521521 """Legacy endpoint - calls Camera controller directly."""
522- cam : Camera | None = CONTROLLERS .get ("camera" )
522+ cam : Optional [ Camera ] = CONTROLLERS .get ("camera" )
523523 if cam is None :
524524 raise HTTPException (status_code = 503 , detail = "Camera unavailable" )
525525 cam .on_roi ({"cmd" : CMD_SET , "parameters" : {"x" : req .x , "y" : req .y , "w" : req .w , "h" : req .h }})
@@ -528,7 +528,7 @@ def camera_set_roi_legacy(req: CameraROIRequest):
528528 @app .post ("/api/control/camera/roi/clear" )
529529 def camera_clear_roi_legacy ():
530530 """Legacy endpoint - calls Camera controller directly."""
531- cam : Camera | None = CONTROLLERS .get ("camera" )
531+ cam : Optional [ Camera ] = CONTROLLERS .get ("camera" )
532532 if cam is None :
533533 raise HTTPException (status_code = 503 , detail = "Camera unavailable" )
534534 cam .on_roi ({"cmd" : CMD_CLEAR , "parameters" : {}})
@@ -537,7 +537,7 @@ def camera_clear_roi_legacy():
537537 @app .get ("/api/control/camera/state" , response_model = CameraState )
538538 def camera_state_legacy () -> CameraState :
539539 """Return current camera state for remote UI clients."""
540- cam : Camera | None = CONTROLLERS .get ("camera" )
540+ cam : Optional [ Camera ] = CONTROLLERS .get ("camera" )
541541 if cam is None :
542542 raise HTTPException (status_code = 503 , detail = "Camera unavailable" )
543543 roi_tuple = cam .get_roi ()
@@ -562,7 +562,7 @@ def camera_state_legacy() -> CameraState:
562562 @app .post ("/api/control/camera/select" )
563563 def camera_select_legacy (req : CameraSelectRequest ):
564564 """Select camera backend (legacy endpoint)."""
565- cam : Camera | None = CONTROLLERS .get ("camera" )
565+ cam : Optional [ Camera ] = CONTROLLERS .get ("camera" )
566566 if cam is None or cam .strobe_cam is None :
567567 raise HTTPException (status_code = 503 , detail = "Camera unavailable" )
568568 if cam .thread is not None and cam .thread .is_alive ():
@@ -590,7 +590,7 @@ def camera_select_legacy(req: CameraSelectRequest):
590590 @app .post ("/api/control/strobe/enable" )
591591 def strobe_enable_legacy (req : StrobeEnableRequest ):
592592 """Legacy endpoint - calls Camera controller directly."""
593- cam : Camera | None = CONTROLLERS .get ("camera" )
593+ cam : Optional [ Camera ] = CONTROLLERS .get ("camera" )
594594 if cam is None :
595595 raise HTTPException (status_code = 503 , detail = "Camera unavailable" )
596596 cam .on_strobe ({"cmd" : CMD_ENABLE , "parameters" : {"on" : 1 if req .on else 0 }})
@@ -599,7 +599,7 @@ def strobe_enable_legacy(req: StrobeEnableRequest):
599599 @app .post ("/api/control/strobe/hold" )
600600 def strobe_hold_legacy (req : StrobeEnableRequest ):
601601 """Legacy endpoint - calls Camera controller directly."""
602- cam : Camera | None = CONTROLLERS .get ("camera" )
602+ cam : Optional [ Camera ] = CONTROLLERS .get ("camera" )
603603 if cam is None :
604604 raise HTTPException (status_code = 503 , detail = "Camera unavailable" )
605605 cam .on_strobe ({"cmd" : CMD_HOLD , "parameters" : {"on" : 1 if req .on else 0 }})
@@ -608,7 +608,7 @@ def strobe_hold_legacy(req: StrobeEnableRequest):
608608 @app .post ("/api/control/strobe/timing" )
609609 def strobe_timing_legacy (req : StrobeTimingRequest ):
610610 """Legacy endpoint - calls Camera controller directly."""
611- cam : Camera | None = CONTROLLERS .get ("camera" )
611+ cam : Optional [ Camera ] = CONTROLLERS .get ("camera" )
612612 if cam is None :
613613 raise HTTPException (status_code = 503 , detail = "Camera unavailable" )
614614 params = {"period_ns" : int (req .period_ns )}
@@ -620,7 +620,7 @@ def strobe_timing_legacy(req: StrobeTimingRequest):
620620 @app .get ("/api/control/strobe/state" , response_model = StrobeState )
621621 def strobe_state_legacy () -> StrobeState :
622622 """Return current strobe state for remote UI clients."""
623- cam : Camera | None = CONTROLLERS .get ("camera" )
623+ cam : Optional [ Camera ] = CONTROLLERS .get ("camera" )
624624 if cam is None :
625625 raise HTTPException (status_code = 503 , detail = "Camera unavailable" )
626626 cam .update_strobe_data ()
0 commit comments