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) {
const superResponse = super.getData(_weatherParameters);
const superResponse = super.getData(_weatherParameters, refresh);
const weatherParameters = _weatherParameters ?? this.weatherParameters;
// get sun/moon data

View File

@@ -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;

View File

@@ -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,
},

View File

@@ -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;
}
}

View File

@@ -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) => {