Refresh hassio data after API call

This commit is contained in:
Paulus Schoutsen 2017-04-30 22:48:35 -07:00
parent 928be4eed5
commit f255e6c7bf
5 changed files with 39 additions and 4 deletions

View File

@ -12,6 +12,7 @@
</style>
<template>
<hassio-data
id='data'
hass='[[hass]]'
supervisor='{{supervisorInfo}}'
homeassistant='{{hassInfo}}'
@ -100,6 +101,11 @@ Polymer({
listeners: {
'hassio-select-addon': 'addonSelected',
'hass-api-called': 'apiCalled',
},
apiCalled: function (ev) {
this.$.data.refresh();
},
computeIsLoaded: function (supervisorInfo, hostInfo, hassInfo, forceLoading) {

View File

@ -234,6 +234,14 @@ Polymer({
},
},
listeners: {
'hass-api-called': 'apiCalled',
},
apiCalled: function (ev) {
this.addonChanged(this.addon);
},
addonChanged: function (addon) {
if (!this.hass) {
setTimeout(function () { this.addonChanged(addon); }.bind(this), 0);
@ -242,10 +250,9 @@ Polymer({
this.hass.callApi('get', 'hassio/addons/' + addon + '/info')
.then(function (info) {
// Error if addon not installed.
if (info.result !== 'error') {
this.addonState = info.data;
}
this.addonState = info.data;
}.bind(this), function (info) {
this.addonState = null;
}.bind(this));
this.refreshLogs();
},

View File

@ -25,6 +25,10 @@ Polymer({
},
attached: function () {
this.refresh();
},
refresh: function () {
this.fetchSupervisorInfo();
this.fetchHostInfo();
this.fetchHassInfo();

View File

@ -49,14 +49,23 @@ Polymer({
buttonTapped: function () {
this.progress = true;
var el = this;
var eventData = {
method: this.method,
path: this.path,
data: this.data,
};
this.hass.callApi(this.method, this.path, this.data)
.then(function () {
el.progress = false;
el.$.progress.actionSuccess();
eventData.success = true;
}, function () {
el.progress = false;
el.$.progress.actionError();
eventData.success = false;
}).then(function () {
el.fire('hass-api-called', eventData);
});
}
});

View File

@ -42,14 +42,23 @@ Polymer({
buttonTapped: function () {
this.progress = true;
var el = this;
var eventData = {
domain: this.domain,
service: this.service,
serviceData: this.serviceData,
};
this.hass.callService(this.domain, this.service, this.serviceData)
.then(function () {
el.progress = false;
el.$.progress.actionSuccess();
eventData.success = true;
}, function () {
el.progress = false;
el.$.progress.actionError();
eventData.success = false;
}).then(function () {
el.fire('hass-service-called', eventData);
});
}
});