Procházet zdrojové kódy

Fix DW LEDs staying on green blink after connection

The effect_idle() function was doing nothing when no idle effect was
configured, causing the green "connected" blink to persist. Now defaults
to Rainbow effect using controller's current speed/intensity parameters.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
tuanchris před 3 týdny
rodič
revize
29b6815061
2 změnil soubory, kde provedl 8 přidání a 9 odebrání
  1. 1 1
      main.py
  2. 7 8
      modules/led/dw_led_controller.py

+ 1 - 1
main.py

@@ -187,7 +187,7 @@ async def lifespan(app: FastAPI):
             # Initialize hardware and start idle effect (matches behavior of /set_led_config)
             status = state.led_controller.check_status()
             if status.get("connected", False):
-                state.led_controller.effect_idle()
+                state.led_controller.effect_idle(state.dw_led_idle_effect)
                 _start_idle_led_timeout()
                 logger.info("DW LEDs hardware initialized and idle effect started")
             else:

+ 7 - 8
modules/led/dw_led_controller.py

@@ -548,13 +548,12 @@ def effect_loading(controller: DWLEDController) -> bool:
 
 
 def effect_idle(controller: DWLEDController, effect_settings: Optional[dict] = None) -> bool:
-    """Show idle effect with full settings"""
+    """Show idle effect with full settings. If no effect configured, plays Rainbow with current parameters."""
     try:
-        if effect_settings and isinstance(effect_settings, dict):
-            # New format: full settings dict
-            controller.set_power(1)
+        controller.set_power(1)
 
-            # Set effect
+        if effect_settings and isinstance(effect_settings, dict):
+            # Configured idle effect: apply full settings
             effect_id = effect_settings.get("effect_id", 0)
             palette_id = effect_settings.get("palette_id", 0)
             speed = effect_settings.get("speed", 128)
@@ -586,10 +585,10 @@ def effect_idle(controller: DWLEDController, effect_settings: Optional[dict] = N
                     color2=(r2, g2, b2),
                     color3=(r3, g3, b3)
                 )
+        else:
+            # Default: Rainbow effect with current controller parameters
+            controller.set_effect(8)  # Rainbow - uses controller's current speed/intensity
 
-            return True
-
-        # Default: do nothing (keep current LED state)
         return True
     except Exception as e:
         logger.error(f"Error setting idle effect: {e}")