mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 03:06:41 +00:00
Prevent doing yaml conversion twice (#6308)
This commit is contained in:
parent
9ca7aca4b7
commit
072ad87831
@ -24,6 +24,7 @@ import type { EntityConfig } from "../../entity-rows/types";
|
|||||||
import type { LovelaceCardEditor } from "../../types";
|
import type { LovelaceCardEditor } from "../../types";
|
||||||
import type { GUIModeChangedEvent } from "../types";
|
import type { GUIModeChangedEvent } from "../types";
|
||||||
import "../../../../components/ha-circular-progress";
|
import "../../../../components/ha-circular-progress";
|
||||||
|
import { deepEqual } from "../../../../common/util/deep-equal";
|
||||||
|
|
||||||
export interface ConfigChangedEvent {
|
export interface ConfigChangedEvent {
|
||||||
config: LovelaceCardConfig;
|
config: LovelaceCardConfig;
|
||||||
@ -81,16 +82,11 @@ export class HuiCardEditor extends LitElement {
|
|||||||
this._yaml = _yaml;
|
this._yaml = _yaml;
|
||||||
try {
|
try {
|
||||||
this._config = safeLoad(this.yaml);
|
this._config = safeLoad(this.yaml);
|
||||||
this._updateConfigElement();
|
|
||||||
this._error = undefined;
|
this._error = undefined;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this._error = err.message;
|
this._error = err.message;
|
||||||
}
|
}
|
||||||
fireEvent(this, "config-changed", {
|
this._setConfig();
|
||||||
config: this.value!,
|
|
||||||
error: this._error,
|
|
||||||
guiModeAvailable: !(this.hasWarning || this.hasError),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public get value(): LovelaceCardConfig | undefined {
|
public get value(): LovelaceCardConfig | undefined {
|
||||||
@ -98,9 +94,29 @@ export class HuiCardEditor extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public set value(config: LovelaceCardConfig | undefined) {
|
public set value(config: LovelaceCardConfig | undefined) {
|
||||||
if (JSON.stringify(config) !== JSON.stringify(this._config || {})) {
|
if (this._config && deepEqual(config, this._config)) {
|
||||||
this.yaml = safeDump(config);
|
return;
|
||||||
}
|
}
|
||||||
|
this._config = config;
|
||||||
|
this._yaml = safeDump(config);
|
||||||
|
this._error = undefined;
|
||||||
|
this._setConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
private _setConfig() {
|
||||||
|
if (!this._error) {
|
||||||
|
try {
|
||||||
|
this._updateConfigElement();
|
||||||
|
this._error = undefined;
|
||||||
|
} catch (err) {
|
||||||
|
this._error = err.message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fireEvent(this, "config-changed", {
|
||||||
|
config: this.value!,
|
||||||
|
error: this._error,
|
||||||
|
guiModeAvailable: !(this.hasWarning || this.hasError),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public get hasWarning(): boolean {
|
public get hasWarning(): boolean {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user