From dac15405fa567e87a8ac624a540c9cc056319445 Mon Sep 17 00:00:00 2001 From: mrkmntal Date: Thu, 16 Apr 2026 21:31:53 -0400 Subject: [PATCH] fix current conditions weather.gov gaps --- server/scripts/modules/currentweather.mjs | 24 ++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/server/scripts/modules/currentweather.mjs b/server/scripts/modules/currentweather.mjs index eac88e4..a37315c 100644 --- a/server/scripts/modules/currentweather.mjs +++ b/server/scripts/modules/currentweather.mjs @@ -63,7 +63,7 @@ class CurrentWeather extends WeatherDisplay { dewpoint: this.data.DewPoint + String.fromCharCode(176), ceiling: this.data.Ceiling === 0 ? 'Unlimited' : `${this.data.Ceiling}${this.data.CeilingUnit}`, visibility: `${this.data.Visibility}${this.data.VisibilityUnit}`, - pressure: `${this.data.Pressure} ${this.data.PressureDirection}`, + pressure: this.data.PressureDirection ? `${this.data.Pressure} ${this.data.PressureDirection}` : this.data.Pressure, icon: { type: 'img', src: this.data.Icon }, }; @@ -121,10 +121,15 @@ const getCurrentWeatherByHourFromTime = (data) => { return currDiff < prevDiff ? curr : prev; }, availableTimes[0]); - const diff = (closestTime.pressure_msl ?? 0) - (previousHour.pressure_msl ?? 0); - let pressureTrend = 'Steady'; - if (diff > 0.5) pressureTrend = 'Rising'; - if (diff < -0.5) pressureTrend = 'Falling'; + const currentPressure = closestTime.pressure_msl; + const previousPressure = previousHour.pressure_msl; + let pressureTrend = ''; + if (Number.isFinite(currentPressure) && Number.isFinite(previousPressure)) { + const diff = currentPressure - previousPressure; + pressureTrend = 'Steady'; + if (diff > 0.5) pressureTrend = 'Rising'; + if (diff < -0.5) pressureTrend = 'Falling'; + } closestTime.pressureTrend = pressureTrend; closestTime.uv_index_max = data.forecast[currentDateKey]?.uv_index_max ?? closestTime.uv_index ?? 0; return closestTime; @@ -144,6 +149,7 @@ const parseData = async (weatherParameters) => { const visibilityConverter = distanceKilometers(); const ceilingMeters = Math.max(0, ((observation.temperature ?? 0) - (observation.dewPoint ?? 0)) * 68); const pressureValue = observation.pressure ?? currentForecast.pressure_msl ?? null; + const resolvedWindGust = observation.windGust ?? currentForecast.wind_gusts_10m ?? 0; return { city: weatherParameters.city, timeZone: weatherParameters.timeZone, @@ -158,17 +164,17 @@ const parseData = async (weatherParameters) => { WindSpeedRaw: observation.windSpeed, WindDirection: directionToNSEW(observation.windDirection ?? 0), Pressure: pressureValue === null ? '-' : pressureConverter(pressureValue * 100), - PressureDirection: currentForecast.pressureTrend ?? 'Steady', + PressureDirection: pressureValue === null ? '' : (currentForecast.pressureTrend ?? ''), Humidity: Math.round(observation.relativeHumidity ?? currentForecast.relative_humidity_2m ?? 0), - WindGust: windConverter(observation.windGust), - WindGustRaw: observation.windGust, + WindGust: windConverter(resolvedWindGust), + WindGustRaw: resolvedWindGust, WindUnit: windConverter.units, TextConditions: Number(observation.weatherCode ?? 0), Icon: getLargeIconFromWmoCodeWithWind( observation.weatherCode, Boolean(observation.isDay), observation.windSpeed, - observation.windGust + resolvedWindGust ), }; }