live priority rotation fix

This commit is contained in:
Chuck
2025-08-09 20:31:47 -05:00
parent 29f36827ca
commit 8703c485bc

View File

@@ -893,9 +893,9 @@ class DisplayController:
# Check for live games and live_priority # Check for live games and live_priority
has_live_games, live_sport_type = self._check_live_games() has_live_games, live_sport_type = self._check_live_games()
is_currently_live = self.current_display_mode.endswith('_live') is_currently_live = self.current_display_mode.endswith('_live')
# Determine if any sport has live_priority True and live games
live_priority_takeover = False # Collect all sports with live_priority=True that have live games
live_priority_sport = None live_priority_sports = []
for sport, attr, priority in [ for sport, attr, priority in [
('nhl', 'nhl_live', self.nhl_live_priority), ('nhl', 'nhl_live', self.nhl_live_priority),
('nba', 'nba_live', self.nba_live_priority), ('nba', 'nba_live', self.nba_live_priority),
@@ -915,33 +915,51 @@ class DisplayController:
priority and priority and
live_games is not None and live_games is not None and
len(live_games) > 0): len(live_games) > 0):
live_priority_takeover = True live_priority_sports.append(sport)
live_priority_sport = sport logger.debug(f"Live priority sport found: {sport} with {len(live_games)} live games")
logger.debug(f"Live priority takeover triggered by {sport} with {len(live_games)} live games")
break
elif manager is not None and priority and live_games is not None: elif manager is not None and priority and live_games is not None:
logger.debug(f"{sport} has live_priority=True but {len(live_games)} live games (not taking over)") logger.debug(f"{sport} has live_priority=True but {len(live_games)} live games (not taking over)")
# Determine if we have any live priority sports
live_priority_takeover = len(live_priority_sports) > 0
manager_to_display = None manager_to_display = None
# --- State Machine for Display Logic --- # --- State Machine for Display Logic ---
if is_currently_live: if is_currently_live:
if live_priority_takeover: if live_priority_takeover:
# Only allow takeover if live_priority is True for the sport # Check if we need to rotate to the next live priority sport
if current_time - self.last_switch >= self.get_current_duration(): current_sport_type = self.current_display_mode.replace('_live', '')
new_mode = f"{live_priority_sport}_live"
if self.current_display_mode != new_mode: # If current sport is not in live priority sports, switch to first one
logger.info(f"Switching to only active live sport: {new_mode} from {self.current_display_mode}") if current_sport_type not in live_priority_sports:
next_sport = live_priority_sports[0]
new_mode = f"{next_sport}_live"
logger.info(f"Current live sport {current_sport_type} no longer has priority, switching to {new_mode}")
self.current_display_mode = new_mode self.current_display_mode = new_mode
# Reset logged duration when mode changes
if hasattr(self, '_last_logged_duration'): if hasattr(self, '_last_logged_duration'):
delattr(self, '_last_logged_duration') delattr(self, '_last_logged_duration')
self.force_clear = True self.force_clear = True
else:
self.force_clear = False
self.last_switch = current_time self.last_switch = current_time
manager_to_display = getattr(self, f"{live_priority_sport}_live", None) manager_to_display = getattr(self, f"{next_sport}_live", None)
else:
# Check if duration has elapsed for current sport
current_duration = self.get_current_duration()
if current_time - self.last_switch >= current_duration:
# Find next sport in rotation
current_index = live_priority_sports.index(current_sport_type)
next_index = (current_index + 1) % len(live_priority_sports)
next_sport = live_priority_sports[next_index]
new_mode = f"{next_sport}_live"
logger.info(f"Rotating live priority sports: {current_sport_type} -> {next_sport} (duration: {current_duration}s)")
self.current_display_mode = new_mode
if hasattr(self, '_last_logged_duration'):
delattr(self, '_last_logged_duration')
self.force_clear = True
self.last_switch = current_time
manager_to_display = getattr(self, f"{next_sport}_live", None)
else: else:
self.force_clear = False self.force_clear = False
current_sport_type = self.current_display_mode.replace('_live', '')
manager_to_display = getattr(self, f"{current_sport_type}_live", None) manager_to_display = getattr(self, f"{current_sport_type}_live", None)
else: else:
# If no sport has live_priority takeover, treat as regular rotation # If no sport has live_priority takeover, treat as regular rotation
@@ -949,13 +967,15 @@ class DisplayController:
if not is_currently_live: if not is_currently_live:
previous_mode_before_switch = self.current_display_mode previous_mode_before_switch = self.current_display_mode
if live_priority_takeover: if live_priority_takeover:
new_mode = f"{live_priority_sport}_live" # Switch to first live priority sport
if self.current_display_mode != new_mode: next_sport = live_priority_sports[0]
new_mode = f"{next_sport}_live"
# Double-check that the manager actually has live games before switching # Double-check that the manager actually has live games before switching
target_manager = getattr(self, f"{live_priority_sport}_live", None) target_manager = getattr(self, f"{next_sport}_live", None)
if target_manager and hasattr(target_manager, 'live_games') and len(target_manager.live_games) > 0: if target_manager and hasattr(target_manager, 'live_games') and len(target_manager.live_games) > 0:
logger.info(f"Live priority takeover: Switching to {new_mode} from {self.current_display_mode}") logger.info(f"Live priority takeover: Switching to {new_mode} from {self.current_display_mode}")
logger.debug(f"[DisplayController] Live priority takeover details: sport={live_priority_sport}, manager={target_manager}, live_games={target_manager.live_games}") logger.debug(f"[DisplayController] Live priority takeover details: sport={next_sport}, manager={target_manager}, live_games={target_manager.live_games}")
if previous_mode_before_switch == 'music' and self.music_manager: if previous_mode_before_switch == 'music' and self.music_manager:
self.music_manager.deactivate_music_display() self.music_manager.deactivate_music_display()
self.current_display_mode = new_mode self.current_display_mode = new_mode
@@ -968,10 +988,6 @@ class DisplayController:
else: else:
logger.warning(f"[DisplayController] Live priority takeover attempted for {new_mode} but manager has no live games, skipping takeover") logger.warning(f"[DisplayController] Live priority takeover attempted for {new_mode} but manager has no live games, skipping takeover")
live_priority_takeover = False live_priority_takeover = False
else:
self.force_clear = False
self.last_switch = current_time
manager_to_display = getattr(self, f"{live_priority_sport}_live", None)
else: else:
# No live_priority takeover, regular rotation # No live_priority takeover, regular rotation
needs_switch = False needs_switch = False
@@ -1005,12 +1021,15 @@ class DisplayController:
# Reset logged duration when mode changes # Reset logged duration when mode changes
if hasattr(self, '_last_logged_duration'): if hasattr(self, '_last_logged_duration'):
delattr(self, '_last_logged_duration') delattr(self, '_last_logged_duration')
else:
needs_switch = False
if needs_switch: if needs_switch:
self.force_clear = True self.force_clear = True
self.last_switch = current_time self.last_switch = current_time
else: else:
self.force_clear = False self.force_clear = False
# Select the manager for the current regular mode # Only set manager_to_display if it hasn't been set by live priority logic
if manager_to_display is None:
if self.current_display_mode == 'clock' and self.clock: if self.current_display_mode == 'clock' and self.clock:
manager_to_display = self.clock manager_to_display = self.clock
elif self.current_display_mode == 'weather_current' and self.weather: elif self.current_display_mode == 'weather_current' and self.weather:
@@ -1039,57 +1058,58 @@ class DisplayController:
manager_to_display = self.nhl_recent manager_to_display = self.nhl_recent
elif self.current_display_mode == 'nhl_upcoming' and self.nhl_upcoming: elif self.current_display_mode == 'nhl_upcoming' and self.nhl_upcoming:
manager_to_display = self.nhl_upcoming manager_to_display = self.nhl_upcoming
elif self.current_display_mode == 'nhl_live' and self.nhl_live:
manager_to_display = self.nhl_live
elif self.current_display_mode == 'nba_recent' and self.nba_recent: elif self.current_display_mode == 'nba_recent' and self.nba_recent:
manager_to_display = self.nba_recent manager_to_display = self.nba_recent
elif self.current_display_mode == 'nba_upcoming' and self.nba_upcoming: elif self.current_display_mode == 'nba_upcoming' and self.nba_upcoming:
manager_to_display = self.nba_upcoming manager_to_display = self.nba_upcoming
elif self.current_display_mode == 'nba_live' and self.nba_live:
manager_to_display = self.nba_live
elif self.current_display_mode == 'mlb_recent' and self.mlb_recent:
manager_to_display = self.mlb_recent
elif self.current_display_mode == 'mlb_upcoming' and self.mlb_upcoming:
manager_to_display = self.mlb_upcoming
elif self.current_display_mode == 'mlb_live' and self.mlb_live:
manager_to_display = self.mlb_live
elif self.current_display_mode == 'milb_recent' and self.milb_recent:
manager_to_display = self.milb_recent
elif self.current_display_mode == 'milb_upcoming' and self.milb_upcoming:
manager_to_display = self.milb_upcoming
elif self.current_display_mode == 'milb_live' and self.milb_live:
manager_to_display = self.milb_live
elif self.current_display_mode == 'soccer_recent' and self.soccer_recent:
manager_to_display = self.soccer_recent
elif self.current_display_mode == 'soccer_upcoming' and self.soccer_upcoming:
manager_to_display = self.soccer_upcoming
elif self.current_display_mode == 'soccer_live' and self.soccer_live:
manager_to_display = self.soccer_live
elif self.current_display_mode == 'nfl_recent' and self.nfl_recent: elif self.current_display_mode == 'nfl_recent' and self.nfl_recent:
manager_to_display = self.nfl_recent manager_to_display = self.nfl_recent
elif self.current_display_mode == 'nfl_upcoming' and self.nfl_upcoming: elif self.current_display_mode == 'nfl_upcoming' and self.nfl_upcoming:
manager_to_display = self.nfl_upcoming manager_to_display = self.nfl_upcoming
elif self.current_display_mode == 'nfl_live' and self.nfl_live:
manager_to_display = self.nfl_live
elif self.current_display_mode == 'ncaa_fb_recent' and self.ncaa_fb_recent: elif self.current_display_mode == 'ncaa_fb_recent' and self.ncaa_fb_recent:
manager_to_display = self.ncaa_fb_recent manager_to_display = self.ncaa_fb_recent
elif self.current_display_mode == 'ncaa_fb_upcoming' and self.ncaa_fb_upcoming: elif self.current_display_mode == 'ncaa_fb_upcoming' and self.ncaa_fb_upcoming:
manager_to_display = self.ncaa_fb_upcoming manager_to_display = self.ncaa_fb_upcoming
elif self.current_display_mode == 'ncaa_fb_live' and self.ncaa_fb_live:
manager_to_display = self.ncaa_fb_live
elif self.current_display_mode == 'ncaa_baseball_recent' and self.ncaa_baseball_recent: elif self.current_display_mode == 'ncaa_baseball_recent' and self.ncaa_baseball_recent:
manager_to_display = self.ncaa_baseball_recent manager_to_display = self.ncaa_baseball_recent
elif self.current_display_mode == 'ncaa_baseball_upcoming' and self.ncaa_baseball_upcoming: elif self.current_display_mode == 'ncaa_baseball_upcoming' and self.ncaa_baseball_upcoming:
manager_to_display = self.ncaa_baseball_upcoming manager_to_display = self.ncaa_baseball_upcoming
elif self.current_display_mode == 'ncaa_baseball_live' and self.ncaa_baseball_live:
manager_to_display = self.ncaa_baseball_live
elif self.current_display_mode == 'ncaam_basketball_recent' and self.ncaam_basketball_recent: elif self.current_display_mode == 'ncaam_basketball_recent' and self.ncaam_basketball_recent:
manager_to_display = self.ncaam_basketball_recent manager_to_display = self.ncaam_basketball_recent
elif self.current_display_mode == 'ncaam_basketball_upcoming' and self.ncaam_basketball_upcoming: elif self.current_display_mode == 'ncaam_basketball_upcoming' and self.ncaam_basketball_upcoming:
manager_to_display = self.ncaam_basketball_upcoming manager_to_display = self.ncaam_basketball_upcoming
elif self.current_display_mode == 'mlb_recent' and self.mlb_recent:
manager_to_display = self.mlb_recent
elif self.current_display_mode == 'mlb_upcoming' and self.mlb_upcoming:
manager_to_display = self.mlb_upcoming
elif self.current_display_mode == 'milb_recent' and self.milb_recent:
manager_to_display = self.milb_recent
elif self.current_display_mode == 'milb_upcoming' and self.milb_upcoming:
manager_to_display = self.milb_upcoming
elif self.current_display_mode == 'soccer_recent' and self.soccer_recent:
manager_to_display = self.soccer_recent
elif self.current_display_mode == 'soccer_upcoming' and self.soccer_upcoming:
manager_to_display = self.soccer_upcoming
elif self.current_display_mode == 'music' and self.music_manager:
manager_to_display = self.music_manager
elif self.current_display_mode == 'nhl_live' and self.nhl_live:
manager_to_display = self.nhl_live
elif self.current_display_mode == 'nba_live' and self.nba_live:
manager_to_display = self.nba_live
elif self.current_display_mode == 'nfl_live' and self.nfl_live:
manager_to_display = self.nfl_live
elif self.current_display_mode == 'ncaa_fb_live' and self.ncaa_fb_live:
manager_to_display = self.ncaa_fb_live
elif self.current_display_mode == 'ncaa_baseball_live' and self.ncaa_baseball_live:
manager_to_display = self.ncaa_baseball_live
elif self.current_display_mode == 'ncaam_basketball_live' and self.ncaam_basketball_live: elif self.current_display_mode == 'ncaam_basketball_live' and self.ncaam_basketball_live:
manager_to_display = self.ncaam_basketball_live manager_to_display = self.ncaam_basketball_live
elif self.current_display_mode == 'mlb_live' and self.mlb_live:
manager_to_display = self.mlb_live
elif self.current_display_mode == 'milb_live' and self.milb_live:
manager_to_display = self.milb_live
elif self.current_display_mode == 'soccer_live' and self.soccer_live:
manager_to_display = self.soccer_live
# --- Perform Display Update --- # --- Perform Display Update ---
try: try: