Skip to content

Fix scheduled refresh not updating correctly and broken default image on first load#629

Open
saulob wants to merge 18 commits intofatihak:mainfrom
saulob:fix/scheduled-refresh-and-stale-image
Open

Fix scheduled refresh not updating correctly and broken default image on first load#629
saulob wants to merge 18 commits intofatihak:mainfrom
saulob:fix/scheduled-refresh-and-stale-image

Conversation

@saulob
Copy link
Copy Markdown

@saulob saulob commented Mar 19, 2026

Description

This PR improves the refresh logic and fixes stability issues in InkyPi. Fixes #380

Changes

  • Process all plugins in the active playlist each cycle
  • Fix playlist iteration getting stuck on a single plugin
  • Ensure scheduled and interval plugins refresh at the correct time
  • Prevent crash when a plugin returns no image
  • Add error handling and clearer logging for failed plugins
  • Return clear error when plugin fails to generate image
  • Add placeholder to avoid broken image on first load
  • Auto-reload main page on browser back navigation

Impact

  • More reliable and responsive refresh behavior
  • No crashes when plugin image generation fails
  • Clearer error visibility for plugin failures
  • Better UX when navigating back in the browser
  • Better handling of initial and error states
2026-03-19_17-15 2026-03-19_16-02

saulob added 6 commits March 19, 2026 14:16
- Remove duplicate scheduled refresh check in PluginInstance.should_refresh()
  that incorrectly triggered refresh before the scheduled time by comparing
  latest_refresh hour string against scheduled time string
- Change PlaylistRefresh.execute() to return None instead of loading a stale
  cached image when plugin does not need refresh, preventing the display from
  reverting to outdated clock images
- Handle None return from execute() in RefreshTask._run() to skip plugins
  that are not due for refresh
… UTC

Align default timezone with refresh_task which already defaults to UTC.
Previously, if timezone was not configured, the clock would display
US/Eastern time instead of the expected system/configured timezone.

fix: scheduled plugin should not refresh before scheduled time on first run

When a scheduled plugin is created with no previous refresh history,
it now waits until the scheduled time instead of refreshing immediately.
…xists

Display a 'No image displayed yet' message on the dashboard when the
system starts fresh and no plugin has generated an image yet.
…ex on skip

- Revert DEFAULT_TIMEZONE back to US/Eastern since UTC is not available
  in the settings UI timezone list
- When a plugin instance is skipped (not time to refresh), revert the
  playlist index so the same plugin is retried on the next cycle instead
  of advancing to the next one and causing a 1-minute delay
- Stop reverting playlist index when a plugin is skipped, preventing
  the playlist from being stuck on the same plugin indefinitely
- Add null check after generate_image() to gracefully skip plugins
  that fail to produce an image instead of crashing
- Loop through all plugins in the playlist to find one that needs
  refreshing, instead of only checking one plugin per cycle
- Prevents delayed refresh when playlist has many plugins (e.g. 10
  plugins with 1-min cycle no longer takes 10 min to reach a plugin)
@saulob saulob changed the title Fixscheduled refresh and stale image Fix scheduled refresh and stale image Mar 19, 2026
saulob added 2 commits March 19, 2026 18:11
- ManualRefresh raises RuntimeError with descriptive message
- update_now returns error response when image is null in dev mode
- Detect bfcache restore via pageshow event and force reload
- Ensures last refresh time and image are up to date after update
@saulob saulob marked this pull request as draft March 26, 2026 00:12
@saulob saulob marked this pull request as ready for review March 26, 2026 00:12
Copilot AI review requested due to automatic review settings March 26, 2026 00:12
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR targets InkyPi’s refresh/playlist behavior and UI resilience, aiming to improve scheduled/interval refresh correctness, avoid crashes when plugins fail to generate images, and improve browser UX when navigating back.

Changes:

  • Updates playlist selection/refresh logic in RefreshTask, including skipping/force refresh behavior and additional error handling for missing images.
  • Refines PluginInstance.should_refresh() scheduled-refresh behavior for first-run and subsequent runs.
  • Improves the main UI page with a first-load placeholder and forces reload on back navigation; adds API error handling when a plugin returns no image.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
src/templates/inky.html Adds back-navigation reload behavior and an image placeholder on load/error.
src/refresh_task.py Changes playlist iteration and refresh execution behavior; adds handling for None images and more logging.
src/model.py Adjusts scheduled refresh logic in PluginInstance.should_refresh().
src/blueprints/plugin.py Returns a clearer API error when generate_image() returns None.
Comments suppressed due to low confidence (1)

src/model.py:325

  • The scheduled-refresh check further down also compares scheduled_time (tz-naive) with latest_refresh_dt.time() / current_time.time() (tz-aware). Even after the initial-refresh case is fixed, this block will still raise the same TypeError for scheduled plugins. Consider converting latest_refresh_dt into the same timezone as current_time, then compare full datetimes (date + scheduled wall time) instead of time objects.
        if "scheduled" in self.refresh:
            scheduled_time_str = self.refresh.get("scheduled")
            scheduled_time = datetime.strptime(scheduled_time_str, "%H:%M").time()
            
            latest_refresh_date = latest_refresh_dt.date()
            current_date = current_time.date()

            # Determine if a refresh is needed based on scheduled time and last refresh
            if (latest_refresh_date < current_date and current_time.time() >= scheduled_time) or \
            (latest_refresh_date == current_date and latest_refresh_dt.time() < scheduled_time <= current_time.time()):
                return True

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/model.py
Comment thread src/model.py
Comment thread src/refresh_task.py Outdated
Comment thread src/refresh_task.py Outdated
Comment thread src/refresh_task.py Outdated
Comment thread src/templates/inky.html Outdated
@saulob
Copy link
Copy Markdown
Author

saulob commented Mar 26, 2026

All Copilot review comments addressed. Fixed timezone handling, separated rotation from refresh logic, ensured cached images are used when not due, reduced log noise, and added pytest coverage. All tests passing, ready for review

@saulob saulob marked this pull request as draft March 26, 2026 11:53
@saulob
Copy link
Copy Markdown
Author

saulob commented Mar 27, 2026

I tested this change on a real device throughout the day and the refresh behavior is now working as expected

The system correctly prioritizes plugins based on their due time instead of playlist order, and no longer skips scheduled or interval-based plugins

The refresh cycle is stable and no unnecessary display updates are happening

Logs confirm that the most overdue plugin is always selected, and backlog is processed correctly over time

Example log:

image image

@saulob saulob marked this pull request as ready for review March 27, 2026 21:23
@saulob saulob closed this Mar 28, 2026
@saulob saulob reopened this Mar 28, 2026
@saulob saulob changed the title Fix scheduled refresh and stale image Fix scheduled refresh not updating correctly and broken default image on first load Mar 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Playlist refresh timestamps and clock plugin show inconsistent times (timezone mismatch)

2 participants