diff --git a/basic.py b/basic.py index f2f86fb..98b79ed 100644 --- a/basic.py +++ b/basic.py @@ -429,10 +429,15 @@ def _force_display_update(self): valid_bus_data = [ bus for bus in bus_data - if any(time != "--" for time in bus["times"]) + if any(time and time != "--" for time in bus["times"]) ] - if valid_bus_data and not error_message: + # Check if we have any bus data at all + if not bus_data and not error_message and weather_enabled and weather_data: + logger.info("Initial display: no bus data available, showing weather data") + draw_weather_display(self.epd, weather_data) + self.in_weather_mode = True + elif valid_bus_data and not error_message: logger.info(f"Initial display: showing bus data ({len(valid_bus_data)} entries)") current_weather = weather_data['current'] if weather_data else None update_display(self.epd, current_weather, valid_bus_data, error_message, stop_name) @@ -508,7 +513,17 @@ def _check_display_updates(self): stop_name = self.bus_manager.get_stop_name() with self._display_lock: - if valid_bus_data and not error_message: + # Check if we have any bus data at all + if not valid_bus_data and not error_message and weather_enabled and weather_data: + logger.info("No bus data available, switching to weather mode...") + self.in_weather_mode = True + self.perform_full_refresh() + draw_weather_display(self.epd, weather_data) + self.last_weather_data = weather_data + self.last_weather_update = current_time + self.last_display_update = datetime.now() + logger.info("Weather display updated successfully") + elif valid_bus_data and not error_message: logger.info("Updating bus display...") self.in_weather_mode = False self.perform_full_refresh() diff --git a/bus_service.py b/bus_service.py index 7c1e219..aac4420 100644 --- a/bus_service.py +++ b/bus_service.py @@ -298,6 +298,11 @@ def get_waiting_times(self) -> tuple[List[Dict], str, str]: stop_name = stop_data.get("name", "") logger.debug(f"Stop name: {stop_name}") + # Check if there are any lines in the stop data + if not stop_data.get("lines"): + logger.info(f"No active lines at stop {stop_name}") + return [], None, stop_name + bus_times = [] for line in self.lines_of_interest: logger.debug(f"Processing line {line}") @@ -353,7 +358,26 @@ def get_waiting_times(self) -> tuple[List[Dict], str, str]: minutes_source = None minutes = None minutes_emoji = '' - time = f"{minutes_emoji}{minutes}" + + # Filter out invalid times (negative times less than -5 minutes) + try: + if minutes and isinstance(minutes, str): + # Only clean and check if it might be a negative number + if '-' in minutes: + # Remove any quotes and non-numeric characters except minus sign + cleaned_minutes = ''.join(c for c in minutes if c.isdigit() or c == '-') + if cleaned_minutes: + minutes_int = int(cleaned_minutes) + if minutes_int < -5: # Skip if less than -5 minutes + logger.warning(f"Skipping invalid negative time: {minutes} minutes") + minutes = None + minutes_emoji = '' + except ValueError as e: + logger.warning(f"Could not parse minutes value '{minutes}': {e}") + minutes = None + minutes_emoji = '' + + time = f"{minutes_emoji}{minutes}" if minutes else "" message = None # Check for special messages