Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/panels/lovelace/components/hui-entity-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class HuiEntityEditor extends LitElement {
private _addEntity() {
const newConfigEntities = this.entities!.concat({ entity: "" });

fireEvent(this, "change", { entities: newConfigEntities });
fireEvent(this, "entities-changed", { entities: newConfigEntities });
}

private _valueChanged(ev: Event): void {
Expand All @@ -68,7 +68,7 @@ export class HuiEntityEditor extends LitElement {
};
}

fireEvent(this, "change", { entities: newConfigEntities });
fireEvent(this, "entities-changed", { entities: newConfigEntities });
}

private renderStyle(): TemplateResult {
Expand Down
7 changes: 5 additions & 2 deletions src/panels/lovelace/components/hui-theme-select-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class HuiThemeSelectionEditor extends hassLocalizeLitMixin(LitElement) {
>
<paper-listbox
slot="dropdown-content"
.selected="${this.value || "Backend-selected"}"
.selected="${this.value}"
attr-for-selected="theme"
>
${
Expand All @@ -57,8 +57,11 @@ export class HuiThemeSelectionEditor extends hassLocalizeLitMixin(LitElement) {
}

private _changed(ev): void {
if (!this.hass || ev.target.value === "") {
return;
}
this.value = ev.target.value;
fireEvent(this, "change");
fireEvent(this, "theme-changed");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ export class HuiEntitiesCardEditor extends hassLocalizeLitMixin(LitElement)
private _configEntities?: ConfigEntity[];

static get properties(): PropertyDeclarations {
return {
hass: {},
_config: {},
_configEntities: {},
};
return { hass: {}, _config: {}, _configEntities: {} };
}

get _title(): string {
return this._config!.title || "";
}

get _theme(): string {
return this._config!.theme || "Backend-selected";
}

public setConfig(config: Config): void {
Expand All @@ -47,20 +51,20 @@ export class HuiEntitiesCardEditor extends hassLocalizeLitMixin(LitElement)
${this.renderStyle()}
<paper-input
label="Title"
value="${this._config!.title || ""}"
value="${this._title}"
.configValue="${"title"}"
@value-changed="${this._valueChanged}"
></paper-input>
<hui-theme-select-editor
.hass="${this.hass}"
.value="${this._config!.theme}"
.value="${this._theme}"
.configValue="${"theme"}"
@change="${this._valueChanged}"
@theme-changed="${this._valueChanged}"
></hui-theme-select-editor>
<hui-entity-editor
.hass="${this.hass}"
.entities="${this._configEntities}"
@change="${this._valueChanged}"
@entities-changed="${this._valueChanged}"
></hui-entity-editor>
<paper-checkbox
?checked="${this._config!.show_header_toggle !== false}"
Expand All @@ -77,21 +81,26 @@ export class HuiEntitiesCardEditor extends hassLocalizeLitMixin(LitElement)
}

const target = ev.target! as EditorTarget;
let newConfig = this._config;

if (
(target.configValue! === "title" && target.value === this._title) ||
(target.configValue! === "theme" && target.value === this._theme)
) {
return;
}

if (ev.detail && ev.detail.entities) {
newConfig.entities = ev.detail.entities;
} else {
newConfig = {
this._config.entities = ev.detail.entities;
this._configEntities = processEditorEntities(this._config.entities);
} else if (target.configValue) {
this._config = {
...this._config,
[target.configValue!]:
[target.configValue]:
target.checked !== undefined ? target.checked : target.value,
};
}

fireEvent(this, "config-changed", {
config: newConfig,
});
fireEvent(this, "config-changed", { config: this._config });
}

private renderStyle(): TemplateResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,27 @@ export class HuiGlanceCardEditor extends hassLocalizeLitMixin(LitElement)
private _config?: Config;
private _configEntities?: ConfigEntity[];

static get properties(): PropertyDeclarations {
return {
hass: {},
_config: {},
_configEntities: {},
};
}

public setConfig(config: Config): void {
this._config = { type: "glance", ...config };
this._configEntities = processEditorEntities(config.entities);
}

static get properties(): PropertyDeclarations {
return { hass: {}, _config: {}, _configEntities: {} };
}

get _title(): string {
return this._config!.title || "";
}

get _theme(): string {
return this._config!.theme || "Backend-selected";
}

get _columns(): string {
return this._config!.columns ? String(this._config!.columns) : "";
}

protected render(): TemplateResult {
if (!this.hass) {
return html``;
Expand All @@ -47,26 +55,26 @@ export class HuiGlanceCardEditor extends hassLocalizeLitMixin(LitElement)
${this.renderStyle()}
<paper-input
label="Title"
value="${this._config!.title}"
value="${this._title}"
.configValue="${"title"}"
@value-changed="${this._valueChanged}"
></paper-input>
<hui-theme-select-editor
.hass="${this.hass}"
.value="${this._config!.theme}"
.value="${this._theme}"
.configValue="${"theme"}"
@change="${this._valueChanged}"
@theme-changed="${this._valueChanged}"
></hui-theme-select-editor>
<paper-input
label="Columns"
value="${this._config!.columns || ""}"
value="${this._columns}"
.configValue="${"columns"}"
@value-changed="${this._valueChanged}"
></paper-input>
<hui-entity-editor
.hass="${this.hass}"
.entities="${this._configEntities}"
@change="${this._valueChanged}"
@entities-changed="${this._valueChanged}"
></hui-entity-editor>
<paper-checkbox
?checked="${this._config!.show_name !== false}"
Expand All @@ -87,23 +95,27 @@ export class HuiGlanceCardEditor extends hassLocalizeLitMixin(LitElement)
if (!this._config || !this.hass) {
return;
}

const target = ev.target! as EditorTarget;
let newConfig = this._config;

if (
(target.configValue! === "title" && target.value === this._title) ||
(target.configValue! === "theme" && target.value === this._theme) ||
(target.configValue! === "columns" && target.value === this._columns)
) {
return;
}

if (ev.detail && ev.detail.entities) {
newConfig.entities = ev.detail.entities;
} else {
newConfig = {
this._config.entities = ev.detail.entities;
this._configEntities = processEditorEntities(this._config.entities);
} else if (target.configValue) {
this._config = {
...this._config,
[target.configValue!]:
target.checked !== undefined ? target.checked : target.value,
};
}

fireEvent(this, "config-changed", {
config: newConfig,
});
fireEvent(this, "config-changed", { config: this._config });
}

private renderStyle(): TemplateResult {
Expand Down
9 changes: 6 additions & 3 deletions src/panels/lovelace/editor/hui-edit-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ export class HuiEditCard extends hassLocalizeLitMixin(LitElement) {
}

private _handleUIConfigChanged(value: LovelaceConfig): void {
this._configElement!.setConfig(value);
this._configValue = { format: "json", value };
this._updatePreview(value);
}
Expand Down Expand Up @@ -339,8 +338,11 @@ export class HuiEditCard extends hassLocalizeLitMixin(LitElement) {
}

private async _loadConfigElement(): Promise<void> {
if (!this._originalConfig) {
return;
}
const conf = this._originalConfig;
const tag = conf!.type.startsWith(CUSTOM_TYPE_PREFIX)
const tag = conf.type.startsWith(CUSTOM_TYPE_PREFIX)
? conf!.type.substr(CUSTOM_TYPE_PREFIX.length)
: `hui-${conf!.type}-card`;

Expand All @@ -362,8 +364,9 @@ export class HuiEditCard extends hassLocalizeLitMixin(LitElement) {
configElement.addEventListener("config-changed", (ev) =>
this._handleUIConfigChanged(ev.detail.config)
);
this._configValue = { format: "json", value: conf! };
this._configValue = { format: "json", value: conf };
this._configElement = configElement;
this._updatePreview(conf);
}
}

Expand Down