Encapsulate target-type dispatch via polymorphism (Phase 1)
Replace isinstance checks with polymorphic methods on PictureTarget hierarchy: register_with_manager, sync_with_manager, update_fields, and has_picture_source property. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -16,6 +16,40 @@ class WledPictureTarget(PictureTarget):
|
||||
picture_source_id: str = ""
|
||||
settings: ProcessingSettings = field(default_factory=ProcessingSettings)
|
||||
|
||||
def register_with_manager(self, manager) -> None:
|
||||
"""Register this WLED target with the processor manager."""
|
||||
if self.device_id:
|
||||
manager.add_target(
|
||||
target_id=self.id,
|
||||
device_id=self.device_id,
|
||||
settings=self.settings,
|
||||
picture_source_id=self.picture_source_id,
|
||||
)
|
||||
|
||||
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)
|
||||
if source_changed:
|
||||
manager.update_target_source(self.id, self.picture_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:
|
||||
"""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
|
||||
|
||||
@property
|
||||
def has_picture_source(self) -> bool:
|
||||
return True
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
"""Convert to dictionary."""
|
||||
d = super().to_dict()
|
||||
|
||||
Reference in New Issue
Block a user