diff --git a/apps/owmweather/ChangeLog b/apps/owmweather/ChangeLog index a2251f83b1..6a5706af15 100644 --- a/apps/owmweather/ChangeLog +++ b/apps/owmweather/ChangeLog @@ -6,4 +6,5 @@ 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.09: Fix infinite loop when settings.updated is not defined \ No newline at end of file +0.09: Fix infinite loop when settings.updated is not defined +0.10: Fix settings.updated being updated even when OWM call failed \ No newline at end of file diff --git a/apps/owmweather/boot.js b/apps/owmweather/boot.js index dc206be38d..82e3a280ae 100644 --- a/apps/owmweather/boot.js +++ b/apps/owmweather/boot.js @@ -18,6 +18,13 @@ timeoutRef = setTimeout(loadIfDueAndReschedule, refreshMillis()); }; + let onError = function(e) { + console.log("owmweather error:", e); + loading = false; + 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) let weather = require("Storage").readJSON('weather.json') || {}; @@ -30,7 +37,7 @@ if (!MillisUntilDue || MillisUntilDue <= 0) { if (!loading) { loading = true; - require("owmweather").pull(onCompleted); + require("owmweather").pull(onCompleted, onError); } } else { // called to early, reschedule diff --git a/apps/owmweather/lib.js b/apps/owmweather/lib.js index baa9555d03..2f6af5f7b6 100644 --- a/apps/owmweather/lib.js +++ b/apps/owmweather/lib.js @@ -27,13 +27,12 @@ function parseWeather(response) { json.weather = weather; require("Storage").writeJSON('weather.json', json); if (require("Storage").read("weather")!==undefined) require("weather").emit("update", json.weather); - return undefined; } else { - return /*LANG*/"Not OWM data"; + throw /*LANG*/"Not OWM data"; } } -exports.pull = function(completionCallback) { +exports.pull = function(completionCallback, errorCallback) { let location = require("Storage").readJSON("mylocation.json", 1) || { "lat": 51.50, "lon": 0.12, @@ -43,12 +42,12 @@ exports.pull = function(completionCallback) { let uri = "https://api.openweathermap.org/data/2.5/weather?lat=" + location.lat.toFixed(2) + "&lon=" + location.lon.toFixed(2) + "&exclude=hourly,daily&appid=" + settings.apikey; if (Bangle.http){ Bangle.http(uri, {timeout:10000}).then(event => { - let result = parseWeather(event.resp); - if (completionCallback) completionCallback(result); + parseWeather(event.resp); + if (completionCallback) completionCallback(); }).catch((e)=>{ - if (completionCallback) completionCallback(e); + if (errorCallback) errorCallback(e); }); } else { - if (completionCallback) completionCallback(/*LANG*/"No http method found"); + if (errorCallback) errorCallback(/*LANG*/"No http method found"); } }; diff --git a/apps/owmweather/metadata.json b/apps/owmweather/metadata.json index 8dfa4fe9c6..1e514e6bb9 100644 --- a/apps/owmweather/metadata.json +++ b/apps/owmweather/metadata.json @@ -1,7 +1,7 @@ { "id": "owmweather", "name": "OpenWeatherMap weather provider", "shortName":"OWM Weather", - "version": "0.09", + "version": "0.10", "description": "Pulls weather from OpenWeatherMap (OWM) API", "icon": "app.png", "type": "bootloader",