From 933e881acf1579965e963215aee5d33ccea99e4c Mon Sep 17 00:00:00 2001 From: dWoolridge Date: Tue, 4 Oct 2022 19:10:44 -0500 Subject: [PATCH 1/2] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9082f6c892..43ccdb2493 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,9 +9,12 @@ This project adheres to [Semantic Versioning](https://semver.org/). _This release is scheduled to be released on 2023-01-01._ +Special thanks to: @rejas, @sdetweil + ### Added - Added test for remoteFile option in compliments module +- Added hourlyWeather functionality to Weather.gov weather provider ### Removed From d35eb1d3c28d93437abafaae17b4cd8a195894ac Mon Sep 17 00:00:00 2001 From: dWoolridge Date: Tue, 4 Oct 2022 19:11:20 -0500 Subject: [PATCH 2/2] Add files via upload --- .../default/weather/providers/weathergov.js | 61 ++++++++++++++++++- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/modules/default/weather/providers/weathergov.js b/modules/default/weather/providers/weathergov.js index 8205992423..42ac20552e 100644 --- a/modules/default/weather/providers/weathergov.js +++ b/modules/default/weather/providers/weathergov.js @@ -57,7 +57,7 @@ WeatherProvider.register("weathergov", { // Overwrite the fetchCurrentWeather method. fetchCurrentWeather() { if (!this.configURLs) { - Log.info("fetch wx waiting on config URLs"); + Log.info("fetchCurrentWeather: fetch wx waiting on config URLs"); return; } this.fetchData(this.stationObsURL) @@ -78,7 +78,7 @@ WeatherProvider.register("weathergov", { // Overwrite the fetchWeatherForecast method. fetchWeatherForecast() { if (!this.configURLs) { - Log.info("fetch wx waiting on config URLs"); + Log.info("fetchWeatherForecast: fetch wx waiting on config URLs"); return; } this.fetchData(this.forecastURL) @@ -96,6 +96,28 @@ WeatherProvider.register("weathergov", { .finally(() => this.updateAvailable()); }, + // Overwrite the fetchWeatherHourly method. + fetchWeatherHourly() { + if (!this.configURLs) { + Log.info("fetchWeatherHourly: fetch wx waiting on config URLs"); + return; + } + this.fetchData(this.forecastHourlyURL) + .then((data) => { + if (!data) { + // Did not receive usable new data. + // Maybe this needs a better check? + return; + } + const hourly = this.generateWeatherObjectsFromHourly(data.properties.periods); + this.setWeatherHourly(hourly); + }) + .catch(function (request) { + Log.error("Could not load data ... ", request); + }) + .finally(() => this.updateAvailable()); + }, + /** Weather.gov Specific Methods - These are not part of the default provider methods */ /* @@ -130,14 +152,49 @@ WeatherProvider.register("weathergov", { .finally(() => { // excellent, let's fetch some actual wx data this.configURLs = true; + // handle 'forecast' config, fall back to 'current' if (config.type === "forecast") { this.fetchWeatherForecast(); + } else if (config.type === "hourly") { + this.fetchWeatherHourly(); } else { this.fetchCurrentWeather(); } }); }, + /* + * Generate a WeatherObject based on hourlyWeatherInformation + * Weather.gov API uses specific units; API does not include choice of units + * ... object needs data in units based on config! + */ + generateWeatherObjectsFromHourly(forecasts) { + const days = []; + + // variable for date + let weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh); + for (const forecast of forecasts) { + weather.date = moment(forecast.startTime.slice(0, 19)); + if (forecast.windSpeed.search(" ") < 0) { + weather.windSpeed = forecast.windSpeed; + } else { + weather.windSpeed = forecast.windSpeed.slice(0, forecast.windSpeed.search(" ")); + } + weather.windDirection = this.convertWindDirection(forecast.windDirection); + weather.temperature = forecast.temperature; + weather.tempUnits = forecast.temperatureUnit; + // use the forecast isDayTime attribute to help build the weatherType label + weather.weatherType = this.convertWeatherType(forecast.shortForecast, forecast.isDaytime); + + days.push(weather); + + weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh); + } + + // push weather information to days array + days.push(weather); + return days; + }, /* * Generate a WeatherObject based on currentWeatherInformation