Browse Source

fix playlist reporting

Fabio De Simone 11 months ago
parent
commit
bccb887372

+ 14 - 14
dune_weaver_flask/modules/core/pattern_manager.py

@@ -20,8 +20,6 @@ CLEAR_PATTERNS = {
     "clear_sideway":  "./patterns/clear_sideway.thr"
     "clear_sideway":  "./patterns/clear_sideway.thr"
 }
 }
 os.makedirs(THETA_RHO_DIR, exist_ok=True)
 os.makedirs(THETA_RHO_DIR, exist_ok=True)
-current_playlist = []
-current_playing_index = None
 
 
 def list_theta_rho_files():
 def list_theta_rho_files():
     files = []
     files = []
@@ -220,17 +218,17 @@ def run_theta_rho_files(file_paths, pause_time=0, clear_pattern=None, run_mode="
     """Run multiple .thr files in sequence with options."""
     """Run multiple .thr files in sequence with options."""
     state.stop_requested = False
     state.stop_requested = False
     
     
+    # Set initial playlist state
+    state.playlist_mode = run_mode
+    state.current_playlist_index = 0
+    
     if shuffle:
     if shuffle:
         random.shuffle(file_paths)
         random.shuffle(file_paths)
         logger.info("Playlist shuffled")
         logger.info("Playlist shuffled")
 
 
-    state.current_playlist = file_paths
-    state.playlist_mode = run_mode
-
     while True:
     while True:
         for idx, path in enumerate(file_paths):
         for idx, path in enumerate(file_paths):
             logger.info(f"Upcoming pattern: {path}")
             logger.info(f"Upcoming pattern: {path}")
-            logger.info(idx)
             state.current_playlist_index = idx
             state.current_playlist_index = idx
             schedule_checker(schedule_hours)
             schedule_checker(schedule_hours)
             if state.stop_requested:
             if state.stop_requested:
@@ -253,6 +251,7 @@ def run_theta_rho_files(file_paths, pause_time=0, clear_pattern=None, run_mode="
                 run_theta_rho_file(clear_file_path, schedule_hours)
                 run_theta_rho_file(clear_file_path, schedule_hours)
 
 
             if not state.stop_requested:
             if not state.stop_requested:
+                
                 logger.info(f"Running pattern {idx + 1} of {len(file_paths)}: {path}")
                 logger.info(f"Running pattern {idx + 1} of {len(file_paths)}: {path}")
                 run_theta_rho_file(path, schedule_hours)
                 run_theta_rho_file(path, schedule_hours)
 
 
@@ -281,20 +280,21 @@ def run_theta_rho_files(file_paths, pause_time=0, clear_pattern=None, run_mode="
             break
             break
     logger.info("All requested patterns completed (or stopped)")
     logger.info("All requested patterns completed (or stopped)")
 
 
-def stop_actions():
+def stop_actions(clear_playlist = False):
     """Stop all current actions."""
     """Stop all current actions."""
-
     with state.pause_condition:
     with state.pause_condition:
         state.pause_requested = False
         state.pause_requested = False
         state.stop_requested = True
         state.stop_requested = True
         state.current_playing_file = None
         state.current_playing_file = None
-        state.current_playlist = None
-        state.current_playlist_index = None
         state.execution_progress = None
         state.execution_progress = None
-        serial_manager.update_machine_position()
         state.is_clearing = False
         state.is_clearing = False
-        state.playlist_mode = None
+        if clear_playlist:
+            # Clear playlist state
+            state.current_playlist = None
+            state.current_playlist_index = None
+            state.playlist_mode = None
         state.pause_condition.notify_all()
         state.pause_condition.notify_all()
+        serial_manager.update_machine_position()
 
 
 def get_status():
 def get_status():
     """Get the current execution status."""
     """Get the current execution status."""
@@ -310,7 +310,7 @@ def get_status():
         "pause_requested": state.pause_requested,
         "pause_requested": state.pause_requested,
         "current_playing_file": state.current_playing_file,
         "current_playing_file": state.current_playing_file,
         "execution_progress": state.execution_progress,
         "execution_progress": state.execution_progress,
-        "current_playing_index": current_playing_index,
-        "current_playlist": current_playlist,
+        "current_playing_index": state.current_playlist_index,
+        "current_playlist": state.current_playlist,
         "is_clearing": state.is_clearing
         "is_clearing": state.is_clearing
     }
     }

+ 2 - 0
dune_weaver_flask/modules/core/playlist_manager.py

@@ -3,6 +3,7 @@ import os
 import threading
 import threading
 import logging
 import logging
 from dune_weaver_flask.modules.core import pattern_manager
 from dune_weaver_flask.modules.core import pattern_manager
+from dune_weaver_flask.modules.core.state import state
 
 
 # Configure logging
 # Configure logging
 logger = logging.getLogger(__name__)
 logger = logging.getLogger(__name__)
@@ -99,6 +100,7 @@ def run_playlist(playlist_name, pause_time=0, clear_pattern=None, run_mode="sing
 
 
     try:
     try:
         logger.info(f"Starting playlist '{playlist_name}' with mode={run_mode}, shuffle={shuffle}")
         logger.info(f"Starting playlist '{playlist_name}' with mode={run_mode}, shuffle={shuffle}")
+        state.current_playlist = playlist_name
         threading.Thread(
         threading.Thread(
             target=pattern_manager.run_theta_rho_files,
             target=pattern_manager.run_theta_rho_files,
             args=(file_paths,),
             args=(file_paths,),

+ 1 - 1
dune_weaver_flask/modules/mqtt/handler.py

@@ -289,7 +289,7 @@ class MQTTHandler(BaseMQTTHandler):
 
 
                 # Update playlist select state
                 # Update playlist select state
                 if state.current_playlist:
                 if state.current_playlist:
-                    current_playlist_name = state.current_playlist[0]
+                    current_playlist_name = state.current_playlist
                     self.client.publish(f"{self.playlist_select_topic}/state", current_playlist_name, retain=True)
                     self.client.publish(f"{self.playlist_select_topic}/state", current_playlist_name, retain=True)
                 else:
                 else:
                     self.client.publish(f"{self.playlist_select_topic}/state", "None", retain=True)
                     self.client.publish(f"{self.playlist_select_topic}/state", "None", retain=True)