feat: 添加电源接口,适配小功能函数

This commit is contained in:
DLmaster361
2025-08-17 10:53:00 +08:00
parent 1fdac22bea
commit 8e2c6bb642
7 changed files with 94 additions and 84 deletions

View File

@@ -25,6 +25,7 @@ import asyncio
from fastapi import APIRouter, WebSocket, WebSocketDisconnect, Body, Path
from app.core import TaskManager, Broadcast
from app.services import System
from app.models.schema import *
router = APIRouter(prefix="/api/dispatch", tags=["任务调度"])
@@ -59,6 +60,18 @@ async def stop_task(task: DispatchIn = Body(...)) -> OutBase:
return OutBase()
@router.post("/power", summary="电源操作", response_model=OutBase, status_code=200)
async def power_task(task: PowerIn = Body(...)) -> OutBase:
try:
await System.set_power(task.signal)
except Exception as e:
return OutBase(
code=500, status="error", message=f"{type(e).__name__}: {str(e)}"
)
return OutBase()
@router.websocket("/ws/{websocketId}")
async def websocket_endpoint(
websocket: WebSocket,