mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-28 12:12:20 +00:00
Merge pull request #1506 from fwitte/fwitte/weather_forecast_daily_openweather
Fix openweather forecast in new weather module, fetch daily data
This commit is contained in:
commit
a5da347177
@ -18,6 +18,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Fixed temperature displays in currentweather and weatherforecast modules [#1503](https://github.com/MichMich/MagicMirror/issues/1503).
|
- Fixed temperature displays in currentweather and weatherforecast modules [#1503](https://github.com/MichMich/MagicMirror/issues/1503).
|
||||||
|
- Weather forecast now works with openweathermap in new weather module. Daily data are displayed, see issue [#1504](https://github.com/MichMich/MagicMirror/issues/1504).
|
||||||
|
|
||||||
## [2.6.0] - 2019-01-01
|
## [2.6.0] - 2019-01-01
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ The following properties can be configured:
|
|||||||
| ---------------------------- | -----------
|
| ---------------------------- | -----------
|
||||||
| `apiVersion` | The OpenWeatherMap API version to use. <br><br> **Default value:** `2.5`
|
| `apiVersion` | The OpenWeatherMap API version to use. <br><br> **Default value:** `2.5`
|
||||||
| `apiBase` | The OpenWeatherMap base URL. <br><br> **Default value:** `'http://api.openweathermap.org/data/'`
|
| `apiBase` | The OpenWeatherMap base URL. <br><br> **Default value:** `'http://api.openweathermap.org/data/'`
|
||||||
| `weatherEndpoint` | The OpenWeatherMap API endPoint. <br><br> **Possible values:** `/weather` or `/forecast/daily` <br> **Default value:** `'/weather'`
|
| `weatherEndpoint` | The OpenWeatherMap API endPoint. <br><br> **Possible values:** `/weather`, `/forecast` or `/forecast/daily` (paying users only) <br> **Default value:** `'/weather'`
|
||||||
| `locationID` | Location ID from [OpenWeatherMap](https://openweathermap.org/find) **This will override anything you put in location.** <br> Leave blank if you want to use location. <br> **Example:** `1234567` <br> **Default value:** `false` <br><br> **Note:** When the `location` and `locationID` are both not set, the location will be based on the information provided by the calendar module. The first upcoming event with location data will be used.
|
| `locationID` | Location ID from [OpenWeatherMap](https://openweathermap.org/find) **This will override anything you put in location.** <br> Leave blank if you want to use location. <br> **Example:** `1234567` <br> **Default value:** `false` <br><br> **Note:** When the `location` and `locationID` are both not set, the location will be based on the information provided by the calendar module. The first upcoming event with location data will be used.
|
||||||
| `location` | The location used for weather information. <br><br> **Example:** `'Amsterdam,Netherlands'` <br> **Default value:** `false` <br><br> **Note:** When the `location` and `locationID` are both not set, the location will be based on the information provided by the calendar module. The first upcoming event with location data will be used.
|
| `location` | The location used for weather information. <br><br> **Example:** `'Amsterdam,Netherlands'` <br> **Default value:** `false` <br><br> **Note:** When the `location` and `locationID` are both not set, the location will be based on the information provided by the calendar module. The first upcoming event with location data will be used.
|
||||||
| `apiKey` | The [OpenWeatherMap](https://home.openweathermap.org) API key, which can be obtained by creating an OpenWeatherMap account. <br><br> This value is **REQUIRED**
|
| `apiKey` | The [OpenWeatherMap](https://home.openweathermap.org) API key, which can be obtained by creating an OpenWeatherMap account. <br><br> This value is **REQUIRED**
|
||||||
|
@ -87,25 +87,64 @@ WeatherProvider.register("openweathermap", {
|
|||||||
* Generate WeatherObjects based on forecast information
|
* Generate WeatherObjects based on forecast information
|
||||||
*/
|
*/
|
||||||
generateWeatherObjectsFromForecast(forecasts) {
|
generateWeatherObjectsFromForecast(forecasts) {
|
||||||
|
// initial variable declaration
|
||||||
const days = [];
|
const days = [];
|
||||||
|
// variables for temperature range and rain
|
||||||
|
var minTemp = [];
|
||||||
|
var maxTemp = [];
|
||||||
|
var rain = 0;
|
||||||
|
// variable for date
|
||||||
|
let date = "";
|
||||||
|
var weather = new WeatherObject(this.config.units);
|
||||||
|
|
||||||
for (const forecast of forecasts) {
|
for (const forecast of forecasts) {
|
||||||
const weather = new WeatherObject(this.config.units);
|
|
||||||
|
|
||||||
weather.date = moment(forecast.dt, "X");
|
if (date === moment(forecast.dt, "X").format("YYYY-MM-DD")) {
|
||||||
weather.minTemperature = forecast.temp.min;
|
// the same day as before
|
||||||
weather.maxTemperature = forecast.temp.max;
|
// add values from forecast to corresponding variables
|
||||||
weather.weatherType = this.convertWeatherType(forecast.weather[0].icon);
|
minTemp.push(forecast.main.temp_min);
|
||||||
if (this.config.units === "imperial" && !isNaN(forecast.rain)) {
|
maxTemp.push(forecast.main.temp_max);
|
||||||
weather.rain = forecast.rain / 25.4
|
if (this.config.units === "imperial" && !isNaN(forecast.rain["3h"])) {
|
||||||
|
rain += forecast.rain["3h"] / 25.4;
|
||||||
} else {
|
} else {
|
||||||
weather.rain = forecast.rain;
|
rain += forecast.rain["3h"];
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// a new day
|
||||||
|
// calculate minimum/maximum temperature, specify rain amount
|
||||||
|
weather.minTemperature = Math.min.apply(null, minTemp);
|
||||||
|
weather.maxTemperature = Math.max.apply(null, maxTemp);
|
||||||
|
weather.rain = rain;
|
||||||
|
// push weather information to days array
|
||||||
days.push(weather);
|
days.push(weather);
|
||||||
|
// create new weather-object
|
||||||
|
weather = new WeatherObject(this.config.units);
|
||||||
|
|
||||||
|
minTemp = [];
|
||||||
|
maxTemp = [];
|
||||||
|
rain *= 0;
|
||||||
|
|
||||||
|
// set new date
|
||||||
|
date = moment(forecast.dt, "X").format("YYYY-MM-DD");
|
||||||
|
|
||||||
|
// specify date
|
||||||
|
weather.date = moment(forecast.dt, "X");
|
||||||
|
|
||||||
|
// select weather type by first forecast value of a day, is this reasonable?
|
||||||
|
weather.weatherType = this.convertWeatherType(forecast.weather[0].icon);
|
||||||
|
|
||||||
|
// add values from first forecast of this day to corresponding variables
|
||||||
|
minTemp.push(forecast.main.temp_min);
|
||||||
|
maxTemp.push(forecast.main.temp_max);
|
||||||
|
if (this.config.units === "imperial" && !isNaN(forecast.rain["3h"])) {
|
||||||
|
rain += forecast.rain["3h"] / 25.4;
|
||||||
|
} else {
|
||||||
|
rain += forecast.rain["3h"];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return days;
|
return days.slice(1);
|
||||||
},
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user