Introduce ColorStripSource as first-class entity
Extracts color processing and calibration out of WledPictureTarget into a new PictureColorStripSource entity, enabling multiple LED targets to share one capture/processing pipeline. New entities & processing: - storage/color_strip_source.py: ColorStripSource + PictureColorStripSource models - storage/color_strip_store.py: JSON-backed CRUD store (prefix css_) - core/processing/color_strip_stream.py: ColorStripStream ABC + PictureColorStripStream (runs border-extract → map → smooth → brightness/sat/gamma in background thread) - core/processing/color_strip_stream_manager.py: ref-counted shared stream manager Modified storage/processing: - WledPictureTarget simplified to device_id + color_strip_source_id + standby_interval + state_check_interval - Device model: calibration field removed - WledTargetProcessor: acquires ColorStripStream from manager instead of running its own pipeline - ProcessorManager: wires ColorStripStreamManager into TargetContext API layer: - New routes: GET/POST/PUT/DELETE /api/v1/color-strip-sources, PUT calibration/test - Removed calibration endpoints from /devices - Updated /picture-targets CRUD for new target structure Frontend: - New color-strips.js module with CSS editor modal and card rendering - Calibration modal extended with CSS mode (css-id hidden field + device picker) - targets.js: Color Strip Sources section added to LED tab; target editor/card updated - app.js: imports and window globals for CSS + showCSSCalibration - en.json / ru.json: color_strip.* and targets.section.color_strips keys added Data migration runs at startup: existing WledPictureTargets are converted to reference a new PictureColorStripSource created from their old settings. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,20 +1,31 @@
|
||||
"""LED picture target — streams a picture source to an LED device."""
|
||||
"""LED picture target — sends a color strip source to an LED device."""
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from wled_controller.core.processing.processing_settings import ProcessingSettings
|
||||
from wled_controller.storage.picture_target import PictureTarget
|
||||
|
||||
DEFAULT_STATE_CHECK_INTERVAL = 30 # seconds
|
||||
|
||||
|
||||
@dataclass
|
||||
class WledPictureTarget(PictureTarget):
|
||||
"""LED picture target — streams a picture source to an LED device."""
|
||||
"""LED picture target — pairs an LED device with a ColorStripSource.
|
||||
|
||||
The ColorStripSource encapsulates everything needed to produce LED colors
|
||||
(calibration, color correction, smoothing, fps). The LED target itself only
|
||||
holds device-specific timing/keepalive settings.
|
||||
"""
|
||||
|
||||
device_id: str = ""
|
||||
picture_source_id: str = ""
|
||||
settings: ProcessingSettings = field(default_factory=ProcessingSettings)
|
||||
color_strip_source_id: str = ""
|
||||
standby_interval: float = 1.0 # seconds between keepalive sends when screen is static
|
||||
state_check_interval: int = DEFAULT_STATE_CHECK_INTERVAL
|
||||
|
||||
# Legacy fields — populated from old JSON data during migration; not written back
|
||||
_legacy_picture_source_id: str = field(default="", repr=False, compare=False)
|
||||
_legacy_settings: Optional[dict] = field(default=None, repr=False, compare=False)
|
||||
|
||||
def register_with_manager(self, manager) -> None:
|
||||
"""Register this WLED target with the processor manager."""
|
||||
@@ -22,74 +33,72 @@ class WledPictureTarget(PictureTarget):
|
||||
manager.add_target(
|
||||
target_id=self.id,
|
||||
device_id=self.device_id,
|
||||
settings=self.settings,
|
||||
picture_source_id=self.picture_source_id,
|
||||
color_strip_source_id=self.color_strip_source_id,
|
||||
standby_interval=self.standby_interval,
|
||||
state_check_interval=self.state_check_interval,
|
||||
)
|
||||
|
||||
def sync_with_manager(self, manager, *, settings_changed: bool, source_changed: bool, device_changed: bool) -> None:
|
||||
"""Push changed fields to the processor manager."""
|
||||
if settings_changed:
|
||||
manager.update_target_settings(self.id, self.settings)
|
||||
manager.update_target_settings(self.id, {
|
||||
"standby_interval": self.standby_interval,
|
||||
"state_check_interval": self.state_check_interval,
|
||||
})
|
||||
if source_changed:
|
||||
manager.update_target_source(self.id, self.picture_source_id)
|
||||
manager.update_target_color_strip_source(self.id, self.color_strip_source_id)
|
||||
if device_changed:
|
||||
manager.update_target_device(self.id, self.device_id)
|
||||
|
||||
def update_fields(self, *, name=None, device_id=None, picture_source_id=None,
|
||||
settings=None, key_colors_settings=None, description=None) -> None:
|
||||
def update_fields(self, *, name=None, device_id=None, color_strip_source_id=None,
|
||||
standby_interval=None, state_check_interval=None,
|
||||
# Legacy params accepted but ignored to keep base class compat:
|
||||
picture_source_id=None, settings=None,
|
||||
key_colors_settings=None, description=None) -> None:
|
||||
"""Apply mutable field updates for WLED targets."""
|
||||
super().update_fields(name=name, description=description)
|
||||
if device_id is not None:
|
||||
self.device_id = device_id
|
||||
if picture_source_id is not None:
|
||||
self.picture_source_id = picture_source_id
|
||||
if settings is not None:
|
||||
self.settings = settings
|
||||
if color_strip_source_id is not None:
|
||||
self.color_strip_source_id = color_strip_source_id
|
||||
if standby_interval is not None:
|
||||
self.standby_interval = standby_interval
|
||||
if state_check_interval is not None:
|
||||
self.state_check_interval = state_check_interval
|
||||
|
||||
@property
|
||||
def has_picture_source(self) -> bool:
|
||||
return True
|
||||
return bool(self.color_strip_source_id)
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
"""Convert to dictionary."""
|
||||
d = super().to_dict()
|
||||
d["device_id"] = self.device_id
|
||||
d["picture_source_id"] = self.picture_source_id
|
||||
d["settings"] = {
|
||||
"display_index": self.settings.display_index,
|
||||
"fps": self.settings.fps,
|
||||
"brightness": self.settings.brightness,
|
||||
"smoothing": self.settings.smoothing,
|
||||
"interpolation_mode": self.settings.interpolation_mode,
|
||||
"standby_interval": self.settings.standby_interval,
|
||||
"state_check_interval": self.settings.state_check_interval,
|
||||
}
|
||||
d["color_strip_source_id"] = self.color_strip_source_id
|
||||
d["standby_interval"] = self.standby_interval
|
||||
d["state_check_interval"] = self.state_check_interval
|
||||
return d
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: dict) -> "WledPictureTarget":
|
||||
"""Create from dictionary."""
|
||||
from wled_controller.core.processing.processing_settings import DEFAULT_STATE_CHECK_INTERVAL
|
||||
|
||||
settings_data = data.get("settings", {})
|
||||
settings = ProcessingSettings(
|
||||
display_index=settings_data.get("display_index", 0),
|
||||
fps=settings_data.get("fps", 30),
|
||||
brightness=settings_data.get("brightness", 1.0),
|
||||
smoothing=settings_data.get("smoothing", 0.3),
|
||||
interpolation_mode=settings_data.get("interpolation_mode", "average"),
|
||||
standby_interval=settings_data.get("standby_interval", 1.0),
|
||||
state_check_interval=settings_data.get("state_check_interval", DEFAULT_STATE_CHECK_INTERVAL),
|
||||
)
|
||||
|
||||
return cls(
|
||||
"""Create from dictionary. Reads legacy picture_source_id/settings for migration."""
|
||||
obj = cls(
|
||||
id=data["id"],
|
||||
name=data["name"],
|
||||
target_type="led",
|
||||
device_id=data.get("device_id", ""),
|
||||
picture_source_id=data.get("picture_source_id", ""),
|
||||
settings=settings,
|
||||
color_strip_source_id=data.get("color_strip_source_id", ""),
|
||||
standby_interval=data.get("standby_interval", 1.0),
|
||||
state_check_interval=data.get("state_check_interval", DEFAULT_STATE_CHECK_INTERVAL),
|
||||
description=data.get("description"),
|
||||
created_at=datetime.fromisoformat(data.get("created_at", datetime.utcnow().isoformat())),
|
||||
updated_at=datetime.fromisoformat(data.get("updated_at", datetime.utcnow().isoformat())),
|
||||
)
|
||||
|
||||
# Preserve legacy fields for migration — never written back by to_dict()
|
||||
obj._legacy_picture_source_id = data.get("picture_source_id", "")
|
||||
settings_data = data.get("settings", {})
|
||||
if settings_data:
|
||||
obj._legacy_settings = settings_data
|
||||
|
||||
return obj
|
||||
|
||||
Reference in New Issue
Block a user