From 32d0e8bf1d9ff23f3c189d83fab5468a4cb505fa Mon Sep 17 00:00:00 2001 From: Ian Richardson Date: Tue, 19 Feb 2019 00:16:18 -0600 Subject: [PATCH] less broken thermostat-card (#2793) * Update hui-thermostat-card.ts * made light and thermo more consistent --- src/panels/lovelace/cards/hui-light-card.ts | 1 + src/panels/lovelace/cards/hui-thermostat-card.ts | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/panels/lovelace/cards/hui-light-card.ts b/src/panels/lovelace/cards/hui-light-card.ts index 7e30776ef1..fa5bee5536 100644 --- a/src/panels/lovelace/cards/hui-light-card.ts +++ b/src/panels/lovelace/cards/hui-light-card.ts @@ -135,6 +135,7 @@ export class HuiLightCard extends LitElement implements LovelaceCard { const stateObj = this.hass!.states[this._config!.entity] as LightEntity; if (!stateObj) { + // Card will require refresh to work again return; } diff --git a/src/panels/lovelace/cards/hui-thermostat-card.ts b/src/panels/lovelace/cards/hui-thermostat-card.ts index 21c5d70614..071f324306 100644 --- a/src/panels/lovelace/cards/hui-thermostat-card.ts +++ b/src/panels/lovelace/cards/hui-thermostat-card.ts @@ -213,6 +213,7 @@ export class HuiThermostatCard extends LitElement implements LovelaceCard { private get _stepSize(): number { const stateObj = this.hass!.states[this._config!.entity]; + if (stateObj.attributes.target_temp_step) { return stateObj.attributes.target_temp_step; } @@ -220,6 +221,13 @@ export class HuiThermostatCard extends LitElement implements LovelaceCard { } private async _initialLoad(): Promise { + const stateObj = this.hass!.states[this._config!.entity] as ClimateEntity; + + if (!stateObj) { + // Card will require refresh to work again + return; + } + this._loaded = true; await this.updateComplete; @@ -233,15 +241,13 @@ export class HuiThermostatCard extends LitElement implements LovelaceCard { (this.shadowRoot!.querySelector( "#thermostat" - )! as HTMLElement).style.height = radius * 2 + "px"; + ) as HTMLElement)!.style.height = radius * 2 + "px"; const loaded = await loadRoundslider(); this._roundSliderStyle = loaded.roundSliderStyle; this._jQuery = loaded.jQuery; - const stateObj = this.hass!.states[this._config!.entity] as ClimateEntity; - const _sliderType = stateObj.attributes.target_temp_low && stateObj.attributes.target_temp_high