Skip to content

Commit

Permalink
Attempt to resolve issue #11 - to be tested
Browse files Browse the repository at this point in the history
  • Loading branch information
bdamokos committed Dec 26, 2024
1 parent e947189 commit 4150e93
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
21 changes: 18 additions & 3 deletions basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
26 changes: 25 additions & 1 deletion bus_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4150e93

Please sign in to comment.