indoor data, new filter, small cleanup

This commit is contained in:
fewieden 2018-07-02 15:43:24 +02:00
parent 66ceafd010
commit 0fe79b5288
3 changed files with 56 additions and 13 deletions

View File

@ -36,18 +36,18 @@
<div class="large light">
<span class="wi weathericon wi-{{current.weatherType}}"></span>
<span class="bright">
{{current.temperature | round(0 if config.roundTemp else 1) | unit("temperature")}}
{{current.temperature | roundValue | unit("temperature")}}
</span>
{% if config.showIndoorTemperature and indoor.temperature %}
<span class="fa fa-home"></span>
<span class="bright">
{{indoor.temperature | round(0 if config.roundTemp else 1) | unit("temperature")}}
{{indoor.temperature | roundValue | unit("temperature")}}
</span>
{% endif %}
{% if config.showIndoorHumidity and indoor.humidity %}
<span class="fa fa-tint"></span>
<span class="bright">
{{indoor.humidity | round(0 if config.roundTemp else 1)}}%
{{indoor.humidity | roundValue}}%
</span>
{% endif %}
</div>

View File

@ -6,15 +6,17 @@
<td class="day">{{f.day}}</td>
<td class="bright weather-icon"><span class="wi weathericon {{f.icon}}"></span></td>
<td class="align-right bright max-temp">
{{f.maxTemperature | round(0 if config.roundTemp else 1) | unit("temperature")}}
{{f.maxTemperature | roundValue | unit("temperature")}}
</td>
<td class="align-right min-temp">
{{f.minTemperature | round(0 if config.roundTemp else 1) | unit("temperature")}}
{{f.minTemperature | roundValue | unit("temperature")}}
</td>
</tr>
{% endfor %}
</table>
</div>
{% else %}
{{"LOADING" | translate}}
{% endif %}
<!-- Unclomment the line below to see the contents of the `current` object. -->

View File

@ -85,6 +85,38 @@ Module.register("weather",{
this.scheduleUpdate(0);
},
// Override notification handler.
notificationReceived: function(notification, payload, sender) {
if (notification === "DOM_OBJECTS_CREATED") {
if (this.config.appendLocationNameToHeader) {
this.hide(0, {lockString: this.identifier});
}
}
if (notification === "CALENDAR_EVENTS") {
var senderClasses = sender.data.classes.toLowerCase().split(" ");
if (senderClasses.indexOf(this.config.calendarClass.toLowerCase()) !== -1) {
this.firstEvent = false;
for (var e in payload) {
var event = payload[e];
if (event.location || event.geo) {
this.firstEvent = event;
//Log.log("First upcoming event with location: ", event);
break;
}
}
}
}
if (notification === "INDOOR_TEMPERATURE") {
this.indoorTemperature = this.roundValue(payload);
this.updateDom(300);
}
if (notification === "INDOOR_HUMIDITY") {
this.indoorHumidity = this.roundValue(payload);
this.updateDom(300);
}
},
// Select the template depending on the display type.
getTemplate: function () {
return this.config.type.toLowerCase() + ".njk"
@ -95,14 +127,18 @@ Module.register("weather",{
return {
config: this.config,
current: this.weatherProvider.currentWeather(),
forecast: this.weatherProvider.weatherForecast()
forecast: this.weatherProvider.weatherForecast(),
indoor: {
humidity: this.indoorHumidity,
temperature: this.indoorTemperature
}
}
},
// What to do when the weather provider has new information available?
updateAvailable: function() {
Log.log("New weather information available.");
this.updateDom(0);
this.updateDom(300);
this.scheduleUpdate(5000);
},
@ -113,18 +149,19 @@ Module.register("weather",{
}
setTimeout(() => {
switch (this.config.type) {
case "forecast":
if (this.config.type === "forecast") {
this.weatherProvider.fetchWeatherForecast();
break;
default:
case "current":
} else {
this.weatherProvider.fetchCurrentWeather();
break;
}
}, nextLoad);
},
roundValue: function(temperature) {
var decimals = this.config.roundTemp ? 0 : 1;
return parseFloat(temperature).toFixed(decimals);
}
addFilters() {
this.nunjucksEnvironment().addFilter("formatTime", function(date) {
date = moment(date);
@ -160,5 +197,9 @@ Module.register("weather",{
return value;
}.bind(this));
this.nunjucksEnvironment().addFilter("roundValue", function(value) {
return this.roundValue(value);
}.bind(this));
}
});