Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

owmweather: Fix infinite loop when settings.updated is not defined #3679

Merged
merged 1 commit into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/owmweather/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
0.05: Upgrade OWM to One Call API 3.0. Add pressure to weather.json
0.06: Fix One Call API 3.0 not returning city names, which are required by the weather app
0.07: Update weather after reconnecting bluetooth if update is due, refactor code
0.08: Undo change to One Call API 3.0
0.08: Undo change to One Call API 3.0
0.09: Fix infinite loop when settings.updated is not defined
12 changes: 6 additions & 6 deletions apps/owmweather/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
);

let refreshMillis = function () {
return settings.refresh * 1000 * 60 + 1 // +1 <- leave some slack
}
return settings.refresh * 1000 * 60 + 1; // +1 <- leave some slack
};

let onCompleted = function () {
loading = false;
settings.updated = Date.now();
require('Storage').writeJSON("owmweather.json", settings);
if (timeoutRef) clearTimeout(timeoutRef);
timeoutRef = setTimeout(loadIfDueAndReschedule, refreshMillis());
}
};

let loadIfDueAndReschedule = function () {
// also check if the weather.json file has been updated (e.g. force refresh)
Expand All @@ -27,18 +27,18 @@
}

let MillisUntilDue = settings.updated + refreshMillis() - Date.now();
if (MillisUntilDue <= 0) {
if (!MillisUntilDue || MillisUntilDue <= 0) {
if (!loading) {
loading = true;
require("owmweather").pull(onCompleted);
}
} else {
// called to early, reschedule
// console.log('Weather data is not due yet, rescheduling in ' + MillisUntilDue|0 + 'ms');
// console.log('Weather data is not due yet, rescheduling in ' + (MillisUntilDue || 0) + 'ms');
if (timeoutRef) clearTimeout(timeoutRef);
timeoutRef = setTimeout(loadIfDueAndReschedule, MillisUntilDue + 1);
}
}
};

if (settings.enabled) {
setTimeout(loadIfDueAndReschedule, 5000); // run 5 seconds after boot
Expand Down
2 changes: 1 addition & 1 deletion apps/owmweather/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ "id": "owmweather",
"name": "OpenWeatherMap weather provider",
"shortName":"OWM Weather",
"version": "0.08",
"version": "0.09",
"description": "Pulls weather from OpenWeatherMap (OWM) API",
"icon": "app.png",
"type": "bootloader",
Expand Down