Files
home-automation/packages/home_capabilities/thermostat.py

78 lines
1.9 KiB
Python

"""
Thermostat Capability Model
Pydantic v2 model for thermostat device state and commands.
"""
from decimal import Decimal
from typing import Literal
from pydantic import BaseModel, Field
CAP_VERSION = "thermostat@2.0.0"
class ThermostatState(BaseModel):
"""
Thermostat state model with validation.
Attributes:
mode: Operating mode (off, heat, auto) - optional for SET commands
target: Target temperature in °C [5.0..30.0]
current: Current temperature in °C (optional in SET, required in STATE)
battery: Battery level 0-100% (optional)
window_open: Window open detection (optional)
"""
mode: Literal["off", "heat", "auto"] | None = Field(
None,
description="Operating mode of the thermostat (optional for SET commands)"
)
target: float | Decimal = Field(
...,
ge=5.0,
le=30.0,
description="Target temperature in degrees Celsius"
)
current: float | Decimal | None = Field(
None,
ge=0.0,
description="Current measured temperature in degrees Celsius"
)
battery: int | None = Field(
None,
ge=0,
le=100,
description="Battery level percentage"
)
window_open: bool | None = Field(
None,
description="Window open detection status"
)
model_config = {
"json_schema_extra": {
"examples": [
{
"mode": "heat",
"target": 21.0,
"current": 20.2,
"battery": 85,
"window_open": False
},
{
"mode": "auto",
"target": 22.5
},
{
"mode": "off",
"target": 5.0,
"current": 18.0
}
]
}
}