History data not updating (#385)

* History data not updating

Fix history data not updating. History chart data will cache for 3 minutes. To reload, change the period dropdown to another value and change back.

* remove history cache
This commit is contained in:
Boyi C 2017-08-18 23:38:30 +08:00 committed by Paulus Schoutsen
parent 0e687fb243
commit c289f6c925

View File

@ -3,7 +3,6 @@
<script> <script>
(function () { (function () {
var RECENT_THRESHOLD = 60000; // 1 minute var RECENT_THRESHOLD = 60000; // 1 minute
var DATE_CACHE = {};
var RECENT_CACHE = {}; var RECENT_CACHE = {};
function computeHistory(stateHistory) { function computeHistory(stateHistory) {
@ -155,19 +154,17 @@
getDate: function (startTime, endTime) { getDate: function (startTime, endTime) {
var filter = startTime.toISOString() + '?end_time=' + endTime.toISOString(); var filter = startTime.toISOString() + '?end_time=' + endTime.toISOString();
if (!DATE_CACHE[filter]) {
DATE_CACHE[filter] = this.hass.callApi('GET', 'history/period/' + filter).then( var prom = this.hass.callApi('GET', 'history/period/' + filter).then(
function (stateHistory) { function (stateHistory) {
return computeHistory(stateHistory); return computeHistory(stateHistory);
}, },
function () { function () {
DATE_CACHE[filter] = false;
return null; return null;
} }
); );
}
return DATE_CACHE[filter]; return prom;
}, },
}); });
}()); }());