compliments: Add feature use current weather.

Possibility the use the actual type of currentweather to show the
compliments.
This commit is contained in:
Rodrigo Ramez Norambuena
2016-11-07 20:08:56 -03:00
committed by Rodrigo Ramírez Norambuena
parent df00a1e0a3
commit 70d6d4246d
4 changed files with 88 additions and 4 deletions

View File

@@ -32,6 +32,9 @@ Module.register("compliments",{
fadeSpeed: 4000
},
// Set currentweather from module
currentWeatherType: "",
// Define required scripts.
getScripts: function() {
return ["moment.js"];
@@ -84,14 +87,21 @@ Module.register("compliments",{
*/
complimentArray: function() {
var hour = moment().hour();
var compliments = null;
if (hour >= 3 && hour < 12) {
return this.config.compliments.morning;
compliments = this.config.compliments.morning;
} else if (hour >= 12 && hour < 17) {
return this.config.compliments.afternoon;
compliments = this.config.compliments.afternoon;
} else {
return this.config.compliments.evening;
compliments = this.config.compliments.evening;
}
if ( this.currentWeatherType in this.config.compliments) {
compliments.push.apply(compliments, this.config.compliments[this.currentWeatherType]);
}
return compliments;
},
/* complimentArray()
@@ -116,6 +126,40 @@ Module.register("compliments",{
wrapper.appendChild(compliment);
return wrapper;
}
},
// From data currentweather set weather type
setCurrentWeatherType: function(data) {
var weatherIconTable = {
"01d": "day_sunny",
"02d": "day_cloudy",
"03d": "cloudy",
"04d": "cloudy_windy",
"09d": "showers",
"10d": "rain",
"11d": "thunderstorm",
"13d": "snow",
"50d": "fog",
"01n": "night_clear",
"02n": "night_cloudy",
"03n": "night_cloudy",
"04n": "night_cloudy",
"09n": "night_showers",
"10n": "night_rain",
"11n": "night_thunderstorm",
"13n": "night_snow",
"50n": "night_alt_cloudy_windy"
};
this.currentWeatherType = weatherIconTable[data.weather[0].icon];
},
// Override notification handler.
notificationReceived: function(notification, payload, sender) {
if (notification == "CURRENTWEATHER_DATA") {
this.setCurrentWeatherType(payload.data);
}
},
});