- pyproject.toml with FastAPI, uvicorn, Pydantic v2, aiofiles, structlog deps - DeviceConfig Pydantic model with StripType, UUID, validation constraints - ShowModel with AudioRef, TrackModel, CueModel, AnalysisBlock, schema_version=1 - BaseDevice ABC with encode_frame, encode_animation_cmd, bytes_per_pixel - SK6812Device (4 bytes/pixel) and WS2801Device (3 bytes/pixel) implementations
34 lines
879 B
Python
34 lines
879 B
Python
from abc import ABC, abstractmethod
|
|
from lightsync.models.device import DeviceConfig
|
|
|
|
|
|
class BaseDevice(ABC):
|
|
def __init__(self, config: DeviceConfig):
|
|
self.config = config
|
|
|
|
@property
|
|
def id(self):
|
|
return self.config.id
|
|
|
|
@property
|
|
def led_count(self) -> int:
|
|
return self.config.led_count
|
|
|
|
@abstractmethod
|
|
def encode_frame(self, pixels: list[tuple]) -> bytes:
|
|
"""Encode a full pixel frame to UDP payload bytes.
|
|
pixels: list of (R, G, B) or (R, G, B, W) tuples.
|
|
"""
|
|
...
|
|
|
|
@abstractmethod
|
|
def encode_animation_cmd(self, animation: str, params: dict) -> bytes:
|
|
"""Encode an animation+params command packet."""
|
|
...
|
|
|
|
@property
|
|
@abstractmethod
|
|
def bytes_per_pixel(self) -> int:
|
|
"""Number of bytes per LED in frame mode (3 for RGB, 4 for RGBW)."""
|
|
...
|