Skip to content

Commit

Permalink
Merge pull request #3679 from gsuarezc/master
Browse files Browse the repository at this point in the history
owmweather: Fix infinite loop when settings.updated is not defined
  • Loading branch information
bobrippling authored Nov 30, 2024
2 parents dfde434 + 9563658 commit 22078e8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
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

0 comments on commit 22078e8

Please sign in to comment.