diff --git a/src/common/const.ts b/src/common/const.ts index dbb3481e6c..12f3a6eb74 100644 --- a/src/common/const.ts +++ b/src/common/const.ts @@ -16,7 +16,7 @@ import { mdiCarCoolantLevel, mdiCash, mdiChatSleep, - mdiClipboardCheck, + mdiClipboardList, mdiClock, mdiCloudUpload, mdiCog, @@ -121,7 +121,7 @@ export const FIXED_DOMAIN_ICONS = { siren: mdiBullhorn, stt: mdiMicrophoneMessage, text: mdiFormTextbox, - todo: mdiClipboardCheck, + todo: mdiClipboardList, time: mdiClock, timer: mdiTimerOutline, tts: mdiSpeakerMessage, diff --git a/src/panels/lovelace/common/generate-lovelace-config.ts b/src/panels/lovelace/common/generate-lovelace-config.ts index f8dfa99cc3..16b77e4ce6 100644 --- a/src/panels/lovelace/common/generate-lovelace-config.ts +++ b/src/panels/lovelace/common/generate-lovelace-config.ts @@ -39,6 +39,7 @@ const HIDE_DOMAIN = new Set([ "event", "tts", "stt", + "todo", ]); const HIDE_PLATFORM = new Set(["mobile_app"]); diff --git a/src/panels/lovelace/editor/config-elements/hui-shopping-list-editor.ts b/src/panels/lovelace/editor/config-elements/hui-shopping-list-editor.ts index 13cdbbbdb0..e1063b7b2f 100644 --- a/src/panels/lovelace/editor/config-elements/hui-shopping-list-editor.ts +++ b/src/panels/lovelace/editor/config-elements/hui-shopping-list-editor.ts @@ -1,16 +1,16 @@ -import { css, CSSResultGroup, html, LitElement, nothing } from "lit"; +import { CSSResultGroup, html, LitElement, nothing } from "lit"; import { customElement, property, state } from "lit/decorators"; import { assert, assign, object, optional, string } from "superstruct"; import { isComponentLoaded } from "../../../../common/config/is_component_loaded"; import { fireEvent } from "../../../../common/dom/fire_event"; -import "../../../../components/entity/ha-entity-picker"; -import "../../../../components/ha-textfield"; -import "../../../../components/ha-theme-picker"; +import "../../../../components/ha-alert"; +import "../../../../components/ha-form/ha-form"; import { HomeAssistant } from "../../../../types"; import { ShoppingListCardConfig } from "../../cards/types"; import { LovelaceCardEditor } from "../../types"; import { baseLovelaceCardConfig } from "../structs/base-card-struct"; -import { EditorTarget, EntitiesEditorEvent } from "../types"; +import { SchemaUnion } from "../../../../components/ha-form/types"; +import { configElementStyle } from "./config-elements-style"; const cardConfigStruct = assign( baseLovelaceCardConfig, @@ -21,6 +21,17 @@ const cardConfigStruct = assign( }) ); +const SCHEMA = [ + { name: "title", selector: { text: {} } }, + { + name: "entity", + selector: { + entity: { domain: "todo" }, + }, + }, + { name: "theme", selector: { theme: {} } }, +] as const; + @customElement("hui-shopping-list-card-editor") export class HuiShoppingListEditor extends LitElement @@ -35,92 +46,56 @@ export class HuiShoppingListEditor this._config = config; } - get _title(): string { - return this._config!.title || ""; - } - - get _theme(): string { - return this._config!.theme || ""; - } - protected render() { if (!this.hass || !this._config) { return nothing; } return html` -
- ${!isComponentLoaded(this.hass, "todo") - ? html` -
- ${this.hass.localize( - "ui.panel.lovelace.editor.card.shopping-list.integration_not_loaded" - )} -
- ` - : ""} - - - - + ${this.hass.localize( + "ui.panel.lovelace.editor.card.shopping-list.integration_not_loaded" + )} + + ` + : "" + } + + >
`; } - private _valueChanged(ev: EntitiesEditorEvent): void { - if (!this._config || !this.hass) { - return; - } - const target = ev.target! as EditorTarget; - - if (this[`_${target.configValue}`] === target.value) { - return; - } - if (target.configValue) { - if (target.value === "") { - this._config = { ...this._config }; - delete this._config[target.configValue!]; - } else { - this._config = { - ...this._config, - [target.configValue!]: target.value, - }; - } - } - fireEvent(this, "config-changed", { config: this._config }); + private _valueChanged(ev: CustomEvent): void { + const config = ev.detail.value; + fireEvent(this, "config-changed", { config }); } + private _computeLabelCallback = (schema: SchemaUnion) => { + switch (schema.name) { + case "theme": + return `${this.hass!.localize( + "ui.panel.lovelace.editor.card.generic.theme" + )} (${this.hass!.localize( + "ui.panel.lovelace.editor.card.config.optional" + )})`; + default: + return this.hass!.localize( + `ui.panel.lovelace.editor.card.generic.${schema.name}` + ); + } + }; + static get styles(): CSSResultGroup { - return css` - .error { - color: var(--error-color); - } - `; + return configElementStyle; } }