Add common method for updating suntimes

This commit is contained in:
rejas
2021-08-31 21:41:27 +02:00
parent e40ddd4b69
commit 8949aa3bec
3 changed files with 16 additions and 34 deletions

View File

@@ -116,9 +116,7 @@ WeatherProvider.register("ukmetoffice", {
}
// determine the sunrise/sunset times - not supplied in UK Met Office data
let times = this.calcAstroData(location);
currentWeather.sunrise = times[0];
currentWeather.sunset = times[1];
currentWeather.updateSunTime(location.lat, location.lon);
return currentWeather;
},
@@ -154,20 +152,6 @@ WeatherProvider.register("ukmetoffice", {
return days;
},
/*
* calculate the astronomical data
*/
calcAstroData(location) {
const sunTimes = [];
// determine the sunrise/sunset times
let times = SunCalc.getTimes(new Date(), location.lat, location.lon);
sunTimes.push(moment(times.sunrise, "X"));
sunTimes.push(moment(times.sunset, "X"));
return sunTimes;
},
/*
* Convert the Met Office icons to a more usable name.
*/

View File

@@ -167,9 +167,7 @@ WeatherProvider.register("weathergov", {
currentWeather.weatherType = this.convertWeatherType(currentWeatherData.textDescription, 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];
currentWeather.updateSunTime(this.config.lat, this.config.lon);
return currentWeather;
},
@@ -272,20 +270,6 @@ WeatherProvider.register("weathergov", {
}
},
/*
* 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.
*/