Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional wind direction in currentweather module #243

Merged
merged 9 commits into from
Apr 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions modules/default/currentweather/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ The following properties can be configured:
<br><b>Default value:</b> <code>false</code>
</td>
</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>
<td><code>lang</code></td>
<td>The language of the days.<br>
Expand Down
50 changes: 48 additions & 2 deletions modules/default/currentweather/currentweather.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Module.register("currentweather",{
timeFormat: config.timeFormat,
showPeriod: true,
showPeriodUpper: false,
showWindDirection: false,
lang: config.language,

initialLoadDelay: 0, // 0 seconds delay
Expand Down Expand Up @@ -68,6 +69,7 @@ Module.register("currentweather",{
moment.locale(config.language);

this.windSpeed = null;
this.windDirection = null;
this.sunriseSunsetTime = null;
this.sunriseSunsetIcon = null;
this.temperature = null;
Expand Down Expand Up @@ -108,11 +110,16 @@ Module.register("currentweather",{
var windIcon = document.createElement("span");
windIcon.className = "wi wi-strong-wind dimmed";
small.appendChild(windIcon);

var windSpeed = document.createElement("span");
windSpeed.innerHTML = " " + this.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");
spacer.innerHTML = "&nbsp;";
small.appendChild(spacer);
Expand Down Expand Up @@ -198,6 +205,7 @@ Module.register("currentweather",{
processWeather: function(data) {
this.temperature = this.roundValue(data.main.temp);
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];

var now = new Date();
Expand Down Expand Up @@ -274,6 +282,44 @@ Module.register("currentweather",{
*
* 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) {
return parseFloat(temperature).toFixed(1);
}
Expand Down