Refresh account status while connecting (#727)

* Refresh account status while connecting

* Lint
This commit is contained in:
Paulus Schoutsen 2017-12-15 23:22:22 -08:00 committed by GitHub
parent aa5ff72710
commit 0904af2ad2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -88,7 +88,10 @@ class HaConfigCloudAccount extends window.hassMixins.EventsMixin(Polymer.Element
static get properties() {
return {
hass: Object,
account: Object,
account: {
type: Object,
observer: '_accountChanged',
},
};
}
@ -99,6 +102,23 @@ class HaConfigCloudAccount extends window.hassMixins.EventsMixin(Polymer.Element
_formatExpiration(date) {
return window.hassUtil.formatDateTime(new Date(date));
}
_accountChanged(newAccount) {
if (newAccount.cloud !== 'connecting') {
if (this._accountUpdater) {
clearTimeout(this._accountUpdater);
this._accountUpdater = null;
}
return;
} else if (this._accountUpdater) {
return;
}
setTimeout(() => {
this._accountUpdater = null;
this.hass.callApi('get', 'cloud/account')
.then(account => this.fire('ha-account-refreshed', { account }));
}, 5000);
}
}
customElements.define(HaConfigCloudAccount.is, HaConfigCloudAccount);