Add ledctl locate/off LED controls to drive detail modal
This commit is contained in:
29
routers/leds.py
Normal file
29
routers/leds.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel, field_validator
|
||||
|
||||
from services.leds import set_led
|
||||
|
||||
router = APIRouter(prefix="/api/drives", tags=["leds"])
|
||||
|
||||
|
||||
class LedRequest(BaseModel):
|
||||
state: str
|
||||
|
||||
@field_validator("state")
|
||||
@classmethod
|
||||
def validate_state(cls, v: str) -> str:
|
||||
if v not in ("locate", "off"):
|
||||
raise ValueError("state must be 'locate' or 'off'")
|
||||
return v
|
||||
|
||||
|
||||
@router.post("/{device}/led")
|
||||
async def set_drive_led(device: str, body: LedRequest):
|
||||
"""Set the locate LED for a drive."""
|
||||
try:
|
||||
result = await set_led(device, body.state)
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
except RuntimeError as e:
|
||||
raise HTTPException(status_code=502, detail=str(e))
|
||||
return result
|
||||
Reference in New Issue
Block a user