mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-28 04:02:12 +00:00
simplified fetchForecastHourly function
This commit is contained in:
parent
409939360f
commit
d6046d2422
@ -112,24 +112,7 @@ WeatherProvider.register("openweathermap", {
|
|||||||
|
|
||||||
for (const forecast of forecasts) {
|
for (const forecast of forecasts) {
|
||||||
|
|
||||||
if (date === moment(forecast.dt, "X").format("YYYY-MM-DD")) {
|
if (date !== moment(forecast.dt, "X").format("YYYY-MM-DD")) {
|
||||||
// the same day as before
|
|
||||||
// add values from forecast to corresponding variables
|
|
||||||
minTemp.push(forecast.main.temp_min);
|
|
||||||
maxTemp.push(forecast.main.temp_max);
|
|
||||||
|
|
||||||
if (forecast.hasOwnProperty("rain")) {
|
|
||||||
if (this.config.units === "imperial" && !isNaN(forecast.rain["3h"])) {
|
|
||||||
rain += forecast.rain["3h"] / 25.4;
|
|
||||||
} else if (!isNaN(forecast.rain["3h"])){
|
|
||||||
rain += forecast.rain["3h"];
|
|
||||||
} else {
|
|
||||||
rain += 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
rain += 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// a new day
|
// a new day
|
||||||
// calculate minimum/maximum temperature, specify rain amount
|
// calculate minimum/maximum temperature, specify rain amount
|
||||||
weather.minTemperature = Math.min.apply(null, minTemp);
|
weather.minTemperature = Math.min.apply(null, minTemp);
|
||||||
@ -153,7 +136,10 @@ WeatherProvider.register("openweathermap", {
|
|||||||
// select weather type by first forecast value of a day, is this reasonable?
|
// select weather type by first forecast value of a day, is this reasonable?
|
||||||
weather.weatherType = this.convertWeatherType(forecast.weather[0].icon);
|
weather.weatherType = this.convertWeatherType(forecast.weather[0].icon);
|
||||||
|
|
||||||
// add values from first forecast of this day to corresponding variables
|
}
|
||||||
|
|
||||||
|
// the same day as before
|
||||||
|
// add values from forecast to corresponding variables
|
||||||
minTemp.push(forecast.main.temp_min);
|
minTemp.push(forecast.main.temp_min);
|
||||||
maxTemp.push(forecast.main.temp_max);
|
maxTemp.push(forecast.main.temp_max);
|
||||||
|
|
||||||
@ -169,7 +155,6 @@ WeatherProvider.register("openweathermap", {
|
|||||||
rain += 0;
|
rain += 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return days.slice(1);
|
return days.slice(1);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user