Keep trying to refresh data after successful API call

This commit is contained in:
Paulus Schoutsen 2017-05-11 20:30:17 -07:00
parent 28f3a23acc
commit 6d5a911cb5
2 changed files with 18 additions and 7 deletions

View File

@ -127,7 +127,16 @@ Polymer({
apiCalled: function (ev) { apiCalled: function (ev) {
if (ev.detail.success) { if (ev.detail.success) {
this.$.data.refresh(); var tries = 1;
var tryUpdate = function () {
this.$.data.refresh().catch(function () {
tries += 1;
setTimeout(tryUpdate, Math.min(tries, 5) * 1000);
})
}.bind(this);
tryUpdate();
} }
}, },

View File

@ -29,27 +29,29 @@ Polymer({
}, },
refresh: function () { refresh: function () {
this.fetchSupervisorInfo(); return Promise.all([
this.fetchHostInfo(); this.fetchSupervisorInfo(),
this.fetchHassInfo(); this.fetchHostInfo(),
this.fetchHassInfo(),
])
}, },
fetchSupervisorInfo: function () { fetchSupervisorInfo: function () {
this.hass.callApi('get', 'hassio/supervisor/info') return this.hass.callApi('get', 'hassio/supervisor/info')
.then(function (info) { .then(function (info) {
this.supervisor = info.data; this.supervisor = info.data;
}.bind(this)); }.bind(this));
}, },
fetchHostInfo: function () { fetchHostInfo: function () {
this.hass.callApi('get', 'hassio/host/info') return this.hass.callApi('get', 'hassio/host/info')
.then(function (info) { .then(function (info) {
this.host = info.data; this.host = info.data;
}.bind(this)); }.bind(this));
}, },
fetchHassInfo: function () { fetchHassInfo: function () {
this.hass.callApi('get', 'hassio/homeassistant/info') return this.hass.callApi('get', 'hassio/homeassistant/info')
.then(function (info) { .then(function (info) {
this.homeassistant = info.data; this.homeassistant = info.data;
}.bind(this)); }.bind(this));