weather module adjustments for rain and snow

This commit is contained in:
vincep5 2019-02-14 13:00:40 -06:00
parent 40101129b5
commit cbe4d2cd7f
9 changed files with 58 additions and 22 deletions

View File

@ -42,6 +42,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Weather forecast now works with openweathermap for both, `/forecast` and `/forecast/daily`, in new weather module. If you use the `/forecast`-weatherEndpoint, the hourly data are converted to daily data, see issues [#1504](https://github.com/MichMich/MagicMirror/issues/1504), [#1513](https://github.com/MichMich/MagicMirror/issues/1513). - Weather forecast now works with openweathermap for both, `/forecast` and `/forecast/daily`, in new weather module. If you use the `/forecast`-weatherEndpoint, the hourly data are converted to daily data, see issues [#1504](https://github.com/MichMich/MagicMirror/issues/1504), [#1513](https://github.com/MichMich/MagicMirror/issues/1513).
- Added fade, fadePoint and maxNumberOfDays properties to the forecast mode [#1516](https://github.com/MichMich/MagicMirror/issues/1516) - Added fade, fadePoint and maxNumberOfDays properties to the forecast mode [#1516](https://github.com/MichMich/MagicMirror/issues/1516)
- Fixed Loading string and decimalSymbol string replace [#1538](https://github.com/MichMich/MagicMirror/issues/1538) - Fixed Loading string and decimalSymbol string replace [#1538](https://github.com/MichMich/MagicMirror/issues/1538)
- Show Snow amounts in new weather module [#1545](https://github.com/MichMich/MagicMirror/issues/1545)
## [2.6.0] - 2019-01-01 ## [2.6.0] - 2019-01-01

View File

@ -70,7 +70,7 @@ The following properties can be configured:
| ---------------------------- | ----------- | ---------------------------- | -----------
| `tableClass` | The class for the forecast table. <br><br> **Default value:** `'small'` | `tableClass` | The class for the forecast table. <br><br> **Default value:** `'small'`
| `colored` | If set to `true`, the min and max temperature are color coded. <br><br> **Default value:** `false` | `colored` | If set to `true`, the min and max temperature are color coded. <br><br> **Default value:** `false`
| `showRainAmount` | Show the amount of rain in the forecast <br><br> **Possible values:** `true` or `false` <br> **Default value:** `true` | `showPrecipitationAmount` | Show the amount of rain/snow in the forecast <br><br> **Possible values:** `true` or `false` <br> **Default value:** `false`
| `fade` | Fade the future events to black. (Gradient) <br><br> **Possible values:** `true` or `false` <br> **Default value:** `true` | `fade` | Fade the future events to black. (Gradient) <br><br> **Possible values:** `true` or `false` <br> **Default value:** `true`
| `fadePoint` | Where to start fade? <br><br> **Possible values:** `0` (top of the list) - `1` (bottom of list) <br> **Default value:** `0.25` | `fadePoint` | Where to start fade? <br><br> **Possible values:** `0` (top of the list) - `1` (bottom of list) <br> **Default value:** `0.25`
| `maxNumberOfDays` | How many days of forecast to return. Specified by config.js <br><br> **Possible values:** `1` - `16` <br> **Default value:** `5` (5 days) <br> This value is optional. By default the weatherforecast module will return 5 days. | `maxNumberOfDays` | How many days of forecast to return. Specified by config.js <br><br> **Possible values:** `1` - `16` <br> **Default value:** `5` (5 days) <br> This value is optional. By default the weatherforecast module will return 5 days.

View File

@ -13,9 +13,9 @@
<td class="align-right min-temp"> <td class="align-right min-temp">
{{ f.minTemperature | roundValue | unit("temperature") }} {{ f.minTemperature | roundValue | unit("temperature") }}
</td> </td>
{% if config.showRainAmount %} {% if config.showPrecipitationAmount %}
<td class="align-right bright rain"> <td class="align-right bright precipitation">
{{ f.rain | unit("rain") }} {{ f.precipitation | unit("precip") }}
</td> </td>
{% endif %} {% endif %}
</tr> </tr>

View File

@ -103,6 +103,8 @@ A convinience function to make requests. It returns a promise.
| weatherType | `string` | Icon name of the weather type. <br> Possible values: [WeatherIcons](https://www.npmjs.com/package/weathericons) | | weatherType | `string` | Icon name of the weather type. <br> Possible values: [WeatherIcons](https://www.npmjs.com/package/weathericons) |
| humidity | `number` | Percentage of humidity | | humidity | `number` | Percentage of humidity |
| rain | `number` | Metric: `millimeters` <br> Imperial: `inches` | | rain | `number` | Metric: `millimeters` <br> Imperial: `inches` |
| snow | `number` | Metric: `millimeters` <br> Imperial: `inches` |
| precipitation | `number` | Metric: `millimeters` <br> Imperial: `inches` |
#### Current weather #### Current weather

View File

@ -8,6 +8,7 @@
* MIT Licensed * MIT Licensed
* *
* This class is a provider for Dark Sky. * This class is a provider for Dark Sky.
* Note that the Dark Sky API does not provide rainfall. Instead it provides snowfall and precipitation probability
*/ */
WeatherProvider.register("darksky", { WeatherProvider.register("darksky", {
// Set the name of the provider. // Set the name of the provider.
@ -81,12 +82,20 @@ WeatherProvider.register("darksky", {
weather.minTemperature = forecast.temperatureMin; weather.minTemperature = forecast.temperatureMin;
weather.maxTemperature = forecast.temperatureMax; weather.maxTemperature = forecast.temperatureMax;
weather.weatherType = this.convertWeatherType(forecast.icon); weather.weatherType = this.convertWeatherType(forecast.icon);
if (this.config.units === "metric" && !isNaN(forecast.precipAccumulation)) { weather.snow = 0;
weather.rain = forecast.precipAccumulation * 10;
} else { // The API will return centimeters if units is 'si' and will return inches for 'us'
weather.rain = forecast.precipAccumulation; // Note that the Dark Sky API does not provide rainfall. Instead it provides snowfall and precipitation probability
if (forecast.hasOwnProperty("precipAccumulation")) {
if (this.config.units === "imperial" && !isNaN(forecast.precipAccumulation)) {
weather.snow = forecast.precipAccumulation;
} else if (!isNaN(forecast.precipAccumulation)) {
weather.snow = forecast.precipAccumulation * 10;
}
} }
weather.precipitation = weather.snow;
days.push(weather); days.push(weather);
} }

View File

@ -106,6 +106,7 @@ WeatherProvider.register("openweathermap", {
var minTemp = []; var minTemp = [];
var maxTemp = []; var maxTemp = [];
var rain = 0; var rain = 0;
var snow = 0;
// variable for date // variable for date
let date = ""; let date = "";
var weather = new WeatherObject(this.config.units); var weather = new WeatherObject(this.config.units);
@ -117,6 +118,8 @@ WeatherProvider.register("openweathermap", {
weather.minTemperature = Math.min.apply(null, minTemp); weather.minTemperature = Math.min.apply(null, minTemp);
weather.maxTemperature = Math.max.apply(null, maxTemp); weather.maxTemperature = Math.max.apply(null, maxTemp);
weather.rain = rain; weather.rain = rain;
weather.snow = snow;
weather.precipitation = weather.rain + weather.snow;
// push weather information to days array // push weather information to days array
days.push(weather); days.push(weather);
// create new weather-object // create new weather-object
@ -125,6 +128,7 @@ WeatherProvider.register("openweathermap", {
minTemp = []; minTemp = [];
maxTemp = []; maxTemp = [];
rain = 0; rain = 0;
snow = 0;
// set new date // set new date
date = moment(forecast.dt, "X").format("YYYY-MM-DD"); date = moment(forecast.dt, "X").format("YYYY-MM-DD");
@ -149,20 +153,27 @@ WeatherProvider.register("openweathermap", {
if (forecast.hasOwnProperty("rain")) { if (forecast.hasOwnProperty("rain")) {
if (this.config.units === "imperial" && !isNaN(forecast.rain["3h"])) { if (this.config.units === "imperial" && !isNaN(forecast.rain["3h"])) {
rain += forecast.rain["3h"] / 25.4; rain += forecast.rain["3h"] / 25.4;
} else if (!isNaN(forecast.rain["3h"])){ } else if (!isNaN(forecast.rain["3h"])) {
rain += forecast.rain["3h"]; rain += forecast.rain["3h"];
} else {
rain += 0;
} }
} else { }
rain += 0;
if (forecast.hasOwnProperty("snow")) {
if (this.config.units === "imperial" && !isNaN(forecast.snow["3h"])) {
snow += forecast.snow["3h"] / 25.4;
} else if (!isNaN(forecast.snow["3h"])) {
snow += forecast.snow["3h"];
}
} }
} }
// last day // last 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);
weather.maxTemperature = Math.max.apply(null, maxTemp); weather.maxTemperature = Math.max.apply(null, maxTemp);
weather.rain = rain; weather.rain = rain;
weather.snow = snow;
weather.precipitation = weather.rain + weather.snow;
// push weather information to days array // push weather information to days array
days.push(weather); days.push(weather);
return days.slice(1); return days.slice(1);
@ -182,20 +193,31 @@ WeatherProvider.register("openweathermap", {
weather.minTemperature = forecast.temp.min; weather.minTemperature = forecast.temp.min;
weather.maxTemperature = forecast.temp.max; weather.maxTemperature = forecast.temp.max;
weather.weatherType = this.convertWeatherType(forecast.weather[0].icon); weather.weatherType = this.convertWeatherType(forecast.weather[0].icon);
weather.rain = 0;
weather.snow = 0;
// forecast.rain not available if amount is zero // forecast.rain not available if amount is zero
// The API always returns in millimeters
if (forecast.hasOwnProperty("rain")) { if (forecast.hasOwnProperty("rain")) {
if (this.config.units === "imperial" && !isNaN(forecast.rain)) { if (this.config.units === "imperial" && !isNaN(forecast.rain)) {
weather.rain = forecast.rain / 25.4; weather.rain = forecast.rain / 25.4;
} else if (!isNaN(forecast.rain)){ } else if (!isNaN(forecast.rain)) {
weather.rain = forecast.rain; weather.rain = forecast.rain;
} else {
weather.rain = 0;
} }
} else {
weather.rain = 0;
} }
// forecast.snow not available if amount is zero
// The API always returns in millimeters
if (forecast.hasOwnProperty("snow")) {
if (this.config.units === "imperial" && !isNaN(forecast.snow)) {
weather.snow = forecast.snow / 25.4;
} else if (!isNaN(forecast.snow)) {
weather.snow = forecast.snow;
}
}
weather.precipitation = weather.rain + weather.snow;
days.push(weather); days.push(weather);
} }

View File

@ -31,7 +31,7 @@
padding-right: 0; padding-right: 0;
} }
.weather .rain { .weather .precipitation {
padding-left: 20px; padding-left: 20px;
padding-right: 0; padding-right: 0;
} }

View File

@ -49,7 +49,7 @@ Module.register("weather",{
tableClass: "small", tableClass: "small",
onlyTemp: false, onlyTemp: false,
showRainAmount: true, showPrecipitationAmount: false,
colored: false, colored: false,
showFeelsLike: true showFeelsLike: true
}, },
@ -200,8 +200,8 @@ Module.register("weather",{
value += "K"; value += "K";
} }
} }
} else if (type === "rain") { } else if (type === "precip") {
if (isNaN(value) || value === 0) { if (isNaN(value) || value === 0 || value.toFixed(2) === "0.00") {
value = ""; value = "";
} else { } else {
value = `${value.toFixed(2)} ${this.config.units === "imperial" ? "in" : "mm"}`; value = `${value.toFixed(2)} ${this.config.units === "imperial" ? "in" : "mm"}`;

View File

@ -26,6 +26,8 @@ class WeatherObject {
this.weatherType = null; this.weatherType = null;
this.humidity = null; this.humidity = null;
this.rain = null; this.rain = null;
this.snow = null;
this.precipitation = null;
} }
cardinalWindDirection() { cardinalWindDirection() {