Fix localize key types related to form schemas (Group 2) (#13342)

This commit is contained in:
Steve Repsher 2022-08-17 12:01:05 -04:00 committed by GitHub
parent eb4dbef610
commit 9a1fc02755
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 199 additions and 205 deletions

View File

@ -112,7 +112,7 @@ export interface DurationSelector {
export interface EntitySelector { export interface EntitySelector {
entity: { entity: {
integration?: string; integration?: string;
domain?: string | string[]; domain?: string | readonly string[];
device_class?: string; device_class?: string;
multiple?: boolean; multiple?: boolean;
include_entities?: string[]; include_entities?: string[];
@ -180,7 +180,7 @@ export interface SelectSelector {
multiple?: boolean; multiple?: boolean;
custom_value?: boolean; custom_value?: boolean;
mode?: "list" | "dropdown"; mode?: "list" | "dropdown";
options: string[] | SelectOption[]; options: readonly string[] | readonly SelectOption[];
}; };
} }

View File

@ -13,7 +13,7 @@ import {
} from "superstruct"; } from "superstruct";
import memoizeOne from "memoize-one"; import memoizeOne from "memoize-one";
import { fireEvent } from "../../../../common/dom/fire_event"; 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 { HomeAssistant } from "../../../../types";
import type { GaugeCardConfig } from "../../cards/types"; import type { GaugeCardConfig } from "../../cards/types";
import type { LovelaceCardEditor } from "../../types"; import type { LovelaceCardEditor } from "../../types";
@ -54,57 +54,66 @@ export class HuiGaugeCardEditor
this._config = config; this._config = config;
} }
private _schema = memoizeOne((showSeverity: boolean) => { private _schema = memoizeOne(
const schema = [ (showSeverity: boolean) =>
{ [
name: "entity", {
selector: { name: "entity",
entity: { selector: {
domain: ["counter", "input_number", "number", "sensor"], entity: {
domain: ["counter", "input_number", "number", "sensor"],
},
}, },
}, },
}, {
{ name: "",
name: "", type: "grid",
type: "grid", schema: [
schema: [ { name: "name", selector: { text: {} } },
{ name: "name", selector: { text: {} } }, { name: "unit", selector: { text: {} } },
{ name: "unit", selector: { text: {} } }, ],
], },
}, { name: "theme", selector: { theme: {} } },
{ name: "theme", selector: { theme: {} } }, {
{ name: "",
name: "", type: "grid",
type: "grid", schema: [
schema: [ { name: "min", selector: { number: { min: 1, mode: "box" } } },
{ name: "min", selector: { number: { min: 1, mode: "box" } } }, { name: "max", selector: { number: { min: 1, mode: "box" } } },
{ name: "max", selector: { number: { min: 1, mode: "box" } } }, ],
], },
}, {
{ name: "",
name: "", type: "grid",
type: "grid", schema: [
schema: [ { name: "needle", selector: { boolean: {} } },
{ name: "needle", selector: { boolean: {} } }, { name: "show_severity", selector: { boolean: {} } },
{ name: "show_severity", selector: { boolean: {} } }, ],
], },
}, ...(showSeverity
]; ? ([
{
if (showSeverity) { name: "",
schema.push({ type: "grid",
name: "", schema: [
type: "grid", {
schema: [ name: "green",
{ name: "green", selector: { number: { min: 0, mode: "box" } } }, selector: { number: { min: 0, mode: "box" } },
{ name: "yellow", selector: { number: { min: 0, mode: "box" } } }, },
{ name: "red", selector: { number: { min: 0, mode: "box" } } }, {
], name: "yellow",
}); selector: { number: { min: 0, mode: "box" } },
} },
{
return schema; name: "red",
}); selector: { number: { min: 0, mode: "box" } },
},
],
},
] as const)
: []),
] as const
);
protected render(): TemplateResult { protected render(): TemplateResult {
if (!this.hass || !this._config) { if (!this.hass || !this._config) {
@ -152,7 +161,9 @@ export class HuiGaugeCardEditor
fireEvent(this, "config-changed", { config }); fireEvent(this, "config-changed", { config });
} }
private _computeLabelCallback = (schema: HaFormSchema) => { private _computeLabelCallback = (
schema: SchemaUnion<ReturnType<typeof this._schema>>
) => {
switch (schema.name) { switch (schema.name) {
case "name": case "name":
return this.hass!.localize( return this.hass!.localize(
@ -186,18 +197,16 @@ export class HuiGaugeCardEditor
)} (${this.hass!.localize( )} (${this.hass!.localize(
"ui.panel.lovelace.editor.card.config.optional" "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}`
)
);
}; };
} }

View File

@ -20,7 +20,7 @@ import type { LovelaceCardEditor } from "../../types";
import { processEditorEntities } from "../process-editor-entities"; import { processEditorEntities } from "../process-editor-entities";
import { entitiesConfigStruct } from "../structs/entities-struct"; import { entitiesConfigStruct } from "../structs/entities-struct";
import { baseLovelaceCardConfig } from "../structs/base-card-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( const cardConfigStruct = assign(
baseLovelaceCardConfig, baseLovelaceCardConfig,
@ -36,7 +36,7 @@ const cardConfigStruct = assign(
}) })
); );
const SCHEMA: HaFormSchema[] = [ const SCHEMA = [
{ name: "title", selector: { text: {} } }, { name: "title", selector: { text: {} } },
{ {
name: "", name: "",
@ -57,7 +57,7 @@ const SCHEMA: HaFormSchema[] = [
], ],
}, },
{ name: "state_color", selector: { boolean: {} } }, { name: "state_color", selector: { boolean: {} } },
]; ] as const;
@customElement("hui-glance-card-editor") @customElement("hui-glance-card-editor")
export class HuiGlanceCardEditor export class HuiGlanceCardEditor
@ -117,22 +117,23 @@ export class HuiGlanceCardEditor
fireEvent(this, "config-changed", { config }); fireEvent(this, "config-changed", { config });
} }
private _computeLabelCallback = (schema: HaFormSchema) => { private _computeLabelCallback = (schema: SchemaUnion<typeof SCHEMA>) => {
if (schema.name === "theme") { switch (schema.name) {
return `${this.hass!.localize( case "theme":
"ui.panel.lovelace.editor.card.generic.theme" return `${this.hass!.localize(
)} (${this.hass!.localize( "ui.panel.lovelace.editor.card.generic.theme"
"ui.panel.lovelace.editor.card.config.optional" )} (${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}`
)
);
}; };
} }

View File

@ -12,7 +12,7 @@ import {
string, string,
} from "superstruct"; } from "superstruct";
import { fireEvent } from "../../../../common/dom/fire_event"; 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 type { GridCardConfig } from "../../cards/types";
import { baseLovelaceCardConfig } from "../structs/base-card-struct"; import { baseLovelaceCardConfig } from "../structs/base-card-struct";
import { HuiStackCardEditor } from "./hui-stack-card-editor"; import { HuiStackCardEditor } from "./hui-stack-card-editor";
@ -27,7 +27,7 @@ const cardConfigStruct = assign(
}) })
); );
const SCHEMA: HaFormSchema[] = [ const SCHEMA = [
{ {
type: "grid", type: "grid",
name: "", name: "",
@ -36,7 +36,7 @@ const SCHEMA: HaFormSchema[] = [
{ name: "square", selector: { boolean: {} } }, { name: "square", selector: { boolean: {} } },
], ],
}, },
]; ] as const;
@customElement("hui-grid-card-editor") @customElement("hui-grid-card-editor")
export class HuiGridCardEditor extends HuiStackCardEditor { export class HuiGridCardEditor extends HuiStackCardEditor {
@ -68,7 +68,7 @@ export class HuiGridCardEditor extends HuiStackCardEditor {
fireEvent(this, "config-changed", { config: ev.detail.value }); fireEvent(this, "config-changed", { config: ev.detail.value });
} }
private _computeLabelCallback = (schema: HaFormSchema) => private _computeLabelCallback = (schema: SchemaUnion<typeof SCHEMA>) =>
this.hass!.localize(`ui.panel.lovelace.editor.card.grid.${schema.name}`); this.hass!.localize(`ui.panel.lovelace.editor.card.grid.${schema.name}`);
} }

View File

@ -19,7 +19,7 @@ import type { LovelaceCardEditor } from "../../types";
import { processEditorEntities } from "../process-editor-entities"; import { processEditorEntities } from "../process-editor-entities";
import { entitiesConfigStruct } from "../structs/entities-struct"; import { entitiesConfigStruct } from "../structs/entities-struct";
import { baseLovelaceCardConfig } from "../structs/base-card-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( const cardConfigStruct = assign(
baseLovelaceCardConfig, baseLovelaceCardConfig,
@ -31,7 +31,7 @@ const cardConfigStruct = assign(
}) })
); );
const SCHEMA: HaFormSchema[] = [ const SCHEMA = [
{ name: "title", selector: { text: {} } }, { name: "title", selector: { text: {} } },
{ {
name: "", name: "",
@ -44,7 +44,7 @@ const SCHEMA: HaFormSchema[] = [
}, },
], ],
}, },
]; ] as const;
@customElement("hui-history-graph-card-editor") @customElement("hui-history-graph-card-editor")
export class HuiHistoryGraphCardEditor export class HuiHistoryGraphCardEditor
@ -97,7 +97,7 @@ export class HuiHistoryGraphCardEditor
fireEvent(this, "config-changed", { config }); fireEvent(this, "config-changed", { config });
} }
private _computeLabelCallback = (schema: HaFormSchema) => private _computeLabelCallback = (schema: SchemaUnion<typeof SCHEMA>) =>
this.hass!.localize(`ui.panel.lovelace.editor.card.generic.${schema.name}`); this.hass!.localize(`ui.panel.lovelace.editor.card.generic.${schema.name}`);
static styles: CSSResultGroup = css` static styles: CSSResultGroup = css`

View File

@ -3,7 +3,7 @@ import { html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { assert, assign, object, optional, string } from "superstruct"; import { assert, assign, object, optional, string } from "superstruct";
import { fireEvent } from "../../../../common/dom/fire_event"; 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 { HomeAssistant } from "../../../../types";
import type { HumidifierCardConfig } from "../../cards/types"; import type { HumidifierCardConfig } from "../../cards/types";
import type { LovelaceCardEditor } from "../../types"; import type { LovelaceCardEditor } from "../../types";
@ -18,7 +18,7 @@ const cardConfigStruct = assign(
}) })
); );
const SCHEMA: HaFormSchema[] = [ const SCHEMA = [
{ {
name: "entity", name: "entity",
required: true, required: true,
@ -32,7 +32,7 @@ const SCHEMA: HaFormSchema[] = [
{ name: "theme", selector: { theme: {} } }, { name: "theme", selector: { theme: {} } },
], ],
}, },
]; ] as const;
@customElement("hui-humidifier-card-editor") @customElement("hui-humidifier-card-editor")
export class HuiHumidifierCardEditor export class HuiHumidifierCardEditor
@ -68,7 +68,7 @@ export class HuiHumidifierCardEditor
fireEvent(this, "config-changed", { config: ev.detail.value }); fireEvent(this, "config-changed", { config: ev.detail.value });
} }
private _computeLabelCallback = (schema: HaFormSchema) => { private _computeLabelCallback = (schema: SchemaUnion<typeof SCHEMA>) => {
if (schema.name === "entity") { if (schema.name === "entity") {
return this.hass!.localize( return this.hass!.localize(
"ui.panel.lovelace.editor.card.generic.entity" "ui.panel.lovelace.editor.card.generic.entity"

View File

@ -3,7 +3,7 @@ import { html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { assert, assign, object, optional, string } from "superstruct"; import { assert, assign, object, optional, string } from "superstruct";
import { fireEvent } from "../../../../common/dom/fire_event"; 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 { HomeAssistant } from "../../../../types";
import type { IframeCardConfig } from "../../cards/types"; import type { IframeCardConfig } from "../../cards/types";
import type { LovelaceCardEditor } from "../../types"; import type { LovelaceCardEditor } from "../../types";
@ -18,7 +18,7 @@ const cardConfigStruct = assign(
}) })
); );
const SCHEMA: HaFormSchema[] = [ const SCHEMA = [
{ name: "title", selector: { text: {} } }, { name: "title", selector: { text: {} } },
{ {
name: "", name: "",
@ -28,7 +28,7 @@ const SCHEMA: HaFormSchema[] = [
{ name: "aspect_ratio", selector: { text: {} } }, { name: "aspect_ratio", selector: { text: {} } },
], ],
}, },
]; ] as const;
@customElement("hui-iframe-card-editor") @customElement("hui-iframe-card-editor")
export class HuiIframeCardEditor export class HuiIframeCardEditor
@ -64,7 +64,7 @@ export class HuiIframeCardEditor
fireEvent(this, "config-changed", { config: ev.detail.value }); fireEvent(this, "config-changed", { config: ev.detail.value });
} }
private _computeLabelCallback = (schema: HaFormSchema) => private _computeLabelCallback = (schema: SchemaUnion<typeof SCHEMA>) =>
this.hass!.localize(`ui.panel.lovelace.editor.card.generic.${schema.name}`); this.hass!.localize(`ui.panel.lovelace.editor.card.generic.${schema.name}`);
} }

View File

@ -15,7 +15,7 @@ import { configElementStyle } from "./config-elements-style";
import { baseLovelaceCardConfig } from "../structs/base-card-struct"; import { baseLovelaceCardConfig } from "../structs/base-card-struct";
import { domainIcon } from "../../../../common/entity/domain_icon"; import { domainIcon } from "../../../../common/entity/domain_icon";
import { computeDomain } from "../../../../common/entity/compute_domain"; 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( const cardConfigStruct = assign(
baseLovelaceCardConfig, baseLovelaceCardConfig,
@ -44,37 +44,34 @@ export class HuiLightCardEditor
} }
private _schema = memoizeOne( private _schema = memoizeOne(
( (entity: string, icon: string | undefined, entityState: HassEntity) =>
entity: string, [
icon: string | undefined, {
entityState: HassEntity name: "entity",
): HaFormSchema[] => [ required: true,
{ selector: { entity: { domain: "light" } },
name: "entity", },
required: true, {
selector: { entity: { domain: "light" } }, type: "grid",
}, name: "",
{ schema: [
type: "grid", { name: "name", selector: { text: {} } },
name: "", {
schema: [ name: "icon",
{ name: "name", selector: { text: {} } }, selector: {
{ icon: {
name: "icon", placeholder: icon || entityState?.attributes.icon,
selector: { fallbackPath:
icon: { !icon && !entityState?.attributes.icon && entityState
placeholder: icon || entityState?.attributes.icon, ? domainIcon(computeDomain(entity), entityState)
fallbackPath: : undefined,
!icon && !entityState?.attributes.icon && entityState },
? domainIcon(computeDomain(entity), entityState)
: undefined,
}, },
}, },
}, ],
], },
}, { name: "theme", selector: { theme: {} } },
{ name: "theme", selector: { theme: {} } }, ] as const
]
); );
get _hold_action(): ActionConfig { get _hold_action(): ActionConfig {
@ -172,7 +169,9 @@ export class HuiLightCardEditor
fireEvent(this, "config-changed", { config: ev.detail.value }); fireEvent(this, "config-changed", { config: ev.detail.value });
} }
private _computeLabelCallback = (schema: HaFormSchema) => { private _computeLabelCallback = (
schema: SchemaUnion<ReturnType<typeof this._schema>>
) => {
if (schema.name === "entity") { if (schema.name === "entity") {
return this.hass!.localize( return this.hass!.localize(
"ui.panel.lovelace.editor.card.generic.entity" "ui.panel.lovelace.editor.card.generic.entity"

View File

@ -3,7 +3,7 @@ import { html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { assert, assign, object, optional, string } from "superstruct"; import { assert, assign, object, optional, string } from "superstruct";
import { fireEvent } from "../../../../common/dom/fire_event"; 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 { HomeAssistant } from "../../../../types";
import type { MarkdownCardConfig } from "../../cards/types"; import type { MarkdownCardConfig } from "../../cards/types";
import type { LovelaceCardEditor } from "../../types"; import type { LovelaceCardEditor } from "../../types";
@ -18,11 +18,11 @@ const cardConfigStruct = assign(
}) })
); );
const SCHEMA: HaFormSchema[] = [ const SCHEMA = [
{ name: "title", selector: { text: {} } }, { name: "title", selector: { text: {} } },
{ name: "content", required: true, selector: { template: {} } }, { name: "content", required: true, selector: { template: {} } },
{ name: "theme", selector: { theme: {} } }, { name: "theme", selector: { theme: {} } },
]; ] as const;
@customElement("hui-markdown-card-editor") @customElement("hui-markdown-card-editor")
export class HuiMarkdownCardEditor export class HuiMarkdownCardEditor
@ -58,22 +58,23 @@ export class HuiMarkdownCardEditor
fireEvent(this, "config-changed", { config: ev.detail.value }); fireEvent(this, "config-changed", { config: ev.detail.value });
} }
private _computeLabelCallback = (schema: HaFormSchema) => { private _computeLabelCallback = (schema: SchemaUnion<typeof SCHEMA>) => {
if (schema.name === "theme") { switch (schema.name) {
return `${this.hass!.localize( case "theme":
"ui.panel.lovelace.editor.card.generic.theme" return `${this.hass!.localize(
)} (${this.hass!.localize( "ui.panel.lovelace.editor.card.generic.theme"
"ui.panel.lovelace.editor.card.config.optional" )} (${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}`
)
);
}; };
} }

View File

@ -2,7 +2,7 @@ import { CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { assert, assign, boolean, object, optional, string } from "superstruct"; import { assert, assign, boolean, object, optional, string } from "superstruct";
import { fireEvent } from "../../../../common/dom/fire_event"; 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 { ActionConfig } from "../../../../data/lovelace";
import type { HomeAssistant } from "../../../../types"; import type { HomeAssistant } from "../../../../types";
import type { PictureEntityCardConfig } from "../../cards/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: "entity", required: true, selector: { entity: {} } },
{ name: "name", selector: { text: {} } }, { name: "name", selector: { text: {} } },
{ name: "image", selector: { text: {} } }, { name: "image", selector: { text: {} } },
@ -61,7 +61,7 @@ const SCHEMA: HaFormSchema[] = [
], ],
}, },
{ name: "theme", selector: { theme: {} } }, { name: "theme", selector: { theme: {} } },
]; ] as const;
@customElement("hui-picture-entity-card-editor") @customElement("hui-picture-entity-card-editor")
export class HuiPictureEntityCardEditor export class HuiPictureEntityCardEditor
@ -163,29 +163,19 @@ export class HuiPictureEntityCardEditor
fireEvent(this, "config-changed", { config: this._config }); fireEvent(this, "config-changed", { config: this._config });
} }
private _computeLabelCallback = (schema: HaFormSchema) => { private _computeLabelCallback = (schema: SchemaUnion<typeof SCHEMA>) => {
if (schema.name === "entity") { switch (schema.name) {
return this.hass!.localize( case "theme":
"ui.panel.lovelace.editor.card.generic.entity" 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; static styles: CSSResultGroup = configElementStyle;

View File

@ -3,7 +3,7 @@ import { customElement, property, state } from "lit/decorators";
import { array, assert, assign, object, optional, string } from "superstruct"; import { array, assert, assign, object, optional, string } from "superstruct";
import { fireEvent } from "../../../../common/dom/fire_event"; import { fireEvent } from "../../../../common/dom/fire_event";
import "../../../../components/ha-form/ha-form"; 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 { ActionConfig } from "../../../../data/lovelace";
import type { HomeAssistant } from "../../../../types"; import type { HomeAssistant } from "../../../../types";
import type { PictureGlanceCardConfig } from "../../cards/types"; import type { PictureGlanceCardConfig } from "../../cards/types";
@ -36,7 +36,7 @@ const cardConfigStruct = assign(
const actions = ["more-info", "toggle", "navigate", "call-service", "none"]; const actions = ["more-info", "toggle", "navigate", "call-service", "none"];
const SCHEMA: HaFormSchema[] = [ const SCHEMA = [
{ name: "title", selector: { text: {} } }, { name: "title", selector: { text: {} } },
{ name: "image", selector: { text: {} } }, { name: "image", selector: { text: {} } },
{ name: "camera_image", selector: { entity: { domain: "camera" } } }, { name: "camera_image", selector: { entity: { domain: "camera" } } },
@ -53,7 +53,7 @@ const SCHEMA: HaFormSchema[] = [
}, },
{ name: "entity", selector: { entity: {} } }, { name: "entity", selector: { entity: {} } },
{ name: "theme", selector: { theme: {} } }, { name: "theme", selector: { theme: {} } },
]; ] as const;
@customElement("hui-picture-glance-card-editor") @customElement("hui-picture-glance-card-editor")
export class HuiPictureGlanceCardEditor export class HuiPictureGlanceCardEditor
@ -158,29 +158,23 @@ export class HuiPictureGlanceCardEditor
fireEvent(this, "config-changed", { config: this._config }); fireEvent(this, "config-changed", { config: this._config });
} }
private _computeLabelCallback = (schema: HaFormSchema) => { private _computeLabelCallback = (schema: SchemaUnion<typeof SCHEMA>) => {
if (schema.name === "entity") { switch (schema.name) {
return this.hass!.localize( case "theme":
"ui.panel.lovelace.editor.card.picture-glance.state_entity" 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; static styles: CSSResultGroup = configElementStyle;

View File

@ -3,7 +3,7 @@ import { html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { assert, assign, object, optional, string } from "superstruct"; import { assert, assign, object, optional, string } from "superstruct";
import { fireEvent } from "../../../../common/dom/fire_event"; 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 { HomeAssistant } from "../../../../types";
import type { PlantStatusCardConfig } from "../../cards/types"; import type { PlantStatusCardConfig } from "../../cards/types";
import type { LovelaceCardEditor } from "../../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: "entity", required: true, selector: { entity: { domain: "plant" } } },
{ name: "name", selector: { text: {} } }, { name: "name", selector: { text: {} } },
{ name: "theme", selector: { theme: {} } }, { name: "theme", selector: { theme: {} } },
]; ] as const;
@customElement("hui-plant-status-card-editor") @customElement("hui-plant-status-card-editor")
export class HuiPlantStatusCardEditor export class HuiPlantStatusCardEditor
@ -58,7 +58,7 @@ export class HuiPlantStatusCardEditor
fireEvent(this, "config-changed", { config: ev.detail.value }); fireEvent(this, "config-changed", { config: ev.detail.value });
} }
private _computeLabelCallback = (schema: HaFormSchema) => { private _computeLabelCallback = (schema: SchemaUnion<typeof SCHEMA>) => {
if (schema.name === "entity") { if (schema.name === "entity") {
return this.hass!.localize( return this.hass!.localize(
"ui.panel.lovelace.editor.card.generic.entity" "ui.panel.lovelace.editor.card.generic.entity"

View File

@ -3,7 +3,7 @@ import { html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { assert, assign, object, optional, string } from "superstruct"; import { assert, assign, object, optional, string } from "superstruct";
import { fireEvent } from "../../../../common/dom/fire_event"; 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 { HomeAssistant } from "../../../../types";
import type { ThermostatCardConfig } from "../../cards/types"; import type { ThermostatCardConfig } from "../../cards/types";
import type { LovelaceCardEditor } from "../../types"; import type { LovelaceCardEditor } from "../../types";
@ -18,7 +18,7 @@ const cardConfigStruct = assign(
}) })
); );
const SCHEMA: HaFormSchema[] = [ const SCHEMA = [
{ name: "entity", selector: { entity: { domain: "climate" } } }, { name: "entity", selector: { entity: { domain: "climate" } } },
{ {
type: "grid", type: "grid",
@ -28,7 +28,7 @@ const SCHEMA: HaFormSchema[] = [
{ name: "theme", required: false, selector: { theme: {} } }, { name: "theme", required: false, selector: { theme: {} } },
], ],
}, },
]; ] as const;
@customElement("hui-thermostat-card-editor") @customElement("hui-thermostat-card-editor")
export class HuiThermostatCardEditor export class HuiThermostatCardEditor
@ -64,7 +64,7 @@ export class HuiThermostatCardEditor
fireEvent(this, "config-changed", { config: ev.detail.value }); fireEvent(this, "config-changed", { config: ev.detail.value });
} }
private _computeLabelCallback = (schema: HaFormSchema) => { private _computeLabelCallback = (schema: SchemaUnion<typeof SCHEMA>) => {
if (schema.name === "entity") { if (schema.name === "entity") {
return this.hass!.localize( return this.hass!.localize(
"ui.panel.lovelace.editor.card.generic.entity" "ui.panel.lovelace.editor.card.generic.entity"