From 0904af2ad2eb35dd5e0c568a141d0763bef6eb7a Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 15 Dec 2017 23:22:22 -0800 Subject: [PATCH] Refresh account status while connecting (#727) * Refresh account status while connecting * Lint --- .../config/cloud/ha-config-cloud-account.html | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/panels/config/cloud/ha-config-cloud-account.html b/panels/config/cloud/ha-config-cloud-account.html index f8ab629b15..5411d8862d 100644 --- a/panels/config/cloud/ha-config-cloud-account.html +++ b/panels/config/cloud/ha-config-cloud-account.html @@ -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);