mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-31 13:07:49 +00:00
Thermostat: check if we are attached before getting clientWidth (#2447)
* We need to be attached to get the cleintWidth * Use isConnected and set _loaded
This commit is contained in:
parent
6d43c9e86a
commit
ebbd308be6
@ -79,6 +79,8 @@ export class HuiThermostatCard extends hassLocalizeLitMixin(LitElement)
|
|||||||
private _roundSliderStyle?: TemplateResult;
|
private _roundSliderStyle?: TemplateResult;
|
||||||
private _jQuery?: any;
|
private _jQuery?: any;
|
||||||
private _broadCard?: boolean;
|
private _broadCard?: boolean;
|
||||||
|
private _loaded?: boolean;
|
||||||
|
private _updated?: boolean;
|
||||||
|
|
||||||
static get properties(): PropertyDeclarations {
|
static get properties(): PropertyDeclarations {
|
||||||
return {
|
return {
|
||||||
@ -101,6 +103,13 @@ export class HuiThermostatCard extends hassLocalizeLitMixin(LitElement)
|
|||||||
this._config = { theme: "default", ...config };
|
this._config = { theme: "default", ...config };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public connectedCallback(): void {
|
||||||
|
super.connectedCallback();
|
||||||
|
if (this._updated && !this._loaded) {
|
||||||
|
this._initialLoad();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
if (!this.hass || !this._config) {
|
if (!this.hass || !this._config) {
|
||||||
return html``;
|
return html``;
|
||||||
@ -157,7 +166,10 @@ export class HuiThermostatCard extends hassLocalizeLitMixin(LitElement)
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected firstUpdated(): void {
|
protected firstUpdated(): void {
|
||||||
this._initialLoad();
|
this._updated = true;
|
||||||
|
if (this.isConnected && !this._loaded) {
|
||||||
|
this._initialLoad();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected updated(changedProps: PropertyValues): void {
|
protected updated(changedProps: PropertyValues): void {
|
||||||
@ -190,12 +202,14 @@ export class HuiThermostatCard extends hassLocalizeLitMixin(LitElement)
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _initialLoad(): Promise<void> {
|
private async _initialLoad(): Promise<void> {
|
||||||
|
this._loaded = true;
|
||||||
|
|
||||||
const radius = this.clientWidth / 3;
|
const radius = this.clientWidth / 3;
|
||||||
this._broadCard = this.clientWidth > 390;
|
this._broadCard = this.clientWidth > 390;
|
||||||
|
|
||||||
(this.shadowRoot!.querySelector(
|
(this.shadowRoot!.querySelector(
|
||||||
"#thermostat"
|
"#thermostat"
|
||||||
)! as HTMLElement).style.minHeight = radius * 2 + "px";
|
)! as HTMLElement).style.height = radius * 2 + "px";
|
||||||
|
|
||||||
const loaded = await loadRoundslider();
|
const loaded = await loadRoundslider();
|
||||||
await new Promise((resolve) => afterNextRender(resolve));
|
await new Promise((resolve) => afterNextRender(resolve));
|
||||||
@ -220,7 +234,6 @@ export class HuiThermostatCard extends hassLocalizeLitMixin(LitElement)
|
|||||||
min: stateObj.attributes.min_temp,
|
min: stateObj.attributes.min_temp,
|
||||||
max: stateObj.attributes.max_temp,
|
max: stateObj.attributes.max_temp,
|
||||||
sliderType: _sliderType,
|
sliderType: _sliderType,
|
||||||
create: () => this._loaded(),
|
|
||||||
change: (value) => this._setTemperature(value),
|
change: (value) => this._setTemperature(value),
|
||||||
drag: (value) => this._dragEvent(value),
|
drag: (value) => this._dragEvent(value),
|
||||||
value: sliderValue,
|
value: sliderValue,
|
||||||
@ -252,12 +265,6 @@ export class HuiThermostatCard extends hassLocalizeLitMixin(LitElement)
|
|||||||
return [sliderValue, uiValue];
|
return [sliderValue, uiValue];
|
||||||
}
|
}
|
||||||
|
|
||||||
private _loaded(): void {
|
|
||||||
(this.shadowRoot!.querySelector(
|
|
||||||
"#thermostat"
|
|
||||||
)! as HTMLElement).style.minHeight = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _updateSetTemp(value: string): void {
|
private _updateSetTemp(value: string): void {
|
||||||
this.shadowRoot!.querySelector("#set-temperature")!.innerHTML = value;
|
this.shadowRoot!.querySelector("#set-temperature")!.innerHTML = value;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user