mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 19:53:36 +00:00
Add common method for updating suntimes
This commit is contained in:
parent
e40ddd4b69
commit
8949aa3bec
@ -116,9 +116,7 @@ WeatherProvider.register("ukmetoffice", {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// determine the sunrise/sunset times - not supplied in UK Met Office data
|
// determine the sunrise/sunset times - not supplied in UK Met Office data
|
||||||
let times = this.calcAstroData(location);
|
currentWeather.updateSunTime(location.lat, location.lon);
|
||||||
currentWeather.sunrise = times[0];
|
|
||||||
currentWeather.sunset = times[1];
|
|
||||||
|
|
||||||
return currentWeather;
|
return currentWeather;
|
||||||
},
|
},
|
||||||
@ -154,20 +152,6 @@ WeatherProvider.register("ukmetoffice", {
|
|||||||
return days;
|
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.
|
* Convert the Met Office icons to a more usable name.
|
||||||
*/
|
*/
|
||||||
|
@ -167,9 +167,7 @@ WeatherProvider.register("weathergov", {
|
|||||||
currentWeather.weatherType = this.convertWeatherType(currentWeatherData.textDescription, isDaytime);
|
currentWeather.weatherType = this.convertWeatherType(currentWeatherData.textDescription, isDaytime);
|
||||||
|
|
||||||
// determine the sunrise/sunset times - not supplied in weather.gov data
|
// determine the sunrise/sunset times - not supplied in weather.gov data
|
||||||
let times = this.calcAstroData(this.config.lat, this.config.lon);
|
currentWeather.updateSunTime(this.config.lat, this.config.lon);
|
||||||
currentWeather.sunrise = times[0];
|
|
||||||
currentWeather.sunset = times[1];
|
|
||||||
|
|
||||||
return currentWeather;
|
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.
|
* Convert the icons to a more usable name.
|
||||||
*/
|
*/
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
/* global SunCalc */
|
||||||
|
|
||||||
/* Magic Mirror
|
/* Magic Mirror
|
||||||
* Module: Weather
|
* Module: Weather
|
||||||
*
|
*
|
||||||
@ -113,4 +115,16 @@ class WeatherObject {
|
|||||||
|
|
||||||
return this.tempUnits === "imperial" ? feelsLike : ((feelsLike - 32) * 5) / 9;
|
return this.tempUnits === "imperial" ? feelsLike : ((feelsLike - 32) * 5) / 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the sunrise / sunset time depending on the location
|
||||||
|
*
|
||||||
|
* @param {number} lat latitude
|
||||||
|
* @param {number} lon longitude
|
||||||
|
*/
|
||||||
|
updateSunTime(lat, lon) {
|
||||||
|
let times = SunCalc.getTimes(new Date(), lat, lon);
|
||||||
|
this.sunrise = moment(times.sunrise, "X");
|
||||||
|
this.sunset = moment(times.sunset, "X");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user