Add profile conditions, scene presets, MQTT integration, and Scenes tab

Feature 1 — Profile Conditions: time-of-day, system idle (Win32
GetLastInputInfo), and display state (GUID_CONSOLE_DISPLAY_STATE)
condition types for automatic profile activation.

Feature 2 — Scene Presets: snapshot/restore system that captures target
running states, device brightness, and profile enables. Server-side
capture with 5-step activation order. Dedicated Scenes tab with
CardSection-based card grid, command palette integration, and dashboard
quick-activate section.

Feature 3 — MQTT Integration: MQTTService singleton with aiomqtt,
MQTTLEDClient device provider for pixel output, MQTT profile condition
type with topic/payload matching, and frontend support for MQTT device
type and condition editor.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-28 16:57:42 +03:00
parent bd8d7a019f
commit 2e747b5ece
38 changed files with 2269 additions and 32 deletions

View File

@@ -28,7 +28,10 @@ from wled_controller.storage.audio_template_store import AudioTemplateStore
import wled_controller.core.audio # noqa: F401 — trigger engine auto-registration
from wled_controller.storage.value_source_store import ValueSourceStore
from wled_controller.storage.profile_store import ProfileStore
from wled_controller.storage.scene_preset_store import ScenePresetStore
from wled_controller.core.profiles.profile_engine import ProfileEngine
from wled_controller.core.mqtt.mqtt_service import MQTTService
from wled_controller.core.devices.mqtt_client import set_mqtt_service
from wled_controller.core.backup.auto_backup import AutoBackupEngine
from wled_controller.api.routes.system import STORE_MAP
from wled_controller.utils import setup_logging, get_logger
@@ -52,6 +55,7 @@ audio_source_store = AudioSourceStore(config.storage.audio_sources_file)
audio_template_store = AudioTemplateStore(config.storage.audio_templates_file)
value_source_store = ValueSourceStore(config.storage.value_sources_file)
profile_store = ProfileStore(config.storage.profiles_file)
scene_preset_store = ScenePresetStore(config.storage.scene_presets_file)
# Migrate embedded audio config from CSS entities to audio sources
audio_source_store.migrate_from_css(color_strip_store)
@@ -100,8 +104,12 @@ async def lifespan(app: FastAPI):
logger.info(f"Authorized clients: {client_labels}")
logger.info("All API requests require valid Bearer token authentication")
# Create profile engine (needs processor_manager)
profile_engine = ProfileEngine(profile_store, processor_manager)
# Create MQTT service (shared broker connection)
mqtt_service = MQTTService(config.mqtt)
set_mqtt_service(mqtt_service)
# Create profile engine (needs processor_manager + mqtt_service)
profile_engine = ProfileEngine(profile_store, processor_manager, mqtt_service=mqtt_service)
# Create auto-backup engine
auto_backup_engine = AutoBackupEngine(
@@ -123,6 +131,7 @@ async def lifespan(app: FastAPI):
audio_template_store=audio_template_store,
value_source_store=value_source_store,
profile_store=profile_store,
scene_preset_store=scene_preset_store,
profile_engine=profile_engine,
auto_backup_engine=auto_backup_engine,
)
@@ -162,6 +171,9 @@ async def lifespan(app: FastAPI):
# Start background health monitoring for all devices
await processor_manager.start_health_monitoring()
# Start MQTT service (broker connection for output, triggers, state)
await mqtt_service.start()
# Start profile engine (evaluates conditions and auto-starts/stops targets)
await profile_engine.start()
@@ -206,6 +218,12 @@ async def lifespan(app: FastAPI):
except Exception as e:
logger.error(f"Error stopping processors: {e}")
# Stop MQTT service
try:
await mqtt_service.stop()
except Exception as e:
logger.error(f"Error stopping MQTT service: {e}")
# Create FastAPI application
app = FastAPI(
title="LED Grab",