Add ledctl locate/off LED controls to drive detail modal

This commit is contained in:
2026-03-07 04:57:35 +00:00
parent 51e6b49830
commit 927a5ccf3a
5 changed files with 119 additions and 2 deletions

29
routers/leds.py Normal file
View 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