feat: cycle through multiple live games with frequent updates

This commit is contained in:
ChuckBuilds
2025-04-19 22:08:21 -05:00
parent 5ecb90946e
commit 8ceabc0a01

View File

@@ -308,69 +308,42 @@ class DisplayController:
# Check for live games # Check for live games
has_live_games, sport_type = self._check_live_games() has_live_games, sport_type = self._check_live_games()
# If we have live games, update their display immediately # If we have live games, cycle through them
if has_live_games: if has_live_games:
if sport_type == 'nhl' and self.nhl_live: # Check if it's time to switch live games
self.nhl_live.display(force_clear=True)
elif sport_type == 'nba' and self.nba_live:
self.nba_live.display(force_clear=True)
# Check for mode switch
if current_time - self.last_switch > self.get_current_duration(): if current_time - self.last_switch > self.get_current_duration():
# If there are live games, check if they involve favorite teams # Switch between NHL and NBA live games if both are available
if has_live_games: if sport_type == 'nhl' and self.nhl_live and self.nba_live and self.nba_live.live_games:
if sport_type == 'nhl' and self.nhl_live: sport_type = 'nba'
# Check if any live NHL games involve favorite teams self.last_switch = current_time
favorite_teams_involved = any( self.force_clear = True
game["home_abbr"] in self.nhl_favorite_teams or elif sport_type == 'nba' and self.nba_live and self.nhl_live and self.nhl_live.live_games:
game["away_abbr"] in self.nhl_favorite_teams sport_type = 'nhl'
for game in self.nhl_live.live_games self.last_switch = current_time
) self.force_clear = True
if favorite_teams_involved:
self.current_display_mode = 'nhl_live'
logger.info("Live NHL games with favorite teams available")
else:
# No favorite teams in live games, check for team rotation
if self._has_team_games('nhl'):
self._rotate_team_games('nhl')
else:
# No favorite team games, continue with regular rotation
self.current_mode_index = (self.current_mode_index + 1) % len(self.available_modes)
self.current_display_mode = self.available_modes[self.current_mode_index]
logger.info(f"Switching to: {self.current_display_mode}")
# Display the current live game
if sport_type == 'nhl' and self.nhl_live:
self.nhl_live.update() # Force update to get latest data
self.nhl_live.display(force_clear=self.force_clear)
elif sport_type == 'nba' and self.nba_live: elif sport_type == 'nba' and self.nba_live:
# Check if any live NBA games involve favorite teams self.nba_live.update() # Force update to get latest data
favorite_teams_involved = any( self.nba_live.display(force_clear=self.force_clear)
game["home_abbr"] in self.nba_favorite_teams or
game["away_abbr"] in self.nba_favorite_teams self.force_clear = False
for game in self.nba_live.live_games continue # Skip the rest of the loop to stay on live games
)
if favorite_teams_involved: # Only proceed with mode switching if no live games
self.current_display_mode = 'nba_live' if current_time - self.last_switch > self.get_current_duration():
logger.info("Live NBA games with favorite teams available")
else:
# No favorite teams in live games, check for team rotation
if self._has_team_games('nba'):
self._rotate_team_games('nba')
else:
# No favorite team games, continue with regular rotation
self.current_mode_index = (self.current_mode_index + 1) % len(self.available_modes)
self.current_display_mode = self.available_modes[self.current_mode_index]
logger.info(f"Switching to: {self.current_display_mode}")
else:
# No live games, continue with regular rotation # No live games, continue with regular rotation
self.current_mode_index = (self.current_mode_index + 1) % len(self.available_modes) self.current_mode_index = (self.current_mode_index + 1) % len(self.available_modes)
self.current_display_mode = self.available_modes[self.current_mode_index] self.current_display_mode = self.available_modes[self.current_mode_index]
logger.info(f"Switching to: {self.current_display_mode}") logger.info(f"Switching to: {self.current_display_mode}")
# Force clear when switching modes
self.force_clear = True self.force_clear = True
self.last_switch = current_time self.last_switch = current_time
# Display current mode frame (only for non-live modes) # Display current mode frame (only for non-live modes)
try: try:
if self.current_display_mode != 'nhl_live' and self.current_display_mode != 'nba_live':
if self.current_display_mode == 'clock' and self.clock: if self.current_display_mode == 'clock' and self.clock:
self.clock.display_time(force_clear=self.force_clear) self.clock.display_time(force_clear=self.force_clear)