30fa107ef7
- Add `tags: List[str]` field to all 13 entity types (devices, output targets, CSS sources, picture sources, audio sources, value sources, sync clocks, automations, scene presets, capture/audio/PP/pattern templates) - Update all stores, schemas, and route handlers for tag CRUD - Add GET /api/v1/tags endpoint aggregating unique tags across all stores - Create TagInput component with chip display, autocomplete dropdown, keyboard navigation, and API-backed suggestions - Display tag chips on all entity cards (searchable via existing text filter) - Add tag input to all 14 editor modals with dirty check support - Add CSS styles and i18n keys (en/ru/zh) for tag UI - Also includes code review fixes: thread safety, perf, store dedup Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
68 lines
2.5 KiB
Python
68 lines
2.5 KiB
Python
"""Output target base data model."""
|
|
|
|
from dataclasses import dataclass, field
|
|
from datetime import datetime
|
|
from typing import List, Optional
|
|
|
|
|
|
@dataclass
|
|
class OutputTarget:
|
|
"""Base class for output targets."""
|
|
|
|
id: str
|
|
name: str
|
|
target_type: str # "wled", "key_colors", ...
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
description: Optional[str] = None
|
|
tags: List[str] = field(default_factory=list)
|
|
|
|
def register_with_manager(self, manager) -> None:
|
|
"""Register this target with the processor manager. Subclasses override."""
|
|
pass
|
|
|
|
def sync_with_manager(self, manager, *, settings_changed: bool, source_changed: bool, device_changed: bool) -> None:
|
|
"""Push changed fields to a running processor. Subclasses override."""
|
|
pass
|
|
|
|
def update_fields(self, *, name=None, device_id=None, picture_source_id=None,
|
|
settings=None, key_colors_settings=None, description=None,
|
|
tags: Optional[List[str]] = None,
|
|
**_kwargs) -> None:
|
|
"""Apply mutable field updates. Base handles common fields; subclasses handle type-specific ones."""
|
|
if name is not None:
|
|
self.name = name
|
|
if description is not None:
|
|
self.description = description
|
|
if tags is not None:
|
|
self.tags = tags
|
|
|
|
@property
|
|
def has_picture_source(self) -> bool:
|
|
"""Whether this target type uses a picture source."""
|
|
return False
|
|
|
|
def to_dict(self) -> dict:
|
|
"""Convert to dictionary."""
|
|
return {
|
|
"id": self.id,
|
|
"name": self.name,
|
|
"target_type": self.target_type,
|
|
"description": self.description,
|
|
"tags": self.tags,
|
|
"created_at": self.created_at.isoformat(),
|
|
"updated_at": self.updated_at.isoformat(),
|
|
}
|
|
|
|
@classmethod
|
|
def from_dict(cls, data: dict) -> "OutputTarget":
|
|
"""Create from dictionary, dispatching to the correct subclass."""
|
|
target_type = data.get("target_type", "led")
|
|
if target_type == "led":
|
|
from wled_controller.storage.wled_output_target import WledOutputTarget
|
|
return WledOutputTarget.from_dict(data)
|
|
if target_type == "key_colors":
|
|
from wled_controller.storage.key_colors_output_target import KeyColorsOutputTarget
|
|
return KeyColorsOutputTarget.from_dict(data)
|
|
raise ValueError(f"Unknown target type: {target_type}")
|