Merge pull request #3679 from gsuarezc/master

owmweather: Fix infinite loop when settings.updated is not defined
pull/3681/head
Rob Pilling 2024-11-30 19:42:00 +00:00 committed by GitHub
commit 22078e87cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 8 deletions

View File

@ -6,3 +6,4 @@
0.06: Fix One Call API 3.0 not returning city names, which are required by the weather app 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.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

View File

@ -7,8 +7,8 @@
); );
let refreshMillis = function () { 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 () { let onCompleted = function () {
loading = false; loading = false;
@ -16,7 +16,7 @@
require('Storage').writeJSON("owmweather.json", settings); require('Storage').writeJSON("owmweather.json", settings);
if (timeoutRef) clearTimeout(timeoutRef); if (timeoutRef) clearTimeout(timeoutRef);
timeoutRef = setTimeout(loadIfDueAndReschedule, refreshMillis()); timeoutRef = setTimeout(loadIfDueAndReschedule, refreshMillis());
} };
let loadIfDueAndReschedule = function () { let loadIfDueAndReschedule = function () {
// also check if the weather.json file has been updated (e.g. force refresh) // also check if the weather.json file has been updated (e.g. force refresh)
@ -27,18 +27,18 @@
} }
let MillisUntilDue = settings.updated + refreshMillis() - Date.now(); let MillisUntilDue = settings.updated + refreshMillis() - Date.now();
if (MillisUntilDue <= 0) { if (!MillisUntilDue || MillisUntilDue <= 0) {
if (!loading) { if (!loading) {
loading = true; loading = true;
require("owmweather").pull(onCompleted); require("owmweather").pull(onCompleted);
} }
} else { } else {
// called to early, reschedule // 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); if (timeoutRef) clearTimeout(timeoutRef);
timeoutRef = setTimeout(loadIfDueAndReschedule, MillisUntilDue + 1); timeoutRef = setTimeout(loadIfDueAndReschedule, MillisUntilDue + 1);
} }
} };
if (settings.enabled) { if (settings.enabled) {
setTimeout(loadIfDueAndReschedule, 5000); // run 5 seconds after boot setTimeout(loadIfDueAndReschedule, 5000); // run 5 seconds after boot

View File

@ -1,7 +1,7 @@
{ "id": "owmweather", { "id": "owmweather",
"name": "OpenWeatherMap weather provider", "name": "OpenWeatherMap weather provider",
"shortName":"OWM Weather", "shortName":"OWM Weather",
"version": "0.08", "version": "0.09",
"description": "Pulls weather from OpenWeatherMap (OWM) API", "description": "Pulls weather from OpenWeatherMap (OWM) API",
"icon": "app.png", "icon": "app.png",
"type": "bootloader", "type": "bootloader",