Add profile system for automatic target activation

Profiles monitor running processes and foreground windows to
automatically start/stop targets when conditions are met.
Includes profile engine, platform detector (WMI), REST API,
process browser endpoint, and calibration persistence fix.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-18 15:12:34 +03:00
parent d6cf45c873
commit 29d9b95885
15 changed files with 933 additions and 10 deletions

View File

@@ -23,6 +23,8 @@ from wled_controller.storage.picture_source_store import PictureSourceStore
from wled_controller.storage.picture_target_store import PictureTargetStore
from wled_controller.storage.wled_picture_target import WledPictureTarget
from wled_controller.storage.key_colors_picture_target import KeyColorsPictureTarget
from wled_controller.storage.profile_store import ProfileStore
from wled_controller.core.profiles.profile_engine import ProfileEngine
from wled_controller.utils import setup_logging, get_logger
# Initialize logging
@@ -39,6 +41,7 @@ pp_template_store = PostprocessingTemplateStore(config.storage.postprocessing_te
picture_source_store = PictureSourceStore(config.storage.picture_sources_file)
picture_target_store = PictureTargetStore(config.storage.picture_targets_file)
pattern_template_store = PatternTemplateStore(config.storage.pattern_templates_file)
profile_store = ProfileStore(config.storage.profiles_file)
processor_manager = ProcessorManager(
picture_source_store=picture_source_store,
@@ -138,6 +141,9 @@ async def lifespan(app: FastAPI):
# Run migrations
_migrate_devices_to_targets()
# Create profile engine (needs processor_manager)
profile_engine = ProfileEngine(profile_store, processor_manager)
# Initialize API dependencies
init_dependencies(
device_store, template_store, processor_manager,
@@ -145,6 +151,8 @@ async def lifespan(app: FastAPI):
pattern_template_store=pattern_template_store,
picture_source_store=picture_source_store,
picture_target_store=picture_target_store,
profile_store=profile_store,
profile_engine=profile_engine,
)
# Register devices in processor manager for health monitoring
@@ -201,11 +209,21 @@ async def lifespan(app: FastAPI):
# Start background health monitoring for all devices
await processor_manager.start_health_monitoring()
# Start profile engine (evaluates conditions and auto-starts/stops targets)
await profile_engine.start()
yield
# Shutdown
logger.info("Shutting down LED Grab")
# Stop profile engine first (deactivates profile-managed targets)
try:
await profile_engine.stop()
logger.info("Stopped profile engine")
except Exception as e:
logger.error(f"Error stopping profile engine: {e}")
# Stop all processing
try:
await processor_manager.stop_all()