initial, step 2 already
This commit is contained in:
1
packages/__init__.py
Normal file
1
packages/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Packages."""
|
||||
5
packages/home_capabilities/__init__.py
Normal file
5
packages/home_capabilities/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
"""Home capabilities package."""
|
||||
|
||||
from packages.home_capabilities.light import CAP_VERSION, LightState
|
||||
|
||||
__all__ = ["LightState", "CAP_VERSION"]
|
||||
52
packages/home_capabilities/light.py
Normal file
52
packages/home_capabilities/light.py
Normal file
@@ -0,0 +1,52 @@
|
||||
"""Light capability models and constants."""
|
||||
|
||||
from typing import Literal, Optional
|
||||
|
||||
from pydantic import BaseModel, Field, field_validator
|
||||
|
||||
|
||||
CAP_VERSION = "light@1.2.0"
|
||||
|
||||
|
||||
class LightState(BaseModel):
|
||||
"""Represents the state of a light device.
|
||||
|
||||
Attributes:
|
||||
power: Whether the light is "on" or "off"
|
||||
brightness: Optional brightness level (0-100)
|
||||
color_temp: Optional color temperature in Kelvin (150-500)
|
||||
color: Optional hex color string in format "#RRGGBB"
|
||||
"""
|
||||
|
||||
power: Literal["on", "off"] = Field(
|
||||
...,
|
||||
description="Power state of the light"
|
||||
)
|
||||
|
||||
brightness: Optional[int] = Field(
|
||||
None,
|
||||
ge=0,
|
||||
le=100,
|
||||
description="Brightness level from 0 to 100"
|
||||
)
|
||||
|
||||
color_temp: Optional[int] = Field(
|
||||
None,
|
||||
ge=150,
|
||||
le=500,
|
||||
description="Color temperature in Kelvin (150-500)"
|
||||
)
|
||||
|
||||
color: Optional[str] = Field(
|
||||
None,
|
||||
pattern=r"^#[0-9A-Fa-f]{6}$",
|
||||
description="Hex color string in format #RRGGBB"
|
||||
)
|
||||
|
||||
@field_validator("color")
|
||||
@classmethod
|
||||
def validate_color_format(cls, v: Optional[str]) -> Optional[str]:
|
||||
"""Ensure color is uppercase if provided."""
|
||||
if v is not None:
|
||||
return v.upper()
|
||||
return v
|
||||
Reference in New Issue
Block a user