mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 11:50:00 +00:00
feat(weather/smhi): support hourly forecasts
This commit is contained in:
parent
ba128cbae9
commit
4915ad8fc7
@ -21,7 +21,7 @@ WeatherProvider.register("smhi", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements method in interface for fetching current weather
|
* Implements method in interface for fetching current weather.
|
||||||
*/
|
*/
|
||||||
fetchCurrentWeather() {
|
fetchCurrentWeather() {
|
||||||
this.fetchData(this.getURL())
|
this.fetchData(this.getURL())
|
||||||
@ -37,14 +37,13 @@ WeatherProvider.register("smhi", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements method in interface for fetching a forecast.
|
* Implements method in interface for fetching a multi-day forecast.
|
||||||
* Handling hourly forecast would be easy as not grouping by day but it seems really specific for one weather provider for now.
|
|
||||||
*/
|
*/
|
||||||
fetchWeatherForecast() {
|
fetchWeatherForecast() {
|
||||||
this.fetchData(this.getURL())
|
this.fetchData(this.getURL())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
let coordinates = this.resolveCoordinates(data);
|
let coordinates = this.resolveCoordinates(data);
|
||||||
let weatherObjects = this.convertWeatherDataGroupedByDay(data.timeSeries, coordinates);
|
const weatherObjects = this.convertWeatherDataGroupedBy(data.timeSeries, coordinates);
|
||||||
this.setFetchedLocation(`(${coordinates.lat},${coordinates.lon})`);
|
this.setFetchedLocation(`(${coordinates.lat},${coordinates.lon})`);
|
||||||
this.setWeatherForecast(weatherObjects);
|
this.setWeatherForecast(weatherObjects);
|
||||||
})
|
})
|
||||||
@ -52,6 +51,21 @@ WeatherProvider.register("smhi", {
|
|||||||
.finally(() => this.updateAvailable());
|
.finally(() => this.updateAvailable());
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements method in interface for fetching hourly forecasts.
|
||||||
|
*/
|
||||||
|
fetchWeatherHourly() {
|
||||||
|
this.fetchData(this.getURL())
|
||||||
|
.then((data) => {
|
||||||
|
let coordinates = this.resolveCoordinates(data);
|
||||||
|
let weatherObjects = this.convertWeatherDataGroupedBy(data.timeSeries, coordinates, "hour");
|
||||||
|
this.setFetchedLocation(`(${coordinates.lat},${coordinates.lon})`);
|
||||||
|
this.setWeatherHourly(weatherObjects);
|
||||||
|
})
|
||||||
|
.catch((error) => Log.error("Could not load data: " + error.message))
|
||||||
|
.finally(() => this.updateAvailable());
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overrides method for setting config with checks for the precipitationValue being unset or invalid
|
* Overrides method for setting config with checks for the precipitationValue being unset or invalid
|
||||||
*
|
*
|
||||||
@ -149,7 +163,7 @@ WeatherProvider.register("smhi", {
|
|||||||
* @param {object} coordinates Coordinates of the locations of the weather
|
* @param {object} coordinates Coordinates of the locations of the weather
|
||||||
* @returns {WeatherObject[]} Array of weatherobjects
|
* @returns {WeatherObject[]} Array of weatherobjects
|
||||||
*/
|
*/
|
||||||
convertWeatherDataGroupedByDay(allWeatherData, coordinates) {
|
convertWeatherDataGroupedBy(allWeatherData, coordinates, groupBy = "day") {
|
||||||
let currentWeather;
|
let currentWeather;
|
||||||
let result = [];
|
let result = [];
|
||||||
|
|
||||||
@ -157,10 +171,11 @@ WeatherProvider.register("smhi", {
|
|||||||
let dayWeatherTypes = [];
|
let dayWeatherTypes = [];
|
||||||
|
|
||||||
for (const weatherObject of allWeatherObjects) {
|
for (const weatherObject of allWeatherObjects) {
|
||||||
//If its the first object or if a day change we need to reset the summary object
|
//If its the first object or if a day/hour change we need to reset the summary object
|
||||||
if (!currentWeather || !currentWeather.date.isSame(weatherObject.date, "day")) {
|
if (!currentWeather || !currentWeather.date.isSame(weatherObject.date, groupBy)) {
|
||||||
currentWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits);
|
currentWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits);
|
||||||
dayWeatherTypes = [];
|
dayWeatherTypes = [];
|
||||||
|
currentWeather.temperature = weatherObject.temperature;
|
||||||
currentWeather.date = weatherObject.date;
|
currentWeather.date = weatherObject.date;
|
||||||
currentWeather.minTemperature = Infinity;
|
currentWeather.minTemperature = Infinity;
|
||||||
currentWeather.maxTemperature = -Infinity;
|
currentWeather.maxTemperature = -Infinity;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user