small improvements

This commit is contained in:
fewieden 2018-12-27 17:13:49 +01:00
parent 63836185d9
commit ebee80d10e
2 changed files with 29 additions and 10 deletions

View File

@ -39,13 +39,15 @@ Module.register("weather",{
apiVersion: "2.5", apiVersion: "2.5",
apiBase: "http://api.openweathermap.org/data/", apiBase: "http://api.openweathermap.org/data/",
weatherEndpoint: "weather", weatherEndpoint: "/weather",
appendLocationNameToHeader: true, appendLocationNameToHeader: true,
calendarClass: "calendar", calendarClass: "calendar",
tableClass: 'small',
onlyTemp: false, onlyTemp: false,
roundTemp: false roundTemp: false,
showRainAmount: true
}, },
// Module properties. // Module properties.
@ -70,8 +72,18 @@ Module.register("weather",{
return scripts return scripts
}, },
// Override getHeader method.
getHeader: function() {
if (this.config.appendLocationNameToHeader && this.weatherProvider) {
return this.data.header + " " + this.weatherProvider.fetchedLocation();
}
return this.data.header;
},
// Start the weather module. // Start the weather module.
start: function () { start: function () {
moment.locale(this.config.lang);
// Initialize the weather provider. // Initialize the weather provider.
this.weatherProvider = WeatherProvider.initialize(this.config.weatherProvider, this); this.weatherProvider = WeatherProvider.initialize(this.config.weatherProvider, this);
@ -87,11 +99,6 @@ Module.register("weather",{
// Override notification handler. // Override notification handler.
notificationReceived: function(notification, payload, sender) { notificationReceived: function(notification, payload, sender) {
if (notification === "DOM_OBJECTS_CREATED") {
if (this.config.appendLocationNameToHeader) {
this.hide(0, {lockString: this.identifier});
}
}
if (notification === "CALENDAR_EVENTS") { if (notification === "CALENDAR_EVENTS") {
var senderClasses = sender.data.classes.toLowerCase().split(" "); var senderClasses = sender.data.classes.toLowerCase().split(" ");
if (senderClasses.indexOf(this.config.calendarClass.toLowerCase()) !== -1) { if (senderClasses.indexOf(this.config.calendarClass.toLowerCase()) !== -1) {
@ -139,7 +146,7 @@ Module.register("weather",{
updateAvailable: function() { updateAvailable: function() {
Log.log("New weather information available."); Log.log("New weather information available.");
this.updateDom(300); this.updateDom(300);
this.scheduleUpdate(5000); this.scheduleUpdate(60000);
}, },
scheduleUpdate: function(delay = null) { scheduleUpdate: function(delay = null) {
@ -160,7 +167,7 @@ Module.register("weather",{
roundValue: function(temperature) { roundValue: function(temperature) {
var decimals = this.config.roundTemp ? 0 : 1; var decimals = this.config.roundTemp ? 0 : 1;
return parseFloat(temperature).toFixed(decimals); return parseFloat(temperature).toFixed(decimals);
} },
addFilters() { addFilters() {
this.nunjucksEnvironment().addFilter("formatTime", function(date) { this.nunjucksEnvironment().addFilter("formatTime", function(date) {
@ -201,5 +208,17 @@ Module.register("weather",{
this.nunjucksEnvironment().addFilter("roundValue", function(value) { this.nunjucksEnvironment().addFilter("roundValue", function(value) {
return this.roundValue(value); return this.roundValue(value);
}.bind(this)); }.bind(this));
this.nunjucksEnvironment().addFilter("formatRain", function(value) {
if (isNaN(value)) {
return "";
}
if(this.config.units === "imperial") {
return (parseFloat(value) / 25.4).toFixed(2) + " in";
} else {
return parseFloat(value).toFixed(1) + " mm";
}
}.bind(this));
} }
}); });

View File

@ -27,7 +27,7 @@ class WeatherObject {
} }
cardinalWindDirection () { cardinalWindDirection () {
if (this.windDirection>11.25 && this.windDirection<=33.75){ if (this.windDirection > 11.25 && this.windDirection <= 33.75){
return "NNE"; return "NNE";
} else if (this.windDirection > 33.75 && this.windDirection <= 56.25) { } else if (this.windDirection > 33.75 && this.windDirection <= 56.25) {
return "NE"; return "NE";