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) {
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 () {
this.fetchSupervisorInfo();
this.fetchHostInfo();
this.fetchHassInfo();
return Promise.all([
this.fetchSupervisorInfo(),
this.fetchHostInfo(),
this.fetchHassInfo(),
])
},
fetchSupervisorInfo: function () {
this.hass.callApi('get', 'hassio/supervisor/info')
return this.hass.callApi('get', 'hassio/supervisor/info')
.then(function (info) {
this.supervisor = info.data;
}.bind(this));
},
fetchHostInfo: function () {
this.hass.callApi('get', 'hassio/host/info')
return this.hass.callApi('get', 'hassio/host/info')
.then(function (info) {
this.host = info.data;
}.bind(this));
},
fetchHassInfo: function () {
this.hass.callApi('get', 'hassio/homeassistant/info')
return this.hass.callApi('get', 'hassio/homeassistant/info')
.then(function (info) {
this.homeassistant = info.data;
}.bind(this));