@@ -30,16 +30,14 @@ WeatherProvider.register("openweathermap", {
3030 fetchCurrentWeather ( ) {
3131 this . fetchData ( this . getUrl ( ) )
3232 . then ( ( data ) => {
33- if ( ! data || ! data . main || typeof data . main . temp === "undefined" ) {
34- // Did not receive usable new data.
35- // Maybe this needs a better check?
36- return ;
33+ if ( this . config . weatherEndpoint === "/onecall" ) {
34+ const weatherData = this . generateWeatherObjectsFromOnecall ( data ) ;
35+ this . setCurrentWeather ( weatherData . current ) ;
36+ this . setFetchedLocation ( `${ data . timezone } ` ) ;
37+ } else {
38+ const currentWeather = this . generateWeatherObjectFromCurrentWeather ( data ) ;
39+ this . setCurrentWeather ( currentWeather ) ;
3740 }
38-
39- this . setFetchedLocation ( `${ data . name } , ${ data . sys . country } ` ) ;
40-
41- const currentWeather = this . generateWeatherObjectFromCurrentWeather ( data ) ;
42- this . setCurrentWeather ( currentWeather ) ;
4341 } )
4442 . catch ( function ( request ) {
4543 Log . error ( "Could not load data ... " , request ) ;
@@ -51,16 +49,15 @@ WeatherProvider.register("openweathermap", {
5149 fetchWeatherForecast ( ) {
5250 this . fetchData ( this . getUrl ( ) )
5351 . then ( ( data ) => {
54- if ( ! data || ! data . list || ! data . list . length ) {
55- // Did not receive usable new data.
56- // Maybe this needs a better check?
57- return ;
52+ if ( this . config . weatherEndpoint === "/onecall" ) {
53+ const weatherData = this . generateWeatherObjectsFromOnecall ( data ) ;
54+ this . setWeatherForecast ( weatherData . days ) ;
55+ this . setFetchedLocation ( `${ data . timezone } ` ) ;
56+ } else {
57+ const forecast = this . generateWeatherObjectsFromForecast ( data . list ) ;
58+ this . setWeatherForecast ( forecast ) ;
59+ this . setFetchedLocation ( `${ data . city . name } , ${ data . city . country } ` ) ;
5860 }
59-
60- this . setFetchedLocation ( `${ data . city . name } , ${ data . city . country } ` ) ;
61-
62- const forecast = this . generateWeatherObjectsFromForecast ( data . list ) ;
63- this . setWeatherForecast ( forecast ) ;
6461 } )
6562 . catch ( function ( request ) {
6663 Log . error ( "Could not load data ... " , request ) ;
0 commit comments