From ea7bf115106d499f423282b8ff1dab46d94d3ec5 Mon Sep 17 00:00:00 2001 From: baerengraben Date: Sat, 8 Jan 2022 10:59:57 +0100 Subject: [PATCH] fixing https://github.com/baerengraben/ioBroker.swiss-weather-api/issues/66 --- main.js | 361 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 181 insertions(+), 180 deletions(-) diff --git a/main.js b/main.js index 83c7d9b..49e667c 100644 --- a/main.js +++ b/main.js @@ -802,194 +802,195 @@ function setCurrentHour(self){ self.log.debug('Updating local current_hour variables...'); self.getState(path + '.0000.DD_DEG', (err, state) => { - if (err){ + if (err) { self.log.error(path + '.0000.DD_DEG' + ':' + 'Error. This should not happen. Error is ' + err.message); + reject("no forecast data is available"); } if (!state || state.val === null) { self.log.debug('tried to update current_hour, but no forecast data is available for ' + path + '.0000.DD_DEG' + '. Try my luck on next hour...'); + reject("no forecast data is available"); } else { // (function(next) { - (function() { - self.log.debug('forecast data is available. ' + path + '.0000.DD_DEG is: ' + state.val + ': So updating current_hour...read correspondenting hour forecast from ' + - 'swiss-weather-api.0.forecast.60minutes.day0.actual_hour and write it to swiss-weather-api.0.forecast.current_hour'); - self.getState(path + '.' + hour + '00.cur_color.background_color', function (err, state) { - if (err){ - self.log.error(path + '.' + hour + '00.cur_color.background_color' + ':' + 'This should not happen. Error is ' + err.message); - } - if ((typeof state !== "undefined") && (state !== null)) { - currentHourVariables.local_background_color = state.val; - } else { - self.log.info(path + '.' + hour + '00.cur_color.background_color' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); - } - }); - self.getState(path + '.' + hour + '00.cur_color.temperature', function (err, state) { - if (err){ - self.log.error(path + '.' + hour + '00.cur_color.temperature' + ':' + 'This should not happen. Error is ' + err.message); - } - if ((typeof state !== "undefined") && (state !== null)) { - currentHourVariables.local_temperature = state.val; - } else { - self.log.info(path + '.' + hour + '00.cur_color.temperature' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); - } - }); - self.getState(path + '.' + hour + '00.cur_color.text_color', function (err, state) { - if (err){ - self.log.error(path + '.' + hour + '00.cur_color.text_color' + ':' + 'This should not happen. Error is ' + err.message); - } - if ((typeof state !== "undefined") && (state !== null)) { - currentHourVariables.local_text_color = state.val; - } else { - self.log.info(path + '.' + hour + '00.cur_color.text_color' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); - } - }); - self.getState(path + '.' + hour + '00.DD_DEG', function (err, state) { - if (err){ - self.log.error(path + '.' + hour + '00.DD_DEG' + ':' + 'This should not happen. Error is ' + err.message); - } - if ((typeof state !== "undefined") && (state !== null)) { - currentHourVariables.local_DD_DEG = state.val; - } else { - self.log.info(path + '.' + hour + '00.DD_DEG' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); - } - }); - self.getState(path + '.' + hour + '00.FF_KMH', function (err, state) { - if (err){ - self.log.error(path + '.' + hour + '00.FF_KMH' + ':' + 'This should not happen. Error is ' + err.message); - } - if ((typeof state !== "undefined") && (state !== null)) { - currentHourVariables.local_FF_KMH = state.val; - } else { - self.log.info(path + '.' + hour + '00.FF_KMH' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); - } - }); - self.getState(path + '.' + hour + '00.FX_KMH', function (err, state) { - if (err){ - self.log.error(path + '.' + hour + '00.FX_KMH' + ':' + 'This should not happen. Error is ' + err.message); - } - if ((typeof state !== "undefined") && (state !== null)) { - currentHourVariables.local_FX_KMH = state.val; - } else { - self.log.info(path + '.' + hour + '00.FX_KMH' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); - } - }); - self.getState(path + '.' + hour + '00.ICON_URL_COLOR', function (err, state) { - if (err){ - self.log.error(path + '.' + hour + '00.ICON_URL_COLOR' + ':' + 'This should not happen. Error is ' + err.message); - } - if ((typeof state !== "undefined") && (state !== null)) { - currentHourVariables.local_ICON_URL_COLOR = state.val; - } else { - self.log.info(path + '.' + hour + '00.ICON_URL_COLOR' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); - } - }); - self.getState(path + '.' + hour + '00.ICON_URL_DARK', function (err, state) { - if (err){ - self.log.error(path + '.' + hour + '00.ICON_URL_DARK' + ':' + 'This should not happen. Error is ' + err.message); - } - if ((typeof state !== "undefined") && (state !== null)) { - currentHourVariables.local_ICON_URL_DARK = state.val; - } else { - self.log.info(path + '.' + hour + '00.ICON_URL_DARK' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); - } - }); - self.getState(path + '.' + hour + '00.ICON_URL_LIGHT', function (err, state) { - if (err){ - self.log.error(path + '.' + hour + '00.ICON_URL_LIGHT' + ':' + 'This should not happen. Error is ' + err.message); - } - if ((typeof state !== "undefined") && (state !== null)) { - currentHourVariables.local_ICON_URL_LIGHT = state.val; - } else { - self.log.info(path + '.' + hour + '00.ICON_URL_LIGHT' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); - } - }); - self.getState(path + '.' + hour + '00.PROBPCP_PERCENT', function (err, state) { - if (err){ - self.log.error(path + '.' + hour + '00.PROBPCP_PERCENT' + ':' + 'This should not happen. Error is ' + err.message); - } - if ((typeof state !== "undefined") && (state !== null)) { - currentHourVariables.local_PROBPCP_PERCENT = state.val; - } else { - self.log.info(path + '.' + hour + '00.PROBPCP_PERCENT' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); - } - }); - self.getState(path + '.' + hour + '00.RRR_MM', function (err, state) { - if (err){ - self.log.error(path + '.' + hour + '00.RRR_MM' + ':' + 'This should not happen. Error is ' + err.message); - } - if ((typeof state !== "undefined") && (state !== null)) { - currentHourVariables.local_RRR_MM = state.val; - } else { - self.log.info(path + '.' + hour + '00.RRR_MM' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); - } - }); - self.getState(path + '.' + hour + '00.SYMBOL_CODE', function (err, state) { - if (err){ - self.log.error(path + '.' + hour + '00.SYMBOL_CODE' + ':' + 'This should not happen. Error is ' + err.message); - } - if ((typeof state !== "undefined") && (state !== null)) { - currentHourVariables.local_SYMBOL_CODE = state.val; - } else { - self.log.info(path + '.' + hour + '00.SYMBOL_CODE' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); - } - }); - self.getState(path + '.' + hour + '00.TTH_C', function (err, state) { - if (err){ - self.log.error(path + '.' + hour + '00.TTH_C' + ':' + 'This should not happen. Error is ' + err.message); - } - if ((typeof state !== "undefined") && (state !== null)) { - currentHourVariables.local_TTH_C = state.val; - } else { - self.log.info(path + '.' + hour + '00.TTH_C' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); - } - }); - self.getState(path + '.' + hour + '00.TTL_C', function (err, state) { - if (err){ - self.log.error(path + '.' + hour + '00.TTL_C' + ':' + 'This should not happen. Error is ' + err.message); - } - if ((typeof state !== "undefined") && (state !== null)) { - currentHourVariables.local_TTL_C = state.val; - } else { - self.log.info(path + '.' + hour + '00.TTL_C' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); - } - }); - self.getState(path + '.' + hour + '00.TTT_C', function (err, state) { - if (err){ - self.log.error(path + '.' + hour + '00.TTT_C' + ':' + 'This should not happen. Error is ' + err.message); - } - if ((typeof state !== "undefined") && (state !== null)) { - currentHourVariables.local_TTT_C = state.val; - } else { - self.log.info(path + '.' + hour + '00.TTT_C' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); - } - }); - self.getState(path + '.' + hour + '00.local_date_time', function (err, state) { - if (err){ - self.log.error(path + '.' + hour + '00.local_date_time' + ':' + 'This should not happen. Error is ' + err.message); - } - if ((typeof state !== "undefined") && (state !== null)) { - currentHourVariables.local_local_date_time = state.val; - } else { - self.log.info(path + '.' + hour + '00.local_date_time' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); - } - }); - self.getState(path + '.' + hour + '00.type', function (err, state) { - if (err){ - self.log.error(path + '.' + hour + '00.type' + ':' + 'This should not happen. Error is ' + err.message); - } - if ((typeof state !== "undefined") && (state !== null)) { - currentHourVariables.local_type = state.val; - } else { - self.log.info(path + '.' + hour + '00.type' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); - } - }); - // next(); - resolve(currentHourVariables); + // (function() { + self.log.debug('forecast data is available. ' + path + '.0000.DD_DEG is: ' + state.val + ': So updating current_hour...read correspondenting hour forecast from ' + + 'swiss-weather-api.0.forecast.60minutes.day0.actual_hour and write it to swiss-weather-api.0.forecast.current_hour'); + self.getState(path + '.' + hour + '00.cur_color.background_color', function (err, state) { + if (err) { + self.log.error(path + '.' + hour + '00.cur_color.background_color' + ':' + 'This should not happen. Error is ' + err.message); + } + if ((typeof state !== "undefined") && (state !== null)) { + currentHourVariables.local_background_color = state.val; + } else { + self.log.info(path + '.' + hour + '00.cur_color.background_color' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); + } + }); + self.getState(path + '.' + hour + '00.cur_color.temperature', function (err, state) { + if (err) { + self.log.error(path + '.' + hour + '00.cur_color.temperature' + ':' + 'This should not happen. Error is ' + err.message); + } + if ((typeof state !== "undefined") && (state !== null)) { + currentHourVariables.local_temperature = state.val; + } else { + self.log.info(path + '.' + hour + '00.cur_color.temperature' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); + } + }); + self.getState(path + '.' + hour + '00.cur_color.text_color', function (err, state) { + if (err) { + self.log.error(path + '.' + hour + '00.cur_color.text_color' + ':' + 'This should not happen. Error is ' + err.message); + } + if ((typeof state !== "undefined") && (state !== null)) { + currentHourVariables.local_text_color = state.val; + } else { + self.log.info(path + '.' + hour + '00.cur_color.text_color' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); + } + }); + self.getState(path + '.' + hour + '00.DD_DEG', function (err, state) { + if (err) { + self.log.error(path + '.' + hour + '00.DD_DEG' + ':' + 'This should not happen. Error is ' + err.message); + } + if ((typeof state !== "undefined") && (state !== null)) { + currentHourVariables.local_DD_DEG = state.val; + } else { + self.log.info(path + '.' + hour + '00.DD_DEG' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); + } + }); + self.getState(path + '.' + hour + '00.FF_KMH', function (err, state) { + if (err) { + self.log.error(path + '.' + hour + '00.FF_KMH' + ':' + 'This should not happen. Error is ' + err.message); + } + if ((typeof state !== "undefined") && (state !== null)) { + currentHourVariables.local_FF_KMH = state.val; + } else { + self.log.info(path + '.' + hour + '00.FF_KMH' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); + } + }); + self.getState(path + '.' + hour + '00.FX_KMH', function (err, state) { + if (err) { + self.log.error(path + '.' + hour + '00.FX_KMH' + ':' + 'This should not happen. Error is ' + err.message); + } + if ((typeof state !== "undefined") && (state !== null)) { + currentHourVariables.local_FX_KMH = state.val; + } else { + self.log.info(path + '.' + hour + '00.FX_KMH' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); + } + }); + self.getState(path + '.' + hour + '00.ICON_URL_COLOR', function (err, state) { + if (err) { + self.log.error(path + '.' + hour + '00.ICON_URL_COLOR' + ':' + 'This should not happen. Error is ' + err.message); + } + if ((typeof state !== "undefined") && (state !== null)) { + currentHourVariables.local_ICON_URL_COLOR = state.val; + } else { + self.log.info(path + '.' + hour + '00.ICON_URL_COLOR' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); + } + }); + self.getState(path + '.' + hour + '00.ICON_URL_DARK', function (err, state) { + if (err) { + self.log.error(path + '.' + hour + '00.ICON_URL_DARK' + ':' + 'This should not happen. Error is ' + err.message); + } + if ((typeof state !== "undefined") && (state !== null)) { + currentHourVariables.local_ICON_URL_DARK = state.val; + } else { + self.log.info(path + '.' + hour + '00.ICON_URL_DARK' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); + } + }); + self.getState(path + '.' + hour + '00.ICON_URL_LIGHT', function (err, state) { + if (err) { + self.log.error(path + '.' + hour + '00.ICON_URL_LIGHT' + ':' + 'This should not happen. Error is ' + err.message); + } + if ((typeof state !== "undefined") && (state !== null)) { + currentHourVariables.local_ICON_URL_LIGHT = state.val; + } else { + self.log.info(path + '.' + hour + '00.ICON_URL_LIGHT' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); + } + }); + self.getState(path + '.' + hour + '00.PROBPCP_PERCENT', function (err, state) { + if (err) { + self.log.error(path + '.' + hour + '00.PROBPCP_PERCENT' + ':' + 'This should not happen. Error is ' + err.message); + } + if ((typeof state !== "undefined") && (state !== null)) { + currentHourVariables.local_PROBPCP_PERCENT = state.val; + } else { + self.log.info(path + '.' + hour + '00.PROBPCP_PERCENT' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); + } + }); + self.getState(path + '.' + hour + '00.RRR_MM', function (err, state) { + if (err) { + self.log.error(path + '.' + hour + '00.RRR_MM' + ':' + 'This should not happen. Error is ' + err.message); + } + if ((typeof state !== "undefined") && (state !== null)) { + currentHourVariables.local_RRR_MM = state.val; + } else { + self.log.info(path + '.' + hour + '00.RRR_MM' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); + } + }); + self.getState(path + '.' + hour + '00.SYMBOL_CODE', function (err, state) { + if (err) { + self.log.error(path + '.' + hour + '00.SYMBOL_CODE' + ':' + 'This should not happen. Error is ' + err.message); + } + if ((typeof state !== "undefined") && (state !== null)) { + currentHourVariables.local_SYMBOL_CODE = state.val; + } else { + self.log.info(path + '.' + hour + '00.SYMBOL_CODE' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); } - // (function() { - // resolve(currentHourVariables); - // }) - ) + }); + self.getState(path + '.' + hour + '00.TTH_C', function (err, state) { + if (err) { + self.log.error(path + '.' + hour + '00.TTH_C' + ':' + 'This should not happen. Error is ' + err.message); + } + if ((typeof state !== "undefined") && (state !== null)) { + currentHourVariables.local_TTH_C = state.val; + } else { + self.log.info(path + '.' + hour + '00.TTH_C' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); + } + }); + self.getState(path + '.' + hour + '00.TTL_C', function (err, state) { + if (err) { + self.log.error(path + '.' + hour + '00.TTL_C' + ':' + 'This should not happen. Error is ' + err.message); + } + if ((typeof state !== "undefined") && (state !== null)) { + currentHourVariables.local_TTL_C = state.val; + } else { + self.log.info(path + '.' + hour + '00.TTL_C' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); + } + }); + self.getState(path + '.' + hour + '00.TTT_C', function (err, state) { + if (err) { + self.log.error(path + '.' + hour + '00.TTT_C' + ':' + 'This should not happen. Error is ' + err.message); + } + if ((typeof state !== "undefined") && (state !== null)) { + currentHourVariables.local_TTT_C = state.val; + } else { + self.log.info(path + '.' + hour + '00.TTT_C' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); + } + }); + self.getState(path + '.' + hour + '00.local_date_time', function (err, state) { + if (err) { + self.log.error(path + '.' + hour + '00.local_date_time' + ':' + 'This should not happen. Error is ' + err.message); + } + if ((typeof state !== "undefined") && (state !== null)) { + currentHourVariables.local_local_date_time = state.val; + } else { + self.log.info(path + '.' + hour + '00.local_date_time' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); + } + }); + self.getState(path + '.' + hour + '00.type', function (err, state) { + if (err) { + self.log.error(path + '.' + hour + '00.type' + ':' + 'This should not happen. Error is ' + err.message); + } + if ((typeof state !== "undefined") && (state !== null)) { + currentHourVariables.local_type = state.val; + } else { + self.log.info(path + '.' + hour + '00.type' + ':' + 'This should not happen. State is undefined or null. So in this run no data is copied for this value'); + } + }); + // next(); + resolve(currentHourVariables); } + // (function() { + // resolve(currentHourVariables); + // }) + // ) }) }) return promise;