ha-frontend/panels/logbook/ha-logbook-data.html

71 lines
1.4 KiB
HTML

<link rel="import" href="../../bower_components/polymer/polymer.html">
<script>
(function () {
var DATE_CACHE = {};
Polymer({
is: 'ha-logbook-data',
properties: {
hass: {
type: Object,
observer: 'hassChanged',
},
filterDate: {
type: String,
observer: 'filterDateChanged',
},
isLoading: {
type: Boolean,
value: true,
readOnly: true,
notify: true,
},
entries: {
type: Object,
value: null,
readOnly: true,
notify: true,
},
},
hassChanged: function (newHass, oldHass) {
if (!oldHass && this.filterDate) {
this.filterDateChanged(this.filterDate);
}
},
filterDateChanged: function (filterDate) {
if (!this.hass) return;
this._setIsLoading(true);
this.getDate(filterDate).then(function (logbookEntries) {
this._setEntries(logbookEntries);
this._setIsLoading(false);
}.bind(this));
},
getDate: function (date) {
if (!DATE_CACHE[date]) {
DATE_CACHE[date] = this.hass.callApi('GET', 'logbook/' + date).then(
function (logbookEntries) {
return logbookEntries;
},
function () {
DATE_CACHE[date] = false;
return null;
}
);
}
return DATE_CACHE[date];
},
});
}());
</script>