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

@@ -15,7 +15,7 @@ import uuid
from aiomqtt import Client
from pydantic import ValidationError
from packages.home_capabilities import LightState, ThermostatState, ContactState, TempHumidityState
from packages.home_capabilities import LightState, ThermostatState, ContactState, TempHumidityState, RelayState
from apps.abstraction.transformation import (
transform_abstract_to_vendor,
transform_vendor_to_abstract
@@ -154,6 +154,9 @@ async def handle_abstract_set(
if device_type == "light":
# Validate light SET payload (power and/or brightness)
LightState.model_validate(abstract_payload)
elif device_type == "relay":
# Validate relay SET payload (power only)
RelayState.model_validate(abstract_payload)
elif device_type == "thermostat":
# For thermostat SET: only allow mode and target fields
allowed_set_fields = {"mode", "target"}
@@ -216,6 +219,8 @@ async def handle_vendor_state(
try:
if device_type == "light":
LightState.model_validate(abstract_payload)
elif device_type == "relay":
RelayState.model_validate(abstract_payload)
elif device_type == "thermostat":
# Validate thermostat state: mode, target, current (required), battery, window_open
ThermostatState.model_validate(abstract_payload)