thermostat

This commit is contained in:
2025-11-05 18:26:36 +01:00
parent 478450794f
commit cb555a1f67
10 changed files with 1293 additions and 11 deletions

View File

@@ -15,7 +15,7 @@ from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import StreamingResponse
from pydantic import BaseModel, ValidationError
from packages.home_capabilities import CAP_VERSION, LightState
from packages.home_capabilities import LIGHT_VERSION, THERMOSTAT_VERSION, LightState, ThermostatState
logger = logging.getLogger(__name__)
@@ -57,7 +57,8 @@ async def spec() -> dict[str, dict[str, str]]:
"""
return {
"capabilities": {
"light": CAP_VERSION
"light": LIGHT_VERSION,
"thermostat": THERMOSTAT_VERSION
}
}
@@ -233,6 +234,22 @@ async def set_device(device_id: str, request: SetDeviceRequest) -> dict[str, str
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
detail=f"Invalid payload for light: {e}"
)
elif request.type == "thermostat":
try:
# For thermostat SET: only allow mode and target
allowed_set_fields = {"mode", "target"}
invalid_fields = set(request.payload.keys()) - allowed_set_fields
if invalid_fields:
raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
detail=f"Thermostat SET only allows {allowed_set_fields}, got invalid fields: {invalid_fields}"
)
ThermostatState(**request.payload)
except ValidationError as e:
raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
detail=f"Invalid payload for thermostat: {e}"
)
else:
raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,