File tree Expand file tree Collapse file tree 4 files changed +17
-10
lines changed Expand file tree Collapse file tree 4 files changed +17
-10
lines changed Original file line number Diff line number Diff line change 660.06: Fix One Call API 3.0 not returning city names, which are required by the weather app
770.07: Update weather after reconnecting bluetooth if update is due, refactor code
880.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
Original file line number Diff line number Diff line change 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' ) || { } ;
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
Original file line number Diff line number Diff 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} ;
Original file line number Diff line number Diff line change 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" ,
You can’t perform that action at this time.
0 commit comments