diff --git a/server/scripts/modules/almanac.mjs b/server/scripts/modules/almanac.mjs index de39ace..e8c3e18 100644 --- a/server/scripts/modules/almanac.mjs +++ b/server/scripts/modules/almanac.mjs @@ -22,7 +22,7 @@ class Almanac extends WeatherDisplay { } async getData(_weatherParameters, refresh) { - const superResponse = super.getData(_weatherParameters); + const superResponse = super.getData(_weatherParameters, refresh); const weatherParameters = _weatherParameters ?? this.weatherParameters; // get sun/moon data diff --git a/server/scripts/modules/currentweather.mjs b/server/scripts/modules/currentweather.mjs index eba89e8..1ac6652 100644 --- a/server/scripts/modules/currentweather.mjs +++ b/server/scripts/modules/currentweather.mjs @@ -21,13 +21,12 @@ class CurrentWeather extends WeatherDisplay { this.backgroundImage = loadImg('images/BackGround1_1.png'); } - async getData(_weatherParameters, refresh) { + async getData(weatherParameters, refresh) { // always load the data for use in the lower scroll - const superResult = super.getData(_weatherParameters, refresh); - const weatherParameters = _weatherParameters ?? this.weatherParameters; + const superResult = super.getData(weatherParameters, refresh); // filter for 4-letter observation stations, only those contain sky conditions and thus an icon - const filteredStations = weatherParameters.stations.filter((station) => station?.properties?.stationIdentifier?.length === 4 && !skipStations.includes(station.properties.stationIdentifier.slice(0, 1))); + const filteredStations = this.weatherParameters.stations.filter((station) => station?.properties?.stationIdentifier?.length === 4 && !skipStations.includes(station.properties.stationIdentifier.slice(0, 1))); // Load the observations let observations; diff --git a/server/scripts/modules/extendedforecast.mjs b/server/scripts/modules/extendedforecast.mjs index bd62f50..74ab169 100644 --- a/server/scripts/modules/extendedforecast.mjs +++ b/server/scripts/modules/extendedforecast.mjs @@ -18,14 +18,13 @@ class ExtendedForecast extends WeatherDisplay { this.timing.totalScreens = 2; } - async getData(_weatherParameters, refresh) { - if (!super.getData(_weatherParameters, refresh)) return; - const weatherParameters = _weatherParameters ?? this.weatherParameters; + async getData(weatherParameters, refresh) { + if (!super.getData(weatherParameters, refresh)) return; // request us or si units let forecast; try { - forecast = await json(weatherParameters.forecast, { + forecast = await json(this.weatherParameters.forecast, { data: { units: settings.units.value, }, diff --git a/server/scripts/modules/localforecast.mjs b/server/scripts/modules/localforecast.mjs index 6104fc2..48486b5 100644 --- a/server/scripts/modules/localforecast.mjs +++ b/server/scripts/modules/localforecast.mjs @@ -14,19 +14,21 @@ class LocalForecast extends WeatherDisplay { this.timing.baseDelay = 5000; } - async getData(_weatherParameters, refresh) { - if (!super.getData(_weatherParameters, refresh)) return; - const weatherParameters = _weatherParameters ?? this.weatherParameters; + async getData(weatherParameters, refresh) { + if (!super.getData(weatherParameters, refresh)) return; // get raw data - const rawData = await this.getRawData(weatherParameters); - // check for data - if (!rawData) { + const rawData = await this.getRawData(this.weatherParameters); + // check for data, or if there's old data available + if (!rawData && !this.data) { + // fail for no old or new data this.setStatus(STATUS.failed); return; } + // store the data + this.data = rawData || this.data; // parse raw data - const conditions = parse(rawData); + const conditions = parse(this.data); // read each text this.screenTexts = conditions.map((condition) => { @@ -70,7 +72,6 @@ class LocalForecast extends WeatherDisplay { } catch (error) { console.error(`GetWeatherForecast failed: ${weatherParameters.forecast}`); console.error(error.status, error.responseJSON); - this.setStatus(STATUS.failed); return false; } } diff --git a/server/scripts/modules/utils/fetch.mjs b/server/scripts/modules/utils/fetch.mjs index b30f6d2..bafdd13 100644 --- a/server/scripts/modules/utils/fetch.mjs +++ b/server/scripts/modules/utils/fetch.mjs @@ -73,7 +73,7 @@ const doFetch = (url, params) => new Promise((resolve, reject) => { // out of retries return resolve(response); }) - .catch((error) => reject(error)); + .catch(reject); }); const delay = (time, func, ...args) => new Promise((resolve) => {