From 9a1fc02755f292451f7df3446cf7b4687206bae1 Mon Sep 17 00:00:00 2001 From: Steve Repsher Date: Wed, 17 Aug 2022 12:01:05 -0400 Subject: [PATCH] Fix localize key types related to form schemas (Group 2) (#13342) --- src/data/selector.ts | 4 +- .../config-elements/hui-gauge-card-editor.ts | 133 ++++++++++-------- .../config-elements/hui-glance-card-editor.ts | 37 ++--- .../config-elements/hui-grid-card-editor.ts | 8 +- .../hui-history-graph-card-editor.ts | 8 +- .../hui-humidifier-card-editor.ts | 8 +- .../config-elements/hui-iframe-card-editor.ts | 8 +- .../config-elements/hui-light-card-editor.ts | 61 ++++---- .../hui-markdown-card-editor.ts | 37 ++--- .../hui-picture-entity-card-editor.ts | 40 ++---- .../hui-picture-glance-card-editor.ts | 44 +++--- .../hui-plant-status-card-editor.ts | 8 +- .../hui-thermostat-card-editor.ts | 8 +- 13 files changed, 199 insertions(+), 205 deletions(-) diff --git a/src/data/selector.ts b/src/data/selector.ts index 1b3997b6de..b56f43d901 100644 --- a/src/data/selector.ts +++ b/src/data/selector.ts @@ -112,7 +112,7 @@ export interface DurationSelector { export interface EntitySelector { entity: { integration?: string; - domain?: string | string[]; + domain?: string | readonly string[]; device_class?: string; multiple?: boolean; include_entities?: string[]; @@ -180,7 +180,7 @@ export interface SelectSelector { multiple?: boolean; custom_value?: boolean; mode?: "list" | "dropdown"; - options: string[] | SelectOption[]; + options: readonly string[] | readonly SelectOption[]; }; } diff --git a/src/panels/lovelace/editor/config-elements/hui-gauge-card-editor.ts b/src/panels/lovelace/editor/config-elements/hui-gauge-card-editor.ts index 2baa6c32a0..c390ea3b1d 100644 --- a/src/panels/lovelace/editor/config-elements/hui-gauge-card-editor.ts +++ b/src/panels/lovelace/editor/config-elements/hui-gauge-card-editor.ts @@ -13,7 +13,7 @@ import { } from "superstruct"; import memoizeOne from "memoize-one"; import { fireEvent } from "../../../../common/dom/fire_event"; -import type { HaFormSchema } from "../../../../components/ha-form/types"; +import type { SchemaUnion } from "../../../../components/ha-form/types"; import type { HomeAssistant } from "../../../../types"; import type { GaugeCardConfig } from "../../cards/types"; import type { LovelaceCardEditor } from "../../types"; @@ -54,57 +54,66 @@ export class HuiGaugeCardEditor this._config = config; } - private _schema = memoizeOne((showSeverity: boolean) => { - const schema = [ - { - name: "entity", - selector: { - entity: { - domain: ["counter", "input_number", "number", "sensor"], + private _schema = memoizeOne( + (showSeverity: boolean) => + [ + { + name: "entity", + selector: { + entity: { + domain: ["counter", "input_number", "number", "sensor"], + }, }, }, - }, - { - name: "", - type: "grid", - schema: [ - { name: "name", selector: { text: {} } }, - { name: "unit", selector: { text: {} } }, - ], - }, - { name: "theme", selector: { theme: {} } }, - { - name: "", - type: "grid", - schema: [ - { name: "min", selector: { number: { min: 1, mode: "box" } } }, - { name: "max", selector: { number: { min: 1, mode: "box" } } }, - ], - }, - { - name: "", - type: "grid", - schema: [ - { name: "needle", selector: { boolean: {} } }, - { name: "show_severity", selector: { boolean: {} } }, - ], - }, - ]; - - if (showSeverity) { - schema.push({ - name: "", - type: "grid", - schema: [ - { name: "green", selector: { number: { min: 0, mode: "box" } } }, - { name: "yellow", selector: { number: { min: 0, mode: "box" } } }, - { name: "red", selector: { number: { min: 0, mode: "box" } } }, - ], - }); - } - - return schema; - }); + { + name: "", + type: "grid", + schema: [ + { name: "name", selector: { text: {} } }, + { name: "unit", selector: { text: {} } }, + ], + }, + { name: "theme", selector: { theme: {} } }, + { + name: "", + type: "grid", + schema: [ + { name: "min", selector: { number: { min: 1, mode: "box" } } }, + { name: "max", selector: { number: { min: 1, mode: "box" } } }, + ], + }, + { + name: "", + type: "grid", + schema: [ + { name: "needle", selector: { boolean: {} } }, + { name: "show_severity", selector: { boolean: {} } }, + ], + }, + ...(showSeverity + ? ([ + { + name: "", + type: "grid", + schema: [ + { + name: "green", + selector: { number: { min: 0, mode: "box" } }, + }, + { + name: "yellow", + selector: { number: { min: 0, mode: "box" } }, + }, + { + name: "red", + selector: { number: { min: 0, mode: "box" } }, + }, + ], + }, + ] as const) + : []), + ] as const + ); protected render(): TemplateResult { if (!this.hass || !this._config) { @@ -152,7 +161,9 @@ export class HuiGaugeCardEditor fireEvent(this, "config-changed", { config }); } - private _computeLabelCallback = (schema: HaFormSchema) => { + private _computeLabelCallback = ( + schema: SchemaUnion> + ) => { switch (schema.name) { case "name": return this.hass!.localize( @@ -186,18 +197,16 @@ export class HuiGaugeCardEditor )} (${this.hass!.localize( "ui.panel.lovelace.editor.card.config.optional" )})`; + case "unit": + return this.hass!.localize( + "ui.panel.lovelace.editor.card.generic.unit" + ); + default: + // "green" | "yellow" | "red" + return this.hass!.localize( + `ui.panel.lovelace.editor.card.gauge.severity.${schema.name}` + ); } - return ( - this.hass!.localize( - `ui.panel.lovelace.editor.card.gauge.${schema.name}` - ) || - this.hass!.localize( - `ui.panel.lovelace.editor.card.generic.${schema.name}` - ) || - this.hass!.localize( - `ui.panel.lovelace.editor.card.gauge.severity.${schema.name}` - ) - ); }; } diff --git a/src/panels/lovelace/editor/config-elements/hui-glance-card-editor.ts b/src/panels/lovelace/editor/config-elements/hui-glance-card-editor.ts index 9cdf13c4cd..31f8ef60f1 100644 --- a/src/panels/lovelace/editor/config-elements/hui-glance-card-editor.ts +++ b/src/panels/lovelace/editor/config-elements/hui-glance-card-editor.ts @@ -20,7 +20,7 @@ import type { LovelaceCardEditor } from "../../types"; import { processEditorEntities } from "../process-editor-entities"; import { entitiesConfigStruct } from "../structs/entities-struct"; import { baseLovelaceCardConfig } from "../structs/base-card-struct"; -import type { HaFormSchema } from "../../../../components/ha-form/types"; +import type { SchemaUnion } from "../../../../components/ha-form/types"; const cardConfigStruct = assign( baseLovelaceCardConfig, @@ -36,7 +36,7 @@ const cardConfigStruct = assign( }) ); -const SCHEMA: HaFormSchema[] = [ +const SCHEMA = [ { name: "title", selector: { text: {} } }, { name: "", @@ -57,7 +57,7 @@ const SCHEMA: HaFormSchema[] = [ ], }, { name: "state_color", selector: { boolean: {} } }, -]; +] as const; @customElement("hui-glance-card-editor") export class HuiGlanceCardEditor @@ -117,22 +117,23 @@ export class HuiGlanceCardEditor fireEvent(this, "config-changed", { config }); } - private _computeLabelCallback = (schema: HaFormSchema) => { - if (schema.name === "theme") { - return `${this.hass!.localize( - "ui.panel.lovelace.editor.card.generic.theme" - )} (${this.hass!.localize( - "ui.panel.lovelace.editor.card.config.optional" - )})`; + 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" + )})`; + case "columns": + return this.hass!.localize( + `ui.panel.lovelace.editor.card.glance.${schema.name}` + ); + default: + return this.hass!.localize( + `ui.panel.lovelace.editor.card.generic.${schema.name}` + ); } - return ( - this.hass!.localize( - `ui.panel.lovelace.editor.card.glance.${schema.name}` - ) || - this.hass!.localize( - `ui.panel.lovelace.editor.card.generic.${schema.name}` - ) - ); }; } diff --git a/src/panels/lovelace/editor/config-elements/hui-grid-card-editor.ts b/src/panels/lovelace/editor/config-elements/hui-grid-card-editor.ts index 49c30c100f..2a730609ab 100644 --- a/src/panels/lovelace/editor/config-elements/hui-grid-card-editor.ts +++ b/src/panels/lovelace/editor/config-elements/hui-grid-card-editor.ts @@ -12,7 +12,7 @@ import { string, } from "superstruct"; import { fireEvent } from "../../../../common/dom/fire_event"; -import type { HaFormSchema } from "../../../../components/ha-form/types"; +import type { SchemaUnion } from "../../../../components/ha-form/types"; import type { GridCardConfig } from "../../cards/types"; import { baseLovelaceCardConfig } from "../structs/base-card-struct"; import { HuiStackCardEditor } from "./hui-stack-card-editor"; @@ -27,7 +27,7 @@ const cardConfigStruct = assign( }) ); -const SCHEMA: HaFormSchema[] = [ +const SCHEMA = [ { type: "grid", name: "", @@ -36,7 +36,7 @@ const SCHEMA: HaFormSchema[] = [ { name: "square", selector: { boolean: {} } }, ], }, -]; +] as const; @customElement("hui-grid-card-editor") export class HuiGridCardEditor extends HuiStackCardEditor { @@ -68,7 +68,7 @@ export class HuiGridCardEditor extends HuiStackCardEditor { fireEvent(this, "config-changed", { config: ev.detail.value }); } - private _computeLabelCallback = (schema: HaFormSchema) => + private _computeLabelCallback = (schema: SchemaUnion) => this.hass!.localize(`ui.panel.lovelace.editor.card.grid.${schema.name}`); } diff --git a/src/panels/lovelace/editor/config-elements/hui-history-graph-card-editor.ts b/src/panels/lovelace/editor/config-elements/hui-history-graph-card-editor.ts index a18b13c2c1..fb9e05f42f 100644 --- a/src/panels/lovelace/editor/config-elements/hui-history-graph-card-editor.ts +++ b/src/panels/lovelace/editor/config-elements/hui-history-graph-card-editor.ts @@ -19,7 +19,7 @@ import type { LovelaceCardEditor } from "../../types"; import { processEditorEntities } from "../process-editor-entities"; import { entitiesConfigStruct } from "../structs/entities-struct"; import { baseLovelaceCardConfig } from "../structs/base-card-struct"; -import type { HaFormSchema } from "../../../../components/ha-form/types"; +import type { SchemaUnion } from "../../../../components/ha-form/types"; const cardConfigStruct = assign( baseLovelaceCardConfig, @@ -31,7 +31,7 @@ const cardConfigStruct = assign( }) ); -const SCHEMA: HaFormSchema[] = [ +const SCHEMA = [ { name: "title", selector: { text: {} } }, { name: "", @@ -44,7 +44,7 @@ const SCHEMA: HaFormSchema[] = [ }, ], }, -]; +] as const; @customElement("hui-history-graph-card-editor") export class HuiHistoryGraphCardEditor @@ -97,7 +97,7 @@ export class HuiHistoryGraphCardEditor fireEvent(this, "config-changed", { config }); } - private _computeLabelCallback = (schema: HaFormSchema) => + private _computeLabelCallback = (schema: SchemaUnion) => this.hass!.localize(`ui.panel.lovelace.editor.card.generic.${schema.name}`); static styles: CSSResultGroup = css` diff --git a/src/panels/lovelace/editor/config-elements/hui-humidifier-card-editor.ts b/src/panels/lovelace/editor/config-elements/hui-humidifier-card-editor.ts index b5e83f7c81..055cdf68c9 100644 --- a/src/panels/lovelace/editor/config-elements/hui-humidifier-card-editor.ts +++ b/src/panels/lovelace/editor/config-elements/hui-humidifier-card-editor.ts @@ -3,7 +3,7 @@ import { html, LitElement, TemplateResult } from "lit"; import { customElement, property, state } from "lit/decorators"; import { assert, assign, object, optional, string } from "superstruct"; import { fireEvent } from "../../../../common/dom/fire_event"; -import type { HaFormSchema } from "../../../../components/ha-form/types"; +import type { SchemaUnion } from "../../../../components/ha-form/types"; import type { HomeAssistant } from "../../../../types"; import type { HumidifierCardConfig } from "../../cards/types"; import type { LovelaceCardEditor } from "../../types"; @@ -18,7 +18,7 @@ const cardConfigStruct = assign( }) ); -const SCHEMA: HaFormSchema[] = [ +const SCHEMA = [ { name: "entity", required: true, @@ -32,7 +32,7 @@ const SCHEMA: HaFormSchema[] = [ { name: "theme", selector: { theme: {} } }, ], }, -]; +] as const; @customElement("hui-humidifier-card-editor") export class HuiHumidifierCardEditor @@ -68,7 +68,7 @@ export class HuiHumidifierCardEditor fireEvent(this, "config-changed", { config: ev.detail.value }); } - private _computeLabelCallback = (schema: HaFormSchema) => { + private _computeLabelCallback = (schema: SchemaUnion) => { if (schema.name === "entity") { return this.hass!.localize( "ui.panel.lovelace.editor.card.generic.entity" diff --git a/src/panels/lovelace/editor/config-elements/hui-iframe-card-editor.ts b/src/panels/lovelace/editor/config-elements/hui-iframe-card-editor.ts index bef193337b..8e53668e29 100644 --- a/src/panels/lovelace/editor/config-elements/hui-iframe-card-editor.ts +++ b/src/panels/lovelace/editor/config-elements/hui-iframe-card-editor.ts @@ -3,7 +3,7 @@ import { html, LitElement, TemplateResult } from "lit"; import { customElement, property, state } from "lit/decorators"; import { assert, assign, object, optional, string } from "superstruct"; import { fireEvent } from "../../../../common/dom/fire_event"; -import type { HaFormSchema } from "../../../../components/ha-form/types"; +import type { SchemaUnion } from "../../../../components/ha-form/types"; import type { HomeAssistant } from "../../../../types"; import type { IframeCardConfig } from "../../cards/types"; import type { LovelaceCardEditor } from "../../types"; @@ -18,7 +18,7 @@ const cardConfigStruct = assign( }) ); -const SCHEMA: HaFormSchema[] = [ +const SCHEMA = [ { name: "title", selector: { text: {} } }, { name: "", @@ -28,7 +28,7 @@ const SCHEMA: HaFormSchema[] = [ { name: "aspect_ratio", selector: { text: {} } }, ], }, -]; +] as const; @customElement("hui-iframe-card-editor") export class HuiIframeCardEditor @@ -64,7 +64,7 @@ export class HuiIframeCardEditor fireEvent(this, "config-changed", { config: ev.detail.value }); } - private _computeLabelCallback = (schema: HaFormSchema) => + private _computeLabelCallback = (schema: SchemaUnion) => this.hass!.localize(`ui.panel.lovelace.editor.card.generic.${schema.name}`); } diff --git a/src/panels/lovelace/editor/config-elements/hui-light-card-editor.ts b/src/panels/lovelace/editor/config-elements/hui-light-card-editor.ts index 42e47ef81a..69e622d506 100644 --- a/src/panels/lovelace/editor/config-elements/hui-light-card-editor.ts +++ b/src/panels/lovelace/editor/config-elements/hui-light-card-editor.ts @@ -15,7 +15,7 @@ import { configElementStyle } from "./config-elements-style"; import { baseLovelaceCardConfig } from "../structs/base-card-struct"; import { domainIcon } from "../../../../common/entity/domain_icon"; import { computeDomain } from "../../../../common/entity/compute_domain"; -import type { HaFormSchema } from "../../../../components/ha-form/types"; +import type { SchemaUnion } from "../../../../components/ha-form/types"; const cardConfigStruct = assign( baseLovelaceCardConfig, @@ -44,37 +44,34 @@ export class HuiLightCardEditor } private _schema = memoizeOne( - ( - entity: string, - icon: string | undefined, - entityState: HassEntity - ): HaFormSchema[] => [ - { - name: "entity", - required: true, - selector: { entity: { domain: "light" } }, - }, - { - type: "grid", - name: "", - schema: [ - { name: "name", selector: { text: {} } }, - { - name: "icon", - selector: { - icon: { - placeholder: icon || entityState?.attributes.icon, - fallbackPath: - !icon && !entityState?.attributes.icon && entityState - ? domainIcon(computeDomain(entity), entityState) - : undefined, + (entity: string, icon: string | undefined, entityState: HassEntity) => + [ + { + name: "entity", + required: true, + selector: { entity: { domain: "light" } }, + }, + { + type: "grid", + name: "", + schema: [ + { name: "name", selector: { text: {} } }, + { + name: "icon", + selector: { + icon: { + placeholder: icon || entityState?.attributes.icon, + fallbackPath: + !icon && !entityState?.attributes.icon && entityState + ? domainIcon(computeDomain(entity), entityState) + : undefined, + }, }, }, - }, - ], - }, - { name: "theme", selector: { theme: {} } }, - ] + ], + }, + { name: "theme", selector: { theme: {} } }, + ] as const ); get _hold_action(): ActionConfig { @@ -172,7 +169,9 @@ export class HuiLightCardEditor fireEvent(this, "config-changed", { config: ev.detail.value }); } - private _computeLabelCallback = (schema: HaFormSchema) => { + private _computeLabelCallback = ( + schema: SchemaUnion> + ) => { if (schema.name === "entity") { return this.hass!.localize( "ui.panel.lovelace.editor.card.generic.entity" diff --git a/src/panels/lovelace/editor/config-elements/hui-markdown-card-editor.ts b/src/panels/lovelace/editor/config-elements/hui-markdown-card-editor.ts index e22892d392..28b639d5c1 100644 --- a/src/panels/lovelace/editor/config-elements/hui-markdown-card-editor.ts +++ b/src/panels/lovelace/editor/config-elements/hui-markdown-card-editor.ts @@ -3,7 +3,7 @@ import { html, LitElement, TemplateResult } from "lit"; import { customElement, property, state } from "lit/decorators"; import { assert, assign, object, optional, string } from "superstruct"; import { fireEvent } from "../../../../common/dom/fire_event"; -import type { HaFormSchema } from "../../../../components/ha-form/types"; +import type { SchemaUnion } from "../../../../components/ha-form/types"; import type { HomeAssistant } from "../../../../types"; import type { MarkdownCardConfig } from "../../cards/types"; import type { LovelaceCardEditor } from "../../types"; @@ -18,11 +18,11 @@ const cardConfigStruct = assign( }) ); -const SCHEMA: HaFormSchema[] = [ +const SCHEMA = [ { name: "title", selector: { text: {} } }, { name: "content", required: true, selector: { template: {} } }, { name: "theme", selector: { theme: {} } }, -]; +] as const; @customElement("hui-markdown-card-editor") export class HuiMarkdownCardEditor @@ -58,22 +58,23 @@ export class HuiMarkdownCardEditor fireEvent(this, "config-changed", { config: ev.detail.value }); } - private _computeLabelCallback = (schema: HaFormSchema) => { - if (schema.name === "theme") { - return `${this.hass!.localize( - "ui.panel.lovelace.editor.card.generic.theme" - )} (${this.hass!.localize( - "ui.panel.lovelace.editor.card.config.optional" - )})`; + 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" + )})`; + case "content": + return this.hass!.localize( + `ui.panel.lovelace.editor.card.markdown.${schema.name}` + ); + default: + return this.hass!.localize( + `ui.panel.lovelace.editor.card.generic.${schema.name}` + ); } - return ( - this.hass!.localize( - `ui.panel.lovelace.editor.card.generic.${schema.name}` - ) || - this.hass!.localize( - `ui.panel.lovelace.editor.card.markdown.${schema.name}` - ) - ); }; } diff --git a/src/panels/lovelace/editor/config-elements/hui-picture-entity-card-editor.ts b/src/panels/lovelace/editor/config-elements/hui-picture-entity-card-editor.ts index 7367ac09ef..29f26838a8 100644 --- a/src/panels/lovelace/editor/config-elements/hui-picture-entity-card-editor.ts +++ b/src/panels/lovelace/editor/config-elements/hui-picture-entity-card-editor.ts @@ -2,7 +2,7 @@ import { CSSResultGroup, html, LitElement, TemplateResult } from "lit"; import { customElement, property, state } from "lit/decorators"; import { assert, assign, boolean, object, optional, string } from "superstruct"; import { fireEvent } from "../../../../common/dom/fire_event"; -import type { HaFormSchema } from "../../../../components/ha-form/types"; +import type { SchemaUnion } from "../../../../components/ha-form/types"; import type { ActionConfig } from "../../../../data/lovelace"; import type { HomeAssistant } from "../../../../types"; import type { PictureEntityCardConfig } from "../../cards/types"; @@ -30,7 +30,7 @@ const cardConfigStruct = assign( }) ); -const SCHEMA: HaFormSchema[] = [ +const SCHEMA = [ { name: "entity", required: true, selector: { entity: {} } }, { name: "name", selector: { text: {} } }, { name: "image", selector: { text: {} } }, @@ -61,7 +61,7 @@ const SCHEMA: HaFormSchema[] = [ ], }, { name: "theme", selector: { theme: {} } }, -]; +] as const; @customElement("hui-picture-entity-card-editor") export class HuiPictureEntityCardEditor @@ -163,29 +163,19 @@ export class HuiPictureEntityCardEditor fireEvent(this, "config-changed", { config: this._config }); } - private _computeLabelCallback = (schema: HaFormSchema) => { - if (schema.name === "entity") { - return this.hass!.localize( - "ui.panel.lovelace.editor.card.generic.entity" - ); + 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}` + ); } - - if (schema.name === "theme") { - return `${this.hass!.localize( - "ui.panel.lovelace.editor.card.generic.theme" - )} (${this.hass!.localize( - "ui.panel.lovelace.editor.card.config.optional" - )})`; - } - - return ( - this.hass!.localize( - `ui.panel.lovelace.editor.card.generic.${schema.name}` - ) || - this.hass!.localize( - `ui.panel.lovelace.editor.card.picture-entity.${schema.name}` - ) - ); }; static styles: CSSResultGroup = configElementStyle; diff --git a/src/panels/lovelace/editor/config-elements/hui-picture-glance-card-editor.ts b/src/panels/lovelace/editor/config-elements/hui-picture-glance-card-editor.ts index 18e46b154e..aa7340e134 100644 --- a/src/panels/lovelace/editor/config-elements/hui-picture-glance-card-editor.ts +++ b/src/panels/lovelace/editor/config-elements/hui-picture-glance-card-editor.ts @@ -3,7 +3,7 @@ import { customElement, property, state } from "lit/decorators"; import { array, assert, assign, object, optional, string } from "superstruct"; import { fireEvent } from "../../../../common/dom/fire_event"; import "../../../../components/ha-form/ha-form"; -import type { HaFormSchema } from "../../../../components/ha-form/types"; +import type { SchemaUnion } from "../../../../components/ha-form/types"; import type { ActionConfig } from "../../../../data/lovelace"; import type { HomeAssistant } from "../../../../types"; import type { PictureGlanceCardConfig } from "../../cards/types"; @@ -36,7 +36,7 @@ const cardConfigStruct = assign( const actions = ["more-info", "toggle", "navigate", "call-service", "none"]; -const SCHEMA: HaFormSchema[] = [ +const SCHEMA = [ { name: "title", selector: { text: {} } }, { name: "image", selector: { text: {} } }, { name: "camera_image", selector: { entity: { domain: "camera" } } }, @@ -53,7 +53,7 @@ const SCHEMA: HaFormSchema[] = [ }, { name: "entity", selector: { entity: {} } }, { name: "theme", selector: { theme: {} } }, -]; +] as const; @customElement("hui-picture-glance-card-editor") export class HuiPictureGlanceCardEditor @@ -158,29 +158,23 @@ export class HuiPictureGlanceCardEditor fireEvent(this, "config-changed", { config: this._config }); } - private _computeLabelCallback = (schema: HaFormSchema) => { - if (schema.name === "entity") { - return this.hass!.localize( - "ui.panel.lovelace.editor.card.picture-glance.state_entity" - ); + 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" + )})`; + case "entity": + return this.hass!.localize( + "ui.panel.lovelace.editor.card.picture-glance.state_entity" + ); + default: + return this.hass!.localize( + `ui.panel.lovelace.editor.card.generic.${schema.name}` + ); } - - if (schema.name === "theme") { - return `${this.hass!.localize( - "ui.panel.lovelace.editor.card.generic.theme" - )} (${this.hass!.localize( - "ui.panel.lovelace.editor.card.config.optional" - )})`; - } - - return ( - this.hass!.localize( - `ui.panel.lovelace.editor.card.generic.${schema.name}` - ) || - this.hass!.localize( - `ui.panel.lovelace.editor.card.picture-glance.${schema.name}` - ) - ); }; static styles: CSSResultGroup = configElementStyle; diff --git a/src/panels/lovelace/editor/config-elements/hui-plant-status-card-editor.ts b/src/panels/lovelace/editor/config-elements/hui-plant-status-card-editor.ts index f62fe89c21..dbc19b69a3 100644 --- a/src/panels/lovelace/editor/config-elements/hui-plant-status-card-editor.ts +++ b/src/panels/lovelace/editor/config-elements/hui-plant-status-card-editor.ts @@ -3,7 +3,7 @@ import { html, LitElement, TemplateResult } from "lit"; import { customElement, property, state } from "lit/decorators"; import { assert, assign, object, optional, string } from "superstruct"; import { fireEvent } from "../../../../common/dom/fire_event"; -import type { HaFormSchema } from "../../../../components/ha-form/types"; +import type { SchemaUnion } from "../../../../components/ha-form/types"; import type { HomeAssistant } from "../../../../types"; import type { PlantStatusCardConfig } from "../../cards/types"; import type { LovelaceCardEditor } from "../../types"; @@ -18,11 +18,11 @@ const cardConfigStruct = assign( }) ); -const SCHEMA: HaFormSchema[] = [ +const SCHEMA = [ { name: "entity", required: true, selector: { entity: { domain: "plant" } } }, { name: "name", selector: { text: {} } }, { name: "theme", selector: { theme: {} } }, -]; +] as const; @customElement("hui-plant-status-card-editor") export class HuiPlantStatusCardEditor @@ -58,7 +58,7 @@ export class HuiPlantStatusCardEditor fireEvent(this, "config-changed", { config: ev.detail.value }); } - private _computeLabelCallback = (schema: HaFormSchema) => { + private _computeLabelCallback = (schema: SchemaUnion) => { if (schema.name === "entity") { return this.hass!.localize( "ui.panel.lovelace.editor.card.generic.entity" diff --git a/src/panels/lovelace/editor/config-elements/hui-thermostat-card-editor.ts b/src/panels/lovelace/editor/config-elements/hui-thermostat-card-editor.ts index 78d6dc3a97..cf5af922f7 100644 --- a/src/panels/lovelace/editor/config-elements/hui-thermostat-card-editor.ts +++ b/src/panels/lovelace/editor/config-elements/hui-thermostat-card-editor.ts @@ -3,7 +3,7 @@ import { html, LitElement, TemplateResult } from "lit"; import { customElement, property, state } from "lit/decorators"; import { assert, assign, object, optional, string } from "superstruct"; import { fireEvent } from "../../../../common/dom/fire_event"; -import type { HaFormSchema } from "../../../../components/ha-form/types"; +import type { SchemaUnion } from "../../../../components/ha-form/types"; import type { HomeAssistant } from "../../../../types"; import type { ThermostatCardConfig } from "../../cards/types"; import type { LovelaceCardEditor } from "../../types"; @@ -18,7 +18,7 @@ const cardConfigStruct = assign( }) ); -const SCHEMA: HaFormSchema[] = [ +const SCHEMA = [ { name: "entity", selector: { entity: { domain: "climate" } } }, { type: "grid", @@ -28,7 +28,7 @@ const SCHEMA: HaFormSchema[] = [ { name: "theme", required: false, selector: { theme: {} } }, ], }, -]; +] as const; @customElement("hui-thermostat-card-editor") export class HuiThermostatCardEditor @@ -64,7 +64,7 @@ export class HuiThermostatCardEditor fireEvent(this, "config-changed", { config: ev.detail.value }); } - private _computeLabelCallback = (schema: HaFormSchema) => { + private _computeLabelCallback = (schema: SchemaUnion) => { if (schema.name === "entity") { return this.hass!.localize( "ui.panel.lovelace.editor.card.generic.entity"