Skip to content

Commit 817e44a

Browse files
authored
Merge pull request #3876 from thinkpoop/master
[owmweather] prevent updating settings.updated when call to OWM fails
2 parents 8240c2a + bd047f3 commit 817e44a

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

apps/owmweather/ChangeLog

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
0.06: Fix One Call API 3.0 not returning city names, which are required by the weather app
77
0.07: Update weather after reconnecting bluetooth if update is due, refactor code
88
0.08: Undo change to One Call API 3.0
9-
0.09: Fix infinite loop when settings.updated is not defined
9+
0.09: Fix infinite loop when settings.updated is not defined
10+
0.10: Fix settings.updated being updated even when OWM call failed

apps/owmweather/boot.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
timeoutRef = setTimeout(loadIfDueAndReschedule, refreshMillis());
1919
};
2020

21+
let onError = function(e) {
22+
console.log("owmweather error:", e);
23+
loading = false;
24+
if (timeoutRef) clearTimeout(timeoutRef);
25+
timeoutRef = setTimeout(loadIfDueAndReschedule, refreshMillis());
26+
};
27+
2128
let loadIfDueAndReschedule = function () {
2229
// also check if the weather.json file has been updated (e.g. force refresh)
2330
let weather = require("Storage").readJSON('weather.json') || {};
@@ -30,7 +37,7 @@
3037
if (!MillisUntilDue || MillisUntilDue <= 0) {
3138
if (!loading) {
3239
loading = true;
33-
require("owmweather").pull(onCompleted);
40+
require("owmweather").pull(onCompleted, onError);
3441
}
3542
} else {
3643
// called to early, reschedule

apps/owmweather/lib.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ function parseWeather(response) {
2727
json.weather = weather;
2828
require("Storage").writeJSON('weather.json', json);
2929
if (require("Storage").read("weather")!==undefined) require("weather").emit("update", json.weather);
30-
return undefined;
3130
} else {
32-
return /*LANG*/"Not OWM data";
31+
throw /*LANG*/"Not OWM data";
3332
}
3433
}
3534

36-
exports.pull = function(completionCallback) {
35+
exports.pull = function(completionCallback, errorCallback) {
3736
let location = require("Storage").readJSON("mylocation.json", 1) || {
3837
"lat": 51.50,
3938
"lon": 0.12,
@@ -43,12 +42,12 @@ exports.pull = function(completionCallback) {
4342
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;
4443
if (Bangle.http){
4544
Bangle.http(uri, {timeout:10000}).then(event => {
46-
let result = parseWeather(event.resp);
47-
if (completionCallback) completionCallback(result);
45+
parseWeather(event.resp);
46+
if (completionCallback) completionCallback();
4847
}).catch((e)=>{
49-
if (completionCallback) completionCallback(e);
48+
if (errorCallback) errorCallback(e);
5049
});
5150
} else {
52-
if (completionCallback) completionCallback(/*LANG*/"No http method found");
51+
if (errorCallback) errorCallback(/*LANG*/"No http method found");
5352
}
5453
};

apps/owmweather/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{ "id": "owmweather",
22
"name": "OpenWeatherMap weather provider",
33
"shortName":"OWM Weather",
4-
"version": "0.09",
4+
"version": "0.10",
55
"description": "Pulls weather from OpenWeatherMap (OWM) API",
66
"icon": "app.png",
77
"type": "bootloader",

0 commit comments

Comments
 (0)