Skip to content

Commit c3dc1ce

Browse files
pjleducclaude
andcommitted
Bug fixes: calendar resilience, weather off-by-one, refresh timeout
- calendar.py: skip failed calendar URLs instead of crashing plugin - weather.py: fix Open-Meteo forecast day label off-by-one (PR fatihak#613) - model.py: remove duplicate scheduled refresh logic - refresh_task.py: add 60s timeout to prevent indefinite hangs Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent de8542e commit c3dc1ce

4 files changed

Lines changed: 15 additions & 17 deletions

File tree

src/model.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ class PlaylistManager:
6767
DEFAULT_PLAYLIST_START = "00:00"
6868
DEFAULT_PLAYLIST_END = "24:00"
6969

70-
def __init__(self, playlists=[], active_playlist=None):
70+
def __init__(self, playlists=None, active_playlist=None):
7171
"""Initialize PlaylistManager with a list of playlists."""
72-
self.playlists = playlists
72+
self.playlists = playlists if playlists is not None else []
7373
self.active_playlist = active_playlist
7474

7575
def get_playlist_names(self):
@@ -306,14 +306,6 @@ def should_refresh(self, current_time):
306306
return True
307307

308308
# Check for scheduled refresh (HH:MM format)
309-
if "scheduled" in self.refresh:
310-
scheduled_time_str = self.refresh.get("scheduled")
311-
latest_refresh_str = latest_refresh_dt.strftime("%H:%M")
312-
313-
# If the latest refresh is before the scheduled time today
314-
if latest_refresh_str < scheduled_time_str:
315-
return True
316-
317309
if "scheduled" in self.refresh:
318310
scheduled_time_str = self.refresh.get("scheduled")
319311
scheduled_time = datetime.strptime(scheduled_time_str, "%H:%M").time()

src/plugins/calendar/calendar.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ def fetch_ics_events(self, calendar_urls, colors, tz, start_range, end_range):
7474
parsed_events = []
7575

7676
for calendar_url, color in zip(calendar_urls, colors):
77-
cal = self.fetch_calendar(calendar_url)
77+
try:
78+
cal = self.fetch_calendar(calendar_url)
79+
except RuntimeError as e:
80+
logger.warning(f"Skipping calendar due to fetch error: {e}")
81+
continue
7882
events = recurring_ical_events.of(cal).between(start_range, end_range)
7983
contrast_color = self.get_contrast_color(color)
8084

src/plugins/weather/weather.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,16 +340,17 @@ def parse_open_meteo_forecast(self, daily_data, units, tz, is_day, lat):
340340

341341
forecast = []
342342

343-
for i in range(0, len(times)):
344-
dt = datetime.fromisoformat(times[i]).replace(tzinfo=timezone.utc).astimezone(tz)
345-
day_label = dt.strftime("%a")
343+
for i in range(0, len(times)):
344+
forecast_date = date.fromisoformat(times[i])
345+
day_label = forecast_date.strftime("%a")
346346

347347
code = weather_codes[i] if i < len(weather_codes) else 0
348348
weather_icon = self.map_weather_code_to_icon(code, is_day=1)
349349
weather_icon_path = self.get_plugin_dir(f"icons/{weather_icon}.png")
350350

351-
timestamp = int(dt.replace(hour=12, minute=0, second=0).timestamp())
352-
target_date: date = dt.date() + timedelta(days=1)
351+
dt = datetime(forecast_date.year, forecast_date.month, forecast_date.day, 12, 0, 0, tzinfo=tz)
352+
timestamp = int(dt.timestamp())
353+
target_date: date = forecast_date
353354

354355
try:
355356
phase_age = moon.phase(target_date)

src/refresh_task.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ def manual_update(self, refresh_action):
143143

144144
self.condition.notify_all() # Wake the thread to process manual update
145145

146-
self.refresh_event.wait()
146+
if not self.refresh_event.wait(timeout=300):
147+
raise TimeoutError("Manual update timed out after 300 seconds")
147148
if self.refresh_result.get("exception"):
148149
raise self.refresh_result.get("exception")
149150
else:

0 commit comments

Comments
 (0)