Merge pull request #243 from roxasvalor/v2-beta

Add optional wind direction in currentweather module
This commit is contained in:
Michael Teeuw 2016-04-25 13:27:59 +02:00
commit 38796a0d40
2 changed files with 55 additions and 2 deletions

View File

@ -90,6 +90,13 @@ The following properties can be configured:
<br><b>Default value:</b> <code>false</code> <br><b>Default value:</b> <code>false</code>
</td> </td>
</tr> </tr>
<tr>
<td><code>showWindDirection</code></td>
<td>Show the wind direction next to the wind speed.<br>
<br><b>Possible values:</b> <code>true</code> or <code>false</code>
<br><b>Default value:</b> <code>false</code>
</td>
</tr>
<tr> <tr>
<td><code>lang</code></td> <td><code>lang</code></td>
<td>The language of the days.<br> <td>The language of the days.<br>

View File

@ -19,6 +19,7 @@ Module.register("currentweather",{
timeFormat: config.timeFormat, timeFormat: config.timeFormat,
showPeriod: true, showPeriod: true,
showPeriodUpper: false, showPeriodUpper: false,
showWindDirection: false,
lang: config.language, lang: config.language,
initialLoadDelay: 0, // 0 seconds delay initialLoadDelay: 0, // 0 seconds delay
@ -68,6 +69,7 @@ Module.register("currentweather",{
moment.locale(config.language); moment.locale(config.language);
this.windSpeed = null; this.windSpeed = null;
this.windDirection = null;
this.sunriseSunsetTime = null; this.sunriseSunsetTime = null;
this.sunriseSunsetIcon = null; this.sunriseSunsetIcon = null;
this.temperature = null; this.temperature = null;
@ -108,11 +110,16 @@ Module.register("currentweather",{
var windIcon = document.createElement("span"); var windIcon = document.createElement("span");
windIcon.className = "wi wi-strong-wind dimmed"; windIcon.className = "wi wi-strong-wind dimmed";
small.appendChild(windIcon); small.appendChild(windIcon);
var windSpeed = document.createElement("span"); var windSpeed = document.createElement("span");
windSpeed.innerHTML = " " + this.windSpeed; windSpeed.innerHTML = " " + this.windSpeed;
small.appendChild(windSpeed); small.appendChild(windSpeed);
if (this.config.showWindDirection) {
var windDirection = document.createElement("span");
windDirection.innerHTML = " " + this.windDirection;
small.appendChild(windDirection);
}
var spacer = document.createElement("span"); var spacer = document.createElement("span");
spacer.innerHTML = "&nbsp;"; spacer.innerHTML = "&nbsp;";
small.appendChild(spacer); small.appendChild(spacer);
@ -198,6 +205,7 @@ Module.register("currentweather",{
processWeather: function(data) { processWeather: function(data) {
this.temperature = this.roundValue(data.main.temp); this.temperature = this.roundValue(data.main.temp);
this.windSpeed = this.ms2Beaufort(this.roundValue(data.wind.speed)); this.windSpeed = this.ms2Beaufort(this.roundValue(data.wind.speed));
this.windDirection = this.deg2Cardinal(data.wind.deg);
this.weatherType = this.config.iconTable[data.weather[0].icon]; this.weatherType = this.config.iconTable[data.weather[0].icon];
var now = new Date(); var now = new Date();
@ -274,6 +282,44 @@ Module.register("currentweather",{
* *
* return number - Rounded Temperature. * return number - Rounded Temperature.
*/ */
deg2Cardinal: function(deg) {
if (deg>11.25 && deg<33.75){
return "NNE";
}else if (deg>33.75 && deg<56.25){
return "ENE";
}else if (deg>56.25 && deg<78.75){
return "E";
}else if (deg>78.75 && deg<101.25){
return "ESE";
}else if (deg>101.25 && deg<123.75){
return "ESE";
}else if (deg>123.75 && deg<146.25){
return "SE";
}else if (deg>146.25 && deg<168.75){
return "SSE";
}else if (deg>168.75 && deg<191.25){
return "S";
}else if (deg>191.25 && deg<213.75){
return "SSW";
}else if (deg>213.75 && deg<236.25){
return "SW";
}else if (deg>236.25 && deg<258.75){
return "WSW";
}else if (deg>258.75 && deg<281.25){
return "W";
}else if (deg>281.25 && deg<303.75){
return "WNW";
}else if (deg>303.75 && deg<326.25){
return "NW";
}else if (deg>326.25 && deg<348.75){
return "NNW";
}else{
return "N";
}
},
roundValue: function(temperature) { roundValue: function(temperature) {
return parseFloat(temperature).toFixed(1); return parseFloat(temperature).toFixed(1);
} }