add type relay

This commit is contained in:
2025-11-11 10:10:22 +01:00
parent 86d1933c1f
commit 97ea853483
8 changed files with 120 additions and 5 deletions

View File

@@ -20,10 +20,12 @@ from packages.home_capabilities import (
THERMOSTAT_VERSION,
CONTACT_SENSOR_VERSION,
TEMP_HUMIDITY_SENSOR_VERSION,
RELAY_VERSION,
LightState,
ThermostatState,
ContactState,
TempHumidityState
TempHumidityState,
RelayState
)
logger = logging.getLogger(__name__)
@@ -148,7 +150,8 @@ async def spec() -> dict[str, dict[str, str]]:
"light": LIGHT_VERSION,
"thermostat": THERMOSTAT_VERSION,
"contact": CONTACT_SENSOR_VERSION,
"temp_humidity": TEMP_HUMIDITY_SENSOR_VERSION
"temp_humidity": TEMP_HUMIDITY_SENSOR_VERSION,
"relay": RELAY_VERSION
}
}
@@ -358,6 +361,14 @@ 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 == "relay":
try:
RelayState(**request.payload)
except ValidationError as e:
raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
detail=f"Invalid payload for relay: {e}"
)
elif request.type == "thermostat":
try:
# For thermostat SET: only allow mode and target