Skip to content

Commit

Permalink
https://github.com/baerengraben/ioBroker.swiss-weather-api/issues/41
Browse files Browse the repository at this point in the history
  • Loading branch information
baerengraben authored and baerengraben committed May 23, 2021
1 parent cc038cd commit 969a7de
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function getTimeFormattet(actualDate) {
return hour + ":" + min + ":" + sec;
}

function getToken(self){
function getToken(self,myCallback){
self.log.debug('getting Token...');

//Convert ConsumerKey and ConsumerSecret to base64
Expand Down Expand Up @@ -103,6 +103,7 @@ function getToken(self){
});
});
req.end();
myCallback(self,getForecast);
}

function getForecast(self){
Expand Down Expand Up @@ -1655,7 +1656,7 @@ function getForecast(self){
req.end();
}

function getGeolocationId(self, getForecastCallback) {
function getGeolocationId(self,myCallback) {
self.log.debug("Getting GeolocationId....");
//Options for getting current Geolocation id
var options_geolocationId = {
Expand Down Expand Up @@ -1718,7 +1719,7 @@ function getGeolocationId(self, getForecastCallback) {
});
});
req.end();
getForecastCallback(self);
myCallback(self);
}

function doIt(self) {
Expand All @@ -1736,15 +1737,13 @@ function doIt(self) {
self.log.debug('Successfull DNS resolve for api.srgssr.ch: ' + JSON.stringify(addresses));
self.setState('info.connection', true, true);

//get Token
getToken(self);
// Check if there is already a geolocationId, if not => Get one
if (geolocationId) {
self.log.debug("geolocationId is available, move forwared to get forcasts...");
getForecast(self);
getToken(self,getForecast);
} else {
self.log.debug("There is no geolocationId, so getting one...");
getGeolocationId(self, getForecast);
self.log.debug("There is no geolocationId, so getting one before calling forecasts...");
getToken(self,getGeolocationId);
}
setTimeout(doIt, pollInterval, self);
}
Expand Down

0 comments on commit 969a7de

Please sign in to comment.