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

View File

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

View File

@ -85,6 +85,38 @@ Module.register("weather",{
this.scheduleUpdate(0); 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. // Select the template depending on the display type.
getTemplate: function () { getTemplate: function () {
return this.config.type.toLowerCase() + ".njk" return this.config.type.toLowerCase() + ".njk"
@ -95,14 +127,18 @@ Module.register("weather",{
return { return {
config: this.config, config: this.config,
current: this.weatherProvider.currentWeather(), 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? // What to do when the weather provider has new information available?
updateAvailable: function() { updateAvailable: function() {
Log.log("New weather information available."); Log.log("New weather information available.");
this.updateDom(0); this.updateDom(300);
this.scheduleUpdate(5000); this.scheduleUpdate(5000);
}, },
@ -113,18 +149,19 @@ Module.register("weather",{
} }
setTimeout(() => { setTimeout(() => {
switch (this.config.type) { if (this.config.type === "forecast") {
case "forecast":
this.weatherProvider.fetchWeatherForecast(); this.weatherProvider.fetchWeatherForecast();
break; } else {
default:
case "current":
this.weatherProvider.fetchCurrentWeather(); this.weatherProvider.fetchCurrentWeather();
break;
} }
}, nextLoad); }, nextLoad);
}, },
roundValue: function(temperature) {
var decimals = this.config.roundTemp ? 0 : 1;
return parseFloat(temperature).toFixed(decimals);
}
addFilters() { addFilters() {
this.nunjucksEnvironment().addFilter("formatTime", function(date) { this.nunjucksEnvironment().addFilter("formatTime", function(date) {
date = moment(date); date = moment(date);
@ -160,5 +197,9 @@ Module.register("weather",{
return value; return value;
}.bind(this)); }.bind(this));
this.nunjucksEnvironment().addFilter("roundValue", function(value) {
return this.roundValue(value);
}.bind(this));
} }
}); });