Adding sunrise/sunset to weathergov

This commit is contained in:
vincep5 2019-06-17 10:20:49 -05:00
parent cd1671830a
commit 818ec33cef

View File

@ -71,9 +71,14 @@ WeatherProvider.register("weathergov", {
currentWeather.temperature = currentWeatherData.temperature; currentWeather.temperature = currentWeatherData.temperature;
currentWeather.windSpeed = currentWeatherData.windSpeed.split(" ", 1); currentWeather.windSpeed = currentWeatherData.windSpeed.split(" ", 1);
currentWeather.windDirection = this.convertDirectiontoDegrees(currentWeatherData.windDirection); currentWeather.windDirection = this.convertWindDirection(currentWeatherData.windDirection);
currentWeather.weatherType = this.convertWeatherType(currentWeatherData.shortForecast, currentWeatherData.isDaytime); currentWeather.weatherType = this.convertWeatherType(currentWeatherData.shortForecast, currentWeatherData.isDaytime);
// determine the sunrise/sunset times - not supplied in weather.gov data
let times = this.calcAstroData(this.config.lat, this.config.lon)
currentWeather.sunrise = times[0];
currentWeather.sunset = times[1];
return currentWeather; return currentWeather;
}, },
@ -136,7 +141,7 @@ WeatherProvider.register("weathergov", {
} }
// last day // last day
// calculate minimum/maximum temperature, specify rain amount // calculate minimum/maximum temperature
weather.minTemperature = Math.min.apply(null, minTemp); weather.minTemperature = Math.min.apply(null, minTemp);
weather.maxTemperature = Math.max.apply(null, maxTemp); weather.maxTemperature = Math.max.apply(null, maxTemp);
@ -145,6 +150,20 @@ WeatherProvider.register("weathergov", {
return days.slice(1); return days.slice(1);
}, },
/*
* Calculate the astronomical data
*/
calcAstroData(lat, lon) {
const sunTimes = [];
// determine the sunrise/sunset times
let times = SunCalc.getTimes(new Date(), lat, lon);
sunTimes.push(moment(times.sunrise, "X"));
sunTimes.push(moment(times.sunset, "X"));
return sunTimes;
},
/* /*
* Convert the icons to a more usable name. * Convert the icons to a more usable name.
*/ */
@ -218,39 +237,26 @@ WeatherProvider.register("weathergov", {
/* /*
Convert the direction into Degrees Convert the direction into Degrees
*/ */
convertDirectiontoDegrees(direction) { convertWindDirection(windDirection) {
if (direction === "NNE"){ const windCardinals = {
return 33.75; "N": 0,
} else if (direction === "NE") { "NNE": 22,
return 56.25; "NE": 45,
} else if (direction === "ENE") { "ENE": 67,
return 78.75; "E": 90,
} else if (direction === "E") { "ESE": 112,
return 101.25; "SE": 135,
} else if (direction === "ESE") { "SSE": 157,
return 123.75; "S": 180,
} else if (direction === "SE") { "SSW": 202,
return 146.25; "SW": 225,
} else if (direction === "SSE") { "WSW": 247,
return 168.75; "W": 270,
} else if (direction === "S") { "WNW": 292,
return 191.25; "NW": 315,
} else if (direction === "SSW") { "NNW": 337
return 213.75; };
} else if (direction === "SW") {
return 236.25; return windCardinals.hasOwnProperty(windDirection) ? windCardinals[windDirection] : null;
} else if (direction === "WSW") {
return 258.75;
} else if (direction === "W") {
return 281.25;
} else if (direction === "WNW") {
return 303.75;
} else if (direction === "NW") {
return 326.25;
} else if (direction === "NNW") {
return 348.75;
} else {
return 0;
}
} }
}); });