mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +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;
|
||||
|
||||
private _elementConfig?: LovelaceCardConfig;
|
||||
|
||||
public load() {
|
||||
if (!this.config) {
|
||||
throw new Error("Cannot build card without config");
|
||||
@ -84,8 +86,18 @@ export class HuiCard extends ReactiveElement {
|
||||
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) {
|
||||
this._element = createCardElement(config);
|
||||
this._elementConfig = config;
|
||||
if (this.hass) {
|
||||
this._element.hass = this.hass;
|
||||
}
|
||||
@ -135,15 +147,14 @@ export class HuiCard extends ReactiveElement {
|
||||
super.update(changedProps);
|
||||
|
||||
if (this._element) {
|
||||
if (changedProps.has("config") && this.hasUpdated) {
|
||||
const oldConfig = changedProps.get("config");
|
||||
if (this.config !== oldConfig && this.config) {
|
||||
const typeChanged = this.config?.type !== oldConfig?.type;
|
||||
if (changedProps.has("config")) {
|
||||
const elementConfig = this._elementConfig;
|
||||
if (this.config !== elementConfig && this.config) {
|
||||
const typeChanged = this.config?.type !== elementConfig?.type;
|
||||
if (typeChanged) {
|
||||
this._loadElement(this.config);
|
||||
} else {
|
||||
this._element?.setConfig(this.config);
|
||||
fireEvent(this, "card-updated");
|
||||
this._updateElement(this.config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user