mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 03:06:41 +00:00
Fix update config mecanism in hui-card (#21218)
This commit is contained in:
parent
d33cf4f199
commit
85865af0c3
@ -31,6 +31,8 @@ export class HuiCard extends ReactiveElement {
|
|||||||
|
|
||||||
@property({ attribute: false }) public hass?: HomeAssistant;
|
@property({ attribute: false }) public hass?: HomeAssistant;
|
||||||
|
|
||||||
|
private _elementConfig?: LovelaceCardConfig;
|
||||||
|
|
||||||
public load() {
|
public load() {
|
||||||
if (!this.config) {
|
if (!this.config) {
|
||||||
throw new Error("Cannot build card without config");
|
throw new Error("Cannot build card without config");
|
||||||
@ -84,8 +86,18 @@ export class HuiCard extends ReactiveElement {
|
|||||||
return this._element?.getLayoutOptions?.() ?? {};
|
return this._element?.getLayoutOptions?.() ?? {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _updateElement(config: LovelaceCardConfig) {
|
||||||
|
if (!this._element) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this._element.setConfig(config);
|
||||||
|
this._elementConfig = config;
|
||||||
|
fireEvent(this, "card-updated");
|
||||||
|
}
|
||||||
|
|
||||||
private _loadElement(config: LovelaceCardConfig) {
|
private _loadElement(config: LovelaceCardConfig) {
|
||||||
this._element = createCardElement(config);
|
this._element = createCardElement(config);
|
||||||
|
this._elementConfig = config;
|
||||||
if (this.hass) {
|
if (this.hass) {
|
||||||
this._element.hass = this.hass;
|
this._element.hass = this.hass;
|
||||||
}
|
}
|
||||||
@ -135,15 +147,14 @@ export class HuiCard extends ReactiveElement {
|
|||||||
super.update(changedProps);
|
super.update(changedProps);
|
||||||
|
|
||||||
if (this._element) {
|
if (this._element) {
|
||||||
if (changedProps.has("config") && this.hasUpdated) {
|
if (changedProps.has("config")) {
|
||||||
const oldConfig = changedProps.get("config");
|
const elementConfig = this._elementConfig;
|
||||||
if (this.config !== oldConfig && this.config) {
|
if (this.config !== elementConfig && this.config) {
|
||||||
const typeChanged = this.config?.type !== oldConfig?.type;
|
const typeChanged = this.config?.type !== elementConfig?.type;
|
||||||
if (typeChanged) {
|
if (typeChanged) {
|
||||||
this._loadElement(this.config);
|
this._loadElement(this.config);
|
||||||
} else {
|
} else {
|
||||||
this._element?.setConfig(this.config);
|
this._updateElement(this.config);
|
||||||
fireEvent(this, "card-updated");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user