Fix settings changes not taking effect until the poll interval elapsed
config.update_screen_settings() writes to config.json immediately, but each screen's cached check() result only gets refreshed on its own poll_interval (30 min for weather by default). So e.g. changing Weather's forecast_days from 3 to 5 saved correctly but kept showing the old 3-day forecast for up to 30 minutes, since the cached state was fetched under the old setting and nothing told the scheduler to re-check sooner. Added Scheduler.invalidate_screen(), called from every settings route right after config.update_screen_settings() succeeds, which resets that screen's cache timestamp so the very next tick re-checks instead of reusing stale data. Reproduced the bug and verified the fix with a direct Scheduler unit test, then confirmed end-to-end through a real running app (POST forecast_days=5, saw it render 5 days within the next ~5s tick instead of after 30 minutes).
This commit is contained in:
1 parent
32c98cec16
commit
79641914fd
2 files changed
+21
No files matched your search
@@ -88,6 +88,18 @@ class Scheduler:
|
||||
self.config.resume_rotation()
|
||||
self._wake.set()
|
||||
|
||||
def invalidate_screen(self, screen_id: str):
|
||||
"""Force the next tick to re-check() this screen instead of reusing
|
||||
its cached state, however much of its poll_interval is left.
|
||||
Without this, a settings change (e.g. weather's forecast_days) sits
|
||||
in config.json immediately but the screen keeps rendering whatever
|
||||
it last fetched under the *old* settings until its own poll_interval
|
||||
happens to elapse -- up to 30 minutes for weather's default."""
|
||||
cache = self._caches.get(screen_id)
|
||||
if cache is not None:
|
||||
cache.checked_at = 0.0
|
||||
self._wake.set()
|
||||
|
||||
def get_status(self) -> dict:
|
||||
with self._status_lock:
|
||||
status = dict(self._status)
|
||||
|
||||
Reference in new issue
Block a user