Add mock LED device type for testing without hardware

Virtual device with configurable LED count, RGB/RGBW mode, and simulated
send latency. Includes full provider/client implementation, API schema
support, and frontend add/settings modal integration.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-24 19:22:53 +03:00
parent dc12452bcd
commit a39dc1b06a
16 changed files with 291 additions and 9 deletions

View File

@@ -30,6 +30,8 @@ class Device:
baud_rate: Optional[int] = None,
software_brightness: int = 255,
auto_shutdown: bool = False,
send_latency_ms: int = 0,
rgbw: bool = False,
created_at: Optional[datetime] = None,
updated_at: Optional[datetime] = None,
):
@@ -42,6 +44,8 @@ class Device:
self.baud_rate = baud_rate
self.software_brightness = software_brightness
self.auto_shutdown = auto_shutdown
self.send_latency_ms = send_latency_ms
self.rgbw = rgbw
self.created_at = created_at or datetime.utcnow()
self.updated_at = updated_at or datetime.utcnow()
# Preserved from old JSON for migration — not written back
@@ -65,6 +69,10 @@ class Device:
d["software_brightness"] = self.software_brightness
if self.auto_shutdown:
d["auto_shutdown"] = True
if self.send_latency_ms:
d["send_latency_ms"] = self.send_latency_ms
if self.rgbw:
d["rgbw"] = True
return d
@classmethod
@@ -84,6 +92,8 @@ class Device:
baud_rate=data.get("baud_rate"),
software_brightness=data.get("software_brightness", 255),
auto_shutdown=data.get("auto_shutdown", False),
send_latency_ms=data.get("send_latency_ms", 0),
rgbw=data.get("rgbw", False),
created_at=datetime.fromisoformat(data.get("created_at", datetime.utcnow().isoformat())),
updated_at=datetime.fromisoformat(data.get("updated_at", datetime.utcnow().isoformat())),
)
@@ -180,6 +190,8 @@ class DeviceStore:
device_type: str = "wled",
baud_rate: Optional[int] = None,
auto_shutdown: bool = False,
send_latency_ms: int = 0,
rgbw: bool = False,
) -> Device:
"""Create a new device."""
device_id = f"device_{uuid.uuid4().hex[:8]}"
@@ -192,6 +204,8 @@ class DeviceStore:
device_type=device_type,
baud_rate=baud_rate,
auto_shutdown=auto_shutdown,
send_latency_ms=send_latency_ms,
rgbw=rgbw,
)
self._devices[device_id] = device
@@ -217,6 +231,8 @@ class DeviceStore:
enabled: Optional[bool] = None,
baud_rate: Optional[int] = None,
auto_shutdown: Optional[bool] = None,
send_latency_ms: Optional[int] = None,
rgbw: Optional[bool] = None,
) -> Device:
"""Update device."""
device = self._devices.get(device_id)
@@ -235,6 +251,10 @@ class DeviceStore:
device.baud_rate = baud_rate
if auto_shutdown is not None:
device.auto_shutdown = auto_shutdown
if send_latency_ms is not None:
device.send_latency_ms = send_latency_ms
if rgbw is not None:
device.rgbw = rgbw
device.updated_at = datetime.utcnow()
self.save()