Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you :-)


### Added

- Added test for remoteFile option in compliments module
- Added hourlyWeather functionality to Weather.gov weather provider

### Removed

Expand Down
61 changes: 59 additions & 2 deletions modules/default/weather/providers/weathergov.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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 */

/*
Expand Down Expand Up @@ -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
Expand Down