mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 23:36:36 +00:00
Fix conditional card with undefined hass (#1927)
* Fix conditional card with undefined hass * Conditional appendChild * Allow updating card properly
This commit is contained in:
parent
d591c45e4d
commit
575882be5a
@ -15,8 +15,9 @@ interface Config extends LovelaceConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class HuiConditionalCard extends HTMLElement implements LovelaceCard {
|
class HuiConditionalCard extends HTMLElement implements LovelaceCard {
|
||||||
protected config?: Config;
|
private _hass?: HomeAssistant;
|
||||||
protected card?: LovelaceCard;
|
private _config?: Config;
|
||||||
|
private _card?: LovelaceCard;
|
||||||
|
|
||||||
public setConfig(config) {
|
public setConfig(config) {
|
||||||
if (
|
if (
|
||||||
@ -28,18 +29,27 @@ class HuiConditionalCard extends HTMLElement implements LovelaceCard {
|
|||||||
throw new Error("Error in card configuration.");
|
throw new Error("Error in card configuration.");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.config = config;
|
if (this._card && this._card.parentElement) {
|
||||||
this.card = createCardElement(config.card);
|
this.removeChild(this._card);
|
||||||
if (this.card) {
|
}
|
||||||
this.appendChild(this.card);
|
|
||||||
this.card.hass = this.hass;
|
this._config = config;
|
||||||
|
this._card = createCardElement(config.card);
|
||||||
|
if (this._hass) {
|
||||||
|
this.hass = this._hass;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
set hass(hass: HomeAssistant) {
|
set hass(hass: HomeAssistant) {
|
||||||
|
this._hass = hass;
|
||||||
|
|
||||||
|
if (!this._card) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const visible =
|
const visible =
|
||||||
this.config &&
|
this._config &&
|
||||||
this.config.conditions.every((c) => {
|
this._config.conditions.every((c) => {
|
||||||
if (!(c.entity in hass.states)) {
|
if (!(c.entity in hass.states)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -49,15 +59,18 @@ class HuiConditionalCard extends HTMLElement implements LovelaceCard {
|
|||||||
return hass.states[c.entity].state !== c.state_not;
|
return hass.states[c.entity].state !== c.state_not;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (visible && this.card) {
|
if (visible) {
|
||||||
this.card.hass = hass;
|
this._card.hass = hass;
|
||||||
|
if (!this._card.parentElement) {
|
||||||
|
this.appendChild(this._card);
|
||||||
|
}
|
||||||
|
} else if (this._card.parentElement) {
|
||||||
|
this.removeChild(this._card);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.style.setProperty("display", visible ? "" : "none");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public getCardSize() {
|
public getCardSize() {
|
||||||
return computeCardSize(this.card);
|
return computeCardSize(this._card);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user