local forecast silent refresh

This commit is contained in:
Matt Walsh
2025-04-02 20:52:33 -05:00
parent 8fa00b34b4
commit 0baa31a92c
5 changed files with 17 additions and 18 deletions

View File

@@ -22,7 +22,7 @@ class Almanac extends WeatherDisplay {
} }
async getData(_weatherParameters, refresh) { async getData(_weatherParameters, refresh) {
const superResponse = super.getData(_weatherParameters); const superResponse = super.getData(_weatherParameters, refresh);
const weatherParameters = _weatherParameters ?? this.weatherParameters; const weatherParameters = _weatherParameters ?? this.weatherParameters;
// get sun/moon data // get sun/moon data

View File

@@ -21,13 +21,12 @@ class CurrentWeather extends WeatherDisplay {
this.backgroundImage = loadImg('images/BackGround1_1.png'); 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 // always load the data for use in the lower scroll
const superResult = super.getData(_weatherParameters, refresh); const superResult = super.getData(weatherParameters, refresh);
const weatherParameters = _weatherParameters ?? this.weatherParameters;
// filter for 4-letter observation stations, only those contain sky conditions and thus an icon // 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 // Load the observations
let observations; let observations;

View File

@@ -18,14 +18,13 @@ class ExtendedForecast extends WeatherDisplay {
this.timing.totalScreens = 2; this.timing.totalScreens = 2;
} }
async getData(_weatherParameters, refresh) { async getData(weatherParameters, refresh) {
if (!super.getData(_weatherParameters, refresh)) return; if (!super.getData(weatherParameters, refresh)) return;
const weatherParameters = _weatherParameters ?? this.weatherParameters;
// request us or si units // request us or si units
let forecast; let forecast;
try { try {
forecast = await json(weatherParameters.forecast, { forecast = await json(this.weatherParameters.forecast, {
data: { data: {
units: settings.units.value, units: settings.units.value,
}, },

View File

@@ -14,19 +14,21 @@ class LocalForecast extends WeatherDisplay {
this.timing.baseDelay = 5000; this.timing.baseDelay = 5000;
} }
async getData(_weatherParameters, refresh) { async getData(weatherParameters, refresh) {
if (!super.getData(_weatherParameters, refresh)) return; if (!super.getData(weatherParameters, refresh)) return;
const weatherParameters = _weatherParameters ?? this.weatherParameters;
// get raw data // get raw data
const rawData = await this.getRawData(weatherParameters); const rawData = await this.getRawData(this.weatherParameters);
// check for data // check for data, or if there's old data available
if (!rawData) { if (!rawData && !this.data) {
// fail for no old or new data
this.setStatus(STATUS.failed); this.setStatus(STATUS.failed);
return; return;
} }
// store the data
this.data = rawData || this.data;
// parse raw data // parse raw data
const conditions = parse(rawData); const conditions = parse(this.data);
// read each text // read each text
this.screenTexts = conditions.map((condition) => { this.screenTexts = conditions.map((condition) => {
@@ -70,7 +72,6 @@ class LocalForecast extends WeatherDisplay {
} catch (error) { } catch (error) {
console.error(`GetWeatherForecast failed: ${weatherParameters.forecast}`); console.error(`GetWeatherForecast failed: ${weatherParameters.forecast}`);
console.error(error.status, error.responseJSON); console.error(error.status, error.responseJSON);
this.setStatus(STATUS.failed);
return false; return false;
} }
} }

View File

@@ -73,7 +73,7 @@ const doFetch = (url, params) => new Promise((resolve, reject) => {
// out of retries // out of retries
return resolve(response); return resolve(response);
}) })
.catch((error) => reject(error)); .catch(reject);
}); });
const delay = (time, func, ...args) => new Promise((resolve) => { const delay = (time, func, ...args) => new Promise((resolve) => {