mirror of
https://github.com/home-assistant/frontend.git
synced 2026-12-04 10:40:30 +00:00
Compare commits
5
Commits
hac-release-prep
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2cdd31284c | ||
|
|
251e7efd99 | ||
|
|
b57d2f1b4b | ||
|
|
65f0425cf8 | ||
|
|
3a59d8c47d |
No files matched your search
@@ -81,36 +81,11 @@ export class HaSelectSelector extends LitElement {
|
||||
}
|
||||
|
||||
protected render() {
|
||||
const options = this._getOptions(this.selector);
|
||||
|
||||
const translationKey = this.selector.select?.translation_key;
|
||||
|
||||
if (this.localizeValue && translationKey) {
|
||||
options.forEach((option) => {
|
||||
const localizedLabel = this.localizeValue!(
|
||||
`${translationKey}.options.${option.value}`
|
||||
);
|
||||
if (localizedLabel) {
|
||||
option.label = localizedLabel;
|
||||
}
|
||||
const localizedDescription = this.localizeValue!(
|
||||
`${translationKey}.options_description.${option.value}`
|
||||
);
|
||||
if (localizedDescription) {
|
||||
option.description = localizedDescription;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (this.selector.select?.sort) {
|
||||
options.sort((a, b) =>
|
||||
caseInsensitiveStringCompare(
|
||||
a.label,
|
||||
b.label,
|
||||
this._i18n.locale.language
|
||||
)
|
||||
);
|
||||
}
|
||||
const options = this._getOptions(
|
||||
this.selector,
|
||||
this.localizeValue,
|
||||
this._i18n
|
||||
);
|
||||
|
||||
if (
|
||||
!this.selector.select?.multiple &&
|
||||
@@ -325,12 +300,45 @@ export class HaSelectSelector extends LitElement {
|
||||
}
|
||||
|
||||
private _getOptions = memoizeOne(
|
||||
(selector: SelectSelector) =>
|
||||
selector.select?.options?.map((option) =>
|
||||
typeof option === "object"
|
||||
? { ...option, label: option.label ?? option.value }
|
||||
: { value: String(option), label: option }
|
||||
) || []
|
||||
(
|
||||
selector: SelectSelector,
|
||||
localizeValue: ((key: string) => string) | undefined,
|
||||
i18n: HomeAssistantInternationalization
|
||||
) => {
|
||||
const translationKey = selector.select?.translation_key;
|
||||
|
||||
const options = (selector.select?.options ?? []).map((option) => {
|
||||
const baseOption =
|
||||
typeof option === "object"
|
||||
? { ...option, label: option.label ?? option.value }
|
||||
: { value: String(option), label: option };
|
||||
|
||||
if (!localizeValue || !translationKey) {
|
||||
return baseOption;
|
||||
}
|
||||
|
||||
const localizedLabel = localizeValue(
|
||||
`${translationKey}.options.${baseOption.value}`
|
||||
);
|
||||
const localizedDescription = localizeValue(
|
||||
`${translationKey}.options_description.${baseOption.value}`
|
||||
);
|
||||
|
||||
return {
|
||||
...baseOption,
|
||||
label: localizedLabel || baseOption.label,
|
||||
description: localizedDescription || baseOption.description,
|
||||
};
|
||||
});
|
||||
|
||||
if (selector.select?.sort) {
|
||||
options.sort((a, b) =>
|
||||
caseInsensitiveStringCompare(a.label, b.label, i18n.locale.language)
|
||||
);
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
);
|
||||
|
||||
private _getItems = memoizeOne(
|
||||
@@ -470,7 +478,12 @@ export class HaSelectSelector extends LitElement {
|
||||
}
|
||||
|
||||
// Look the pick up in the current options: the open list can be older.
|
||||
const option = findPickerOption(this._getOptions(this.selector), id);
|
||||
const options = this._getOptions(
|
||||
this.selector,
|
||||
this.localizeValue,
|
||||
this._i18n
|
||||
);
|
||||
const option = findPickerOption(options, id);
|
||||
|
||||
if (
|
||||
!option ||
|
||||
|
||||
@@ -52,22 +52,21 @@ const iconSchema = {
|
||||
context: { icon_entity: "entity" },
|
||||
} as const satisfies HaFormSchema;
|
||||
|
||||
export const alertCardContentSchema = (localize: LocalizeFunc) =>
|
||||
({
|
||||
name: "content",
|
||||
type: "expandable",
|
||||
flatten: true,
|
||||
iconPath: mdiTextShort,
|
||||
schema: [
|
||||
nameSchema,
|
||||
{
|
||||
name: "",
|
||||
type: "grid",
|
||||
schema: [iconSchema, { name: "hide_state", selector: { boolean: {} } }],
|
||||
},
|
||||
contentLayoutSchema(localize),
|
||||
],
|
||||
}) as const satisfies HaFormSchema;
|
||||
export const alertCardContentSchema = {
|
||||
name: "content",
|
||||
type: "expandable",
|
||||
flatten: true,
|
||||
iconPath: mdiTextShort,
|
||||
schema: [
|
||||
nameSchema,
|
||||
{
|
||||
name: "",
|
||||
type: "grid",
|
||||
schema: [iconSchema, { name: "hide_state", selector: { boolean: {} } }],
|
||||
},
|
||||
contentLayoutSchema,
|
||||
],
|
||||
} as const satisfies HaFormSchema;
|
||||
|
||||
export const alertBadgeContentSchema = (localize: LocalizeFunc) =>
|
||||
({
|
||||
|
||||
@@ -27,29 +27,7 @@ const colorSchema = {
|
||||
},
|
||||
} as const satisfies HaFormSchema;
|
||||
|
||||
export const contentLayoutSchema = (localize: LocalizeFunc) =>
|
||||
({
|
||||
name: "content_layout",
|
||||
required: true,
|
||||
selector: {
|
||||
select: {
|
||||
mode: "box",
|
||||
options: ["horizontal", "vertical"].map((value) => ({
|
||||
label: localize(
|
||||
`ui.panel.lovelace.editor.card.tile.content_layout_options.${value}`
|
||||
),
|
||||
value,
|
||||
image: {
|
||||
src: `/static/images/form/tile_content_layout_${value}.svg`,
|
||||
src_dark: `/static/images/form/tile_content_layout_${value}_dark.svg`,
|
||||
flip_rtl: true,
|
||||
},
|
||||
})),
|
||||
},
|
||||
},
|
||||
}) as const satisfies HaFormSchema;
|
||||
|
||||
const tileContentLayoutSchema = {
|
||||
export const contentLayoutSchema = {
|
||||
name: "content_layout",
|
||||
required: true,
|
||||
selector: {
|
||||
@@ -144,7 +122,7 @@ export const tileContentSchema = (showTimeFormat: boolean) =>
|
||||
ui_time_format: {},
|
||||
},
|
||||
},
|
||||
tileContentLayoutSchema,
|
||||
contentLayoutSchema,
|
||||
],
|
||||
}) as const satisfies HaFormSchema;
|
||||
|
||||
|
||||
@@ -6,13 +6,11 @@ import { fireEvent } from "../../../../common/dom/fire_event";
|
||||
import { ALERT_DOMAINS } from "../../../../common/entity/alert_active";
|
||||
import type { LocalizeFunc } from "../../../../common/translations/localize";
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
import type {
|
||||
HaFormSchema,
|
||||
SchemaUnion,
|
||||
} from "../../../../components/ha-form/types";
|
||||
import type { HaFormSchema } from "../../../../components/ha-form/types";
|
||||
import type { HomeAssistant, ValueChangedEvent } from "../../../../types";
|
||||
import type { AlertCardConfig } from "../../cards/types";
|
||||
import type { LovelaceCardEditor } from "../../types";
|
||||
import { editorTranslations } from "../editor-translations";
|
||||
import { actionConfigStruct } from "../structs/action-struct";
|
||||
import { baseLovelaceCardConfig } from "../structs/base-card-struct";
|
||||
import { entityNameStruct } from "../structs/entity-name-struct";
|
||||
@@ -40,6 +38,17 @@ const cardConfigStruct = assign(
|
||||
})
|
||||
);
|
||||
|
||||
const SCHEMA = [
|
||||
{
|
||||
name: "entity",
|
||||
required: true,
|
||||
selector: { entity: { filter: { domain: ALERT_DOMAINS } } },
|
||||
},
|
||||
alertSchema(),
|
||||
alertCardContentSchema,
|
||||
entityInteractionsSchema(),
|
||||
] as const satisfies readonly HaFormSchema[];
|
||||
|
||||
@customElement("hui-alert-card-editor")
|
||||
export class HuiAlertCardEditor
|
||||
extends LitElement
|
||||
@@ -54,18 +63,8 @@ export class HuiAlertCardEditor
|
||||
this._config = config;
|
||||
}
|
||||
|
||||
private _schema = memoizeOne(
|
||||
(localize: LocalizeFunc) =>
|
||||
[
|
||||
{
|
||||
name: "entity",
|
||||
required: true,
|
||||
selector: { entity: { filter: { domain: ALERT_DOMAINS } } },
|
||||
},
|
||||
alertSchema(),
|
||||
alertCardContentSchema(localize),
|
||||
entityInteractionsSchema(),
|
||||
] as const satisfies readonly HaFormSchema[]
|
||||
private _translations = memoizeOne((localize: LocalizeFunc) =>
|
||||
editorTranslations(localize, "ui.panel.lovelace.editor.card.alert")
|
||||
);
|
||||
|
||||
protected render() {
|
||||
@@ -73,13 +72,16 @@ export class HuiAlertCardEditor
|
||||
return nothing;
|
||||
}
|
||||
|
||||
const translations = this._translations(this.hass.localize);
|
||||
|
||||
return html`
|
||||
<ha-form
|
||||
.hass=${this.hass}
|
||||
.data=${tileContentFormData(this._config)}
|
||||
.schema=${this._schema(this.hass.localize)}
|
||||
.computeLabel=${this._computeLabelCallback}
|
||||
.computeHelper=${this._computeHelperCallback}
|
||||
.schema=${SCHEMA}
|
||||
.computeLabel=${translations.computeLabel}
|
||||
.computeHelper=${translations.computeHelper}
|
||||
.localizeValue=${translations.localizeValue}
|
||||
@value-changed=${this._valueChanged}
|
||||
></ha-form>
|
||||
`;
|
||||
@@ -92,48 +94,6 @@ export class HuiAlertCardEditor
|
||||
|
||||
fireEvent(this, "config-changed", { config });
|
||||
}
|
||||
|
||||
private _computeLabelCallback = (
|
||||
schema: SchemaUnion<ReturnType<typeof this._schema>>
|
||||
) => {
|
||||
switch (schema.name) {
|
||||
case "pulse":
|
||||
case "alert_color":
|
||||
case "clear_color":
|
||||
return this.hass!.localize(
|
||||
`ui.panel.lovelace.editor.card.alert.${schema.name}`
|
||||
);
|
||||
case "alert":
|
||||
return this.hass!.localize(
|
||||
"ui.panel.lovelace.editor.card.alert.alert_section"
|
||||
);
|
||||
case "hide_state":
|
||||
case "content_layout":
|
||||
return this.hass!.localize(
|
||||
`ui.panel.lovelace.editor.card.tile.${schema.name}`
|
||||
);
|
||||
default:
|
||||
return this.hass!.localize(
|
||||
`ui.panel.lovelace.editor.card.generic.${schema.name}`
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
private _computeHelperCallback = (
|
||||
schema: SchemaUnion<ReturnType<typeof this._schema>>
|
||||
) => {
|
||||
if (
|
||||
schema.name === "pulse" ||
|
||||
schema.name === "alert_color" ||
|
||||
schema.name === "clear_color"
|
||||
) {
|
||||
return this.hass?.localize(
|
||||
`ui.panel.lovelace.editor.card.alert.${schema.name}_helper`
|
||||
);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
};
|
||||
}
|
||||
|
||||
declare global {
|
||||
|
||||
@@ -24,10 +24,7 @@ import { getEntityIds } from "../../../../common/entity/get_entity_ids";
|
||||
import { caseInsensitiveStringCompare } from "../../../../common/string/compare";
|
||||
import type { LocalizeFunc } from "../../../../common/translations/localize";
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
import type {
|
||||
HaFormSchema,
|
||||
SchemaUnion,
|
||||
} from "../../../../components/ha-form/types";
|
||||
import type { HaFormSchema } from "../../../../components/ha-form/types";
|
||||
import {
|
||||
internationalizationContext,
|
||||
registriesContext,
|
||||
@@ -49,11 +46,12 @@ import {
|
||||
SUM_DEVICE_CLASSES,
|
||||
type AreaCardFeatureContext,
|
||||
} from "../../cards/hui-area-card";
|
||||
import type { AreaCardConfig, AreaCardDisplayType } from "../../cards/types";
|
||||
import type { AreaCardConfig } from "../../cards/types";
|
||||
import type { LovelaceCardEditor } from "../../types";
|
||||
import { actionConfigStruct } from "../structs/action-struct";
|
||||
import { ACTION_RELATED_CONTEXT } from "../../components/hui-action-editor";
|
||||
import { baseLovelaceCardConfig } from "../structs/base-card-struct";
|
||||
import { editorTranslations } from "../editor-translations";
|
||||
import type { EditDetailElementEvent, EditSubElementEvent } from "../types";
|
||||
import { configElementStyle } from "./config-elements-style";
|
||||
import { getSupportedFeaturesType } from "./hui-card-features-editor";
|
||||
@@ -109,8 +107,7 @@ export class HuiAreaCardEditor
|
||||
|
||||
private _schema = memoizeOne(
|
||||
(
|
||||
localize: LocalizeFunc,
|
||||
displayType: AreaCardDisplayType,
|
||||
camera: boolean,
|
||||
binaryClasses: SelectOption[],
|
||||
sensorClasses: SelectOption[]
|
||||
) =>
|
||||
@@ -133,57 +130,35 @@ export class HuiAreaCardEditor
|
||||
required: true,
|
||||
selector: {
|
||||
select: {
|
||||
options: ["compact", "icon", "picture", "camera"].map(
|
||||
(value) => ({
|
||||
value,
|
||||
label: localize(
|
||||
`ui.panel.lovelace.editor.card.area.display_type_options.${value}`
|
||||
),
|
||||
})
|
||||
),
|
||||
translation_key: "display_type",
|
||||
options: ["compact", "icon", "picture", "camera"],
|
||||
mode: "dropdown",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "content_layout",
|
||||
required: true,
|
||||
visible: { field: "display_type", value: "compact" },
|
||||
selector: {
|
||||
select: {
|
||||
mode: "dropdown",
|
||||
translation_key: "content_layout",
|
||||
options: ["horizontal", "vertical"],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "camera_view",
|
||||
visible: { field: "display_type", value: "camera" },
|
||||
selector: {
|
||||
select: {
|
||||
translation_key: "camera_view",
|
||||
options: ["auto", "live"],
|
||||
mode: "dropdown",
|
||||
},
|
||||
},
|
||||
},
|
||||
...(displayType === "compact"
|
||||
? ([
|
||||
{
|
||||
name: "content_layout",
|
||||
required: true,
|
||||
selector: {
|
||||
select: {
|
||||
mode: "dropdown",
|
||||
options: ["horizontal", "vertical"].map(
|
||||
(value) => ({
|
||||
label: localize(
|
||||
`ui.panel.lovelace.editor.card.area.content_layout_options.${value}`
|
||||
),
|
||||
value,
|
||||
})
|
||||
),
|
||||
},
|
||||
},
|
||||
},
|
||||
] as const satisfies readonly HaFormSchema[])
|
||||
: []),
|
||||
...(displayType === "camera"
|
||||
? ([
|
||||
{
|
||||
name: "camera_view",
|
||||
selector: {
|
||||
select: {
|
||||
options: ["auto", "live"].map((value) => ({
|
||||
value,
|
||||
label: localize(
|
||||
`ui.panel.lovelace.editor.card.generic.camera_view_options.${value}`
|
||||
),
|
||||
})),
|
||||
mode: "dropdown",
|
||||
},
|
||||
},
|
||||
},
|
||||
] as const satisfies readonly HaFormSchema[])
|
||||
: []),
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -226,35 +201,32 @@ export class HuiAreaCardEditor
|
||||
},
|
||||
context: ACTION_RELATED_CONTEXT,
|
||||
},
|
||||
...(displayType !== "compact"
|
||||
? ([
|
||||
{
|
||||
name: "image_tap_action",
|
||||
selector: {
|
||||
ui_action: {
|
||||
default_action:
|
||||
displayType === "camera" ? "more-info" : "none",
|
||||
actions:
|
||||
displayType === "camera"
|
||||
? [
|
||||
"more-info",
|
||||
"navigate",
|
||||
"url",
|
||||
"perform-action",
|
||||
"none",
|
||||
]
|
||||
: ["navigate", "url", "perform-action", "none"],
|
||||
},
|
||||
},
|
||||
context: ACTION_RELATED_CONTEXT,
|
||||
},
|
||||
] as const satisfies readonly HaFormSchema[])
|
||||
: []),
|
||||
{
|
||||
name: "image_tap_action",
|
||||
visible: {
|
||||
field: "display_type",
|
||||
operator: "not_eq",
|
||||
value: "compact",
|
||||
},
|
||||
selector: {
|
||||
ui_action: {
|
||||
default_action: camera ? "more-info" : "none",
|
||||
actions: camera
|
||||
? ["more-info", "navigate", "url", "perform-action", "none"]
|
||||
: ["navigate", "url", "perform-action", "none"],
|
||||
},
|
||||
},
|
||||
context: ACTION_RELATED_CONTEXT,
|
||||
},
|
||||
],
|
||||
},
|
||||
] as const satisfies readonly HaFormSchema[]
|
||||
);
|
||||
|
||||
private _translations = memoizeOne((localize: LocalizeFunc) =>
|
||||
editorTranslations(localize, "ui.panel.lovelace.editor.card.area")
|
||||
);
|
||||
|
||||
private _binaryClassesForArea = memoizeOne(
|
||||
(
|
||||
states: HassEntityStates,
|
||||
@@ -413,7 +385,7 @@ export class HuiAreaCardEditor
|
||||
}
|
||||
|
||||
private _featuresSchema = memoizeOne(
|
||||
(localize: LocalizeFunc, vertical: boolean) =>
|
||||
(vertical: boolean) =>
|
||||
[
|
||||
{
|
||||
name: "features_position",
|
||||
@@ -421,13 +393,8 @@ export class HuiAreaCardEditor
|
||||
selector: {
|
||||
select: {
|
||||
mode: "box",
|
||||
translation_key: "features_position",
|
||||
options: ["bottom", "inline"].map((value) => ({
|
||||
label: localize(
|
||||
`ui.panel.lovelace.editor.card.tile.features_position_options.${value}`
|
||||
),
|
||||
description: localize(
|
||||
`ui.panel.lovelace.editor.card.tile.features_position_options.${value}_description`
|
||||
),
|
||||
value,
|
||||
image: {
|
||||
src: `/static/images/form/tile_features_position_${value}.svg`,
|
||||
@@ -495,15 +462,16 @@ export class HuiAreaCardEditor
|
||||
(this._config.show_camera ? "camera" : "picture");
|
||||
|
||||
const schema = this._schema(
|
||||
localize,
|
||||
displayType,
|
||||
displayType === "camera",
|
||||
binarySelectOptions,
|
||||
sensorSelectOptions
|
||||
);
|
||||
|
||||
const vertical = this._config.vertical && displayType === "compact";
|
||||
|
||||
const featuresSchema = this._featuresSchema(localize, Boolean(vertical));
|
||||
const featuresSchema = this._featuresSchema(Boolean(vertical));
|
||||
|
||||
const translations = this._translations(localize);
|
||||
|
||||
const data = {
|
||||
camera_view: "auto",
|
||||
@@ -536,8 +504,9 @@ export class HuiAreaCardEditor
|
||||
.hass=${this.hass}
|
||||
.data=${data}
|
||||
.schema=${schema}
|
||||
.computeLabel=${this._computeLabelCallback}
|
||||
.computeHelper=${this._computeHelperCallback}
|
||||
.computeLabel=${translations.computeLabel}
|
||||
.computeHelper=${translations.computeHelper}
|
||||
.localizeValue=${translations.localizeValue}
|
||||
@value-changed=${this._valueChanged}
|
||||
></ha-form>
|
||||
<ha-expansion-panel outlined>
|
||||
@@ -553,7 +522,9 @@ export class HuiAreaCardEditor
|
||||
class="features-form"
|
||||
.data=${data}
|
||||
.schema=${featuresSchema}
|
||||
.computeLabel=${this._computeLabelCallback}
|
||||
.computeLabel=${translations.computeLabel}
|
||||
.computeHelper=${translations.computeHelper}
|
||||
.localizeValue=${translations.localizeValue}
|
||||
@value-changed=${this._valueChanged}
|
||||
></ha-form>
|
||||
`
|
||||
@@ -651,54 +622,6 @@ export class HuiAreaCardEditor
|
||||
});
|
||||
}
|
||||
|
||||
private _computeHelperCallback = (
|
||||
schema:
|
||||
| SchemaUnion<ReturnType<typeof this._schema>>
|
||||
| SchemaUnion<ReturnType<typeof this._featuresSchema>>
|
||||
): string | undefined => {
|
||||
switch (schema.name) {
|
||||
case "alert_classes":
|
||||
if (this._config?.display_type === "compact") {
|
||||
return this._i18n.localize(
|
||||
`ui.panel.lovelace.editor.card.area.alert_classes_helper`
|
||||
);
|
||||
}
|
||||
return undefined;
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
private _computeLabelCallback = (
|
||||
schema:
|
||||
| SchemaUnion<ReturnType<typeof this._schema>>
|
||||
| SchemaUnion<ReturnType<typeof this._featuresSchema>>
|
||||
) => {
|
||||
switch (schema.name) {
|
||||
case "area":
|
||||
return this._i18n.localize("ui.panel.lovelace.editor.card.area.name");
|
||||
case "name":
|
||||
case "camera_view":
|
||||
case "content":
|
||||
case "interactions":
|
||||
case "tap_action":
|
||||
return this._i18n.localize(
|
||||
`ui.panel.lovelace.editor.card.generic.${schema.name}`
|
||||
);
|
||||
case "image_tap_action":
|
||||
return this._i18n.localize(
|
||||
`ui.panel.lovelace.editor.card.area.${schema.name}`
|
||||
);
|
||||
case "features_position":
|
||||
return this._i18n.localize(
|
||||
`ui.panel.lovelace.editor.card.tile.${schema.name}`
|
||||
);
|
||||
}
|
||||
return this._i18n.localize(
|
||||
`ui.panel.lovelace.editor.card.area.${schema.name}`
|
||||
);
|
||||
};
|
||||
|
||||
static get styles() {
|
||||
return [
|
||||
configElementStyle,
|
||||
|
||||
@@ -16,10 +16,11 @@ import { consumeLocalize } from "../../../../common/decorators/consume-context-e
|
||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||
import type { LocalizeFunc } from "../../../../common/translations/localize";
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
import type { SchemaUnion } from "../../../../components/ha-form/types";
|
||||
import type { HaFormSchema } from "../../../../components/ha-form/types";
|
||||
import { DEFAULT_HOURS_TO_SHOW } from "../../cards/hui-sensor-card";
|
||||
import type { SensorCardConfig } from "../../cards/types";
|
||||
import type { LovelaceCardEditor } from "../../types";
|
||||
import { editorTranslations } from "../editor-translations";
|
||||
import { baseLovelaceCardConfig } from "../structs/base-card-struct";
|
||||
import { entityNameStruct } from "../structs/entity-name-struct";
|
||||
import { configElementStyle } from "./config-elements-style";
|
||||
@@ -45,6 +46,76 @@ const cardConfigStruct = assign(
|
||||
})
|
||||
);
|
||||
|
||||
const SCHEMA = [
|
||||
{
|
||||
name: "entity",
|
||||
selector: {
|
||||
entity: { domain: ["counter", "input_number", "number", "sensor"] },
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "name",
|
||||
selector: {
|
||||
entity_name: {},
|
||||
},
|
||||
context: { entity: "entity" },
|
||||
},
|
||||
{
|
||||
type: "grid",
|
||||
name: "",
|
||||
schema: [
|
||||
{
|
||||
name: "icon",
|
||||
selector: {
|
||||
icon: {},
|
||||
},
|
||||
context: {
|
||||
icon_entity: "entity",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "color",
|
||||
selector: {
|
||||
ui_color: {
|
||||
include_state: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "graph",
|
||||
selector: {
|
||||
select: {
|
||||
translation_key: "graph",
|
||||
options: ["none", "line"],
|
||||
},
|
||||
},
|
||||
},
|
||||
{ name: "unit", selector: { text: {} } },
|
||||
{ name: "detail", selector: { boolean: {} } },
|
||||
{ name: "theme", selector: { theme: {} } },
|
||||
{
|
||||
name: "hours_to_show",
|
||||
default: DEFAULT_HOURS_TO_SHOW,
|
||||
selector: { number: { min: 1, mode: "box" } },
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: "grid",
|
||||
name: "limits",
|
||||
schema: [
|
||||
{
|
||||
name: "min",
|
||||
selector: { number: { mode: "box", step: "any" } },
|
||||
},
|
||||
{
|
||||
name: "max",
|
||||
selector: { number: { mode: "box", step: "any" } },
|
||||
},
|
||||
],
|
||||
},
|
||||
] as const satisfies readonly HaFormSchema[];
|
||||
|
||||
@customElement("hui-sensor-card-editor")
|
||||
export class HuiSensorCardEditor
|
||||
extends LitElement
|
||||
@@ -60,81 +131,8 @@ export class HuiSensorCardEditor
|
||||
this._config = config;
|
||||
}
|
||||
|
||||
private _schema = memoizeOne(
|
||||
(localize: LocalizeFunc) =>
|
||||
[
|
||||
{
|
||||
name: "entity",
|
||||
selector: {
|
||||
entity: { domain: ["counter", "input_number", "number", "sensor"] },
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "name",
|
||||
selector: {
|
||||
entity_name: {},
|
||||
},
|
||||
context: { entity: "entity" },
|
||||
},
|
||||
{
|
||||
type: "grid",
|
||||
name: "",
|
||||
schema: [
|
||||
{
|
||||
name: "icon",
|
||||
selector: {
|
||||
icon: {},
|
||||
},
|
||||
context: {
|
||||
icon_entity: "entity",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "color",
|
||||
selector: {
|
||||
ui_color: {
|
||||
include_state: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "graph",
|
||||
selector: {
|
||||
select: {
|
||||
options: ["none", "line"].map((value) => ({
|
||||
value,
|
||||
label: localize(
|
||||
`ui.panel.lovelace.editor.card.sensor.graph_options.${value}`
|
||||
),
|
||||
})),
|
||||
},
|
||||
},
|
||||
},
|
||||
{ name: "unit", selector: { text: {} } },
|
||||
{ name: "detail", selector: { boolean: {} } },
|
||||
{ name: "theme", selector: { theme: {} } },
|
||||
{
|
||||
name: "hours_to_show",
|
||||
default: DEFAULT_HOURS_TO_SHOW,
|
||||
selector: { number: { min: 1, mode: "box" } },
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: "grid",
|
||||
name: "limits",
|
||||
schema: [
|
||||
{
|
||||
name: "min",
|
||||
selector: { number: { mode: "box", step: "any" } },
|
||||
},
|
||||
{
|
||||
name: "max",
|
||||
selector: { number: { mode: "box", step: "any" } },
|
||||
},
|
||||
],
|
||||
},
|
||||
] as const
|
||||
private _translations = memoizeOne((localize: LocalizeFunc) =>
|
||||
editorTranslations(localize, "ui.panel.lovelace.editor.card.sensor")
|
||||
);
|
||||
|
||||
protected render() {
|
||||
@@ -148,65 +146,26 @@ export class HuiSensorCardEditor
|
||||
detail: this._config!.detail === 2,
|
||||
};
|
||||
|
||||
const translations = this._translations(this._localize);
|
||||
|
||||
return html`
|
||||
<ha-form
|
||||
.data=${data}
|
||||
.schema=${this._schema(this._localize)}
|
||||
.computeLabel=${this._computeLabelCallback}
|
||||
.computeHelper=${this._computeHelperCallback}
|
||||
.schema=${SCHEMA}
|
||||
.computeLabel=${translations.computeLabel}
|
||||
.computeHelper=${translations.computeHelper}
|
||||
.localizeValue=${translations.localizeValue}
|
||||
@value-changed=${this._valueChanged}
|
||||
></ha-form>
|
||||
`;
|
||||
}
|
||||
|
||||
private _computeHelperCallback = (
|
||||
schema: SchemaUnion<ReturnType<typeof this._schema>>
|
||||
) => {
|
||||
switch (schema.name) {
|
||||
case "color":
|
||||
return this._localize(
|
||||
`ui.panel.lovelace.editor.card.tile.${schema.name}_helper`
|
||||
);
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
private _valueChanged(ev: CustomEvent): void {
|
||||
const config = ev.detail.value;
|
||||
config.detail = config.detail ? 2 : 1;
|
||||
fireEvent(this, "config-changed", { config });
|
||||
}
|
||||
|
||||
private _computeLabelCallback = (
|
||||
schema: SchemaUnion<ReturnType<typeof this._schema>>
|
||||
) => {
|
||||
switch (schema.name) {
|
||||
case "theme":
|
||||
return `${this._localize(
|
||||
"ui.panel.lovelace.editor.card.generic.theme"
|
||||
)} (${this._localize(
|
||||
"ui.panel.lovelace.editor.card.config.optional"
|
||||
)})`;
|
||||
case "detail":
|
||||
return this._localize(
|
||||
"ui.panel.lovelace.editor.card.sensor.show_more_detail"
|
||||
);
|
||||
case "graph":
|
||||
return this._localize(
|
||||
"ui.panel.lovelace.editor.card.sensor.graph_type"
|
||||
);
|
||||
case "min":
|
||||
return this._localize("ui.panel.lovelace.editor.card.sensor.limit_min");
|
||||
case "max":
|
||||
return this._localize("ui.panel.lovelace.editor.card.sensor.limit_max");
|
||||
default:
|
||||
return this._localize(
|
||||
`ui.panel.lovelace.editor.card.generic.${schema.name}`
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
static get styles(): CSSResultGroup {
|
||||
return configElementStyle;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import { getShortcutCardDefaults } from "../../cards/hui-shortcut-card-defaults"
|
||||
import type { ShortcutCardConfig } from "../../cards/types";
|
||||
import type { UiAction } from "../../components/hui-action-editor";
|
||||
import type { LovelaceCardEditor } from "../../types";
|
||||
import { editorTranslations } from "../editor-translations";
|
||||
import { actionConfigStruct } from "../structs/action-struct";
|
||||
import { baseLovelaceCardConfig } from "../structs/base-card-struct";
|
||||
import { configElementStyle } from "./config-elements-style";
|
||||
@@ -73,7 +74,7 @@ export class HuiShortcutCardEditor
|
||||
}
|
||||
|
||||
private _schema = memoizeOne(
|
||||
(localize: LocalizeFunc, label: string, icon?: string) =>
|
||||
(label: string, icon?: string) =>
|
||||
[
|
||||
{
|
||||
name: "tap_action",
|
||||
@@ -133,10 +134,8 @@ export class HuiShortcutCardEditor
|
||||
selector: {
|
||||
select: {
|
||||
mode: "box",
|
||||
translation_key: "content_layout",
|
||||
options: ["horizontal", "vertical"].map((value) => ({
|
||||
label: localize(
|
||||
`ui.panel.lovelace.editor.card.tile.content_layout_options.${value}`
|
||||
),
|
||||
value,
|
||||
image: {
|
||||
src: `/static/images/form/tile_content_layout_${value}.svg`,
|
||||
@@ -182,6 +181,10 @@ export class HuiShortcutCardEditor
|
||||
] as const satisfies readonly HaFormSchema[]
|
||||
);
|
||||
|
||||
private _translations = memoizeOne((localize: LocalizeFunc) =>
|
||||
editorTranslations(localize, "ui.panel.lovelace.editor.card.shortcut")
|
||||
);
|
||||
|
||||
protected render() {
|
||||
if (!this.hass || !this._config) {
|
||||
return nothing;
|
||||
@@ -194,6 +197,8 @@ export class HuiShortcutCardEditor
|
||||
this._serviceInfo.info
|
||||
);
|
||||
|
||||
const translations = this._translations(this.hass.localize);
|
||||
|
||||
const data = {
|
||||
...this._config,
|
||||
content_layout: this._config.vertical ? "vertical" : "horizontal",
|
||||
@@ -203,12 +208,10 @@ export class HuiShortcutCardEditor
|
||||
<ha-form
|
||||
.hass=${this.hass}
|
||||
.data=${data}
|
||||
.schema=${this._schema(
|
||||
this.hass.localize,
|
||||
defaults.label,
|
||||
defaults.icon
|
||||
)}
|
||||
.computeLabel=${this._computeLabelCallback}
|
||||
.schema=${this._schema(defaults.label, defaults.icon)}
|
||||
.computeLabel=${translations.computeLabel}
|
||||
.computeHelper=${translations.computeHelper}
|
||||
.localizeValue=${translations.localizeValue}
|
||||
@value-changed=${this._valueChanged}
|
||||
></ha-form>
|
||||
`;
|
||||
@@ -232,25 +235,6 @@ export class HuiShortcutCardEditor
|
||||
fireEvent(this, "config-changed", { config });
|
||||
}
|
||||
|
||||
private _computeLabelCallback = (schema: HaFormSchema) => {
|
||||
switch (schema.name) {
|
||||
case "label":
|
||||
case "content_layout":
|
||||
case "additional_interactions":
|
||||
return this.hass!.localize(
|
||||
`ui.panel.lovelace.editor.card.shortcut.${schema.name}`
|
||||
);
|
||||
case "description":
|
||||
return this.hass!.localize(
|
||||
"ui.panel.lovelace.editor.card.shortcut.card_description"
|
||||
);
|
||||
default:
|
||||
return this.hass!.localize(
|
||||
`ui.panel.lovelace.editor.card.generic.${schema.name}`
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
static styles = configElementStyle;
|
||||
}
|
||||
|
||||
|
||||
+147
-4
@@ -11505,7 +11505,44 @@
|
||||
"clear_color_helper": "Used when the entity isn't in an alert state. The background doesn't pulse.",
|
||||
"pulse": "Pulse",
|
||||
"pulse_helper": "Animates the colored background while the entity is in an alert state. When reduced motion is on, the background stays tinted instead.",
|
||||
"alert_section": "Alert"
|
||||
"alert_section": "Alert",
|
||||
"sections": {
|
||||
"alert": {
|
||||
"name": "[%key:ui::panel::lovelace::editor::card::alert::alert_section%]"
|
||||
},
|
||||
"content": {
|
||||
"name": "[%key:ui::panel::lovelace::editor::card::generic::content%]"
|
||||
},
|
||||
"interactions": {
|
||||
"name": "[%key:ui::panel::lovelace::editor::card::generic::interactions%]"
|
||||
}
|
||||
},
|
||||
"data": {
|
||||
"entity": "[%key:ui::panel::lovelace::editor::card::generic::entity%]",
|
||||
"clear_color": "[%key:ui::panel::lovelace::editor::card::alert::clear_color%]",
|
||||
"alert_color": "[%key:ui::panel::lovelace::editor::card::alert::alert_color%]",
|
||||
"pulse": "[%key:ui::panel::lovelace::editor::card::alert::pulse%]",
|
||||
"name": "[%key:ui::panel::lovelace::editor::card::generic::name%]",
|
||||
"icon": "[%key:ui::panel::lovelace::editor::card::generic::icon%]",
|
||||
"hide_state": "[%key:ui::panel::lovelace::editor::card::tile::hide_state%]",
|
||||
"content_layout": "[%key:ui::panel::lovelace::editor::card::tile::content_layout%]",
|
||||
"tap_action": "[%key:ui::panel::lovelace::editor::card::generic::tap_action%]",
|
||||
"hold_action": "[%key:ui::panel::lovelace::editor::card::generic::hold_action%]",
|
||||
"double_tap_action": "[%key:ui::panel::lovelace::editor::card::generic::double_tap_action%]"
|
||||
},
|
||||
"data_description": {
|
||||
"clear_color": "[%key:ui::panel::lovelace::editor::card::alert::clear_color_helper%]",
|
||||
"alert_color": "[%key:ui::panel::lovelace::editor::card::alert::alert_color_helper%]",
|
||||
"pulse": "[%key:ui::panel::lovelace::editor::card::alert::pulse_helper%]"
|
||||
},
|
||||
"selector": {
|
||||
"content_layout": {
|
||||
"options": {
|
||||
"horizontal": "[%key:ui::panel::lovelace::editor::card::tile::content_layout_options::horizontal%]",
|
||||
"vertical": "[%key:ui::panel::lovelace::editor::card::tile::content_layout_options::vertical%]"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"area": {
|
||||
"name": "Area",
|
||||
@@ -11528,7 +11565,63 @@
|
||||
"picture": "Area picture",
|
||||
"camera": "Camera feed"
|
||||
},
|
||||
"image_tap_action": "Image tap behavior"
|
||||
"image_tap_action": "Image tap behavior",
|
||||
"sections": {
|
||||
"content": {
|
||||
"name": "[%key:ui::panel::lovelace::editor::card::generic::content%]"
|
||||
},
|
||||
"interactions": {
|
||||
"name": "[%key:ui::panel::lovelace::editor::card::generic::interactions%]"
|
||||
}
|
||||
},
|
||||
"data": {
|
||||
"area": "[%key:ui::panel::lovelace::editor::card::area::name%]",
|
||||
"name": "[%key:ui::panel::lovelace::editor::card::generic::name%]",
|
||||
"color": "[%key:ui::panel::lovelace::editor::card::tile::color%]",
|
||||
"display_type": "[%key:ui::panel::lovelace::editor::card::area::display_type%]",
|
||||
"content_layout": "[%key:ui::panel::lovelace::editor::card::tile::content_layout%]",
|
||||
"camera_view": "[%key:ui::panel::lovelace::editor::card::generic::camera_view%]",
|
||||
"alert_classes": "[%key:ui::panel::lovelace::editor::card::area::alert_classes%]",
|
||||
"sensor_classes": "[%key:ui::panel::lovelace::editor::card::area::sensor_classes%]",
|
||||
"tap_action": "[%key:ui::panel::lovelace::editor::card::generic::tap_action%]",
|
||||
"image_tap_action": "[%key:ui::panel::lovelace::editor::card::area::image_tap_action%]",
|
||||
"features_position": "[%key:ui::panel::lovelace::editor::card::tile::features_position%]"
|
||||
},
|
||||
"data_description": {
|
||||
"alert_classes": "[%key:ui::panel::lovelace::editor::card::area::alert_classes_helper%]"
|
||||
},
|
||||
"selector": {
|
||||
"display_type": {
|
||||
"options": {
|
||||
"compact": "[%key:ui::panel::lovelace::editor::card::area::display_type_options::compact%]",
|
||||
"icon": "[%key:ui::panel::lovelace::editor::card::area::display_type_options::icon%]",
|
||||
"picture": "[%key:ui::panel::lovelace::editor::card::area::display_type_options::picture%]",
|
||||
"camera": "[%key:ui::panel::lovelace::editor::card::area::display_type_options::camera%]"
|
||||
}
|
||||
},
|
||||
"content_layout": {
|
||||
"options": {
|
||||
"horizontal": "[%key:ui::panel::lovelace::editor::card::tile::content_layout_options::horizontal%]",
|
||||
"vertical": "[%key:ui::panel::lovelace::editor::card::tile::content_layout_options::vertical%]"
|
||||
}
|
||||
},
|
||||
"camera_view": {
|
||||
"options": {
|
||||
"auto": "[%key:ui::panel::lovelace::editor::card::generic::camera_view_options::auto%]",
|
||||
"live": "[%key:ui::panel::lovelace::editor::card::generic::camera_view_options::live%]"
|
||||
}
|
||||
},
|
||||
"features_position": {
|
||||
"options": {
|
||||
"bottom": "[%key:ui::panel::lovelace::editor::card::tile::features_position_options::bottom%]",
|
||||
"inline": "[%key:ui::panel::lovelace::editor::card::tile::features_position_options::inline%]"
|
||||
},
|
||||
"options_description": {
|
||||
"bottom": "[%key:ui::panel::lovelace::editor::card::tile::features_position_options::bottom_description%]",
|
||||
"inline": "[%key:ui::panel::lovelace::editor::card::tile::features_position_options::inline_description%]"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"calendar": {
|
||||
"name": "Calendar",
|
||||
@@ -12076,7 +12169,33 @@
|
||||
"card_description": "Description",
|
||||
"text": "Text",
|
||||
"content_layout": "[%key:ui::panel::lovelace::editor::card::tile::content_layout%]",
|
||||
"additional_interactions": "Additional interactions"
|
||||
"additional_interactions": "Additional interactions",
|
||||
"sections": {
|
||||
"content": {
|
||||
"name": "[%key:ui::panel::lovelace::editor::card::generic::content%]"
|
||||
},
|
||||
"additional_interactions": {
|
||||
"name": "[%key:ui::panel::lovelace::editor::card::shortcut::additional_interactions%]"
|
||||
}
|
||||
},
|
||||
"data": {
|
||||
"tap_action": "[%key:ui::panel::lovelace::editor::card::generic::tap_action%]",
|
||||
"label": "[%key:ui::panel::lovelace::editor::card::shortcut::label%]",
|
||||
"description": "[%key:ui::panel::lovelace::editor::card::shortcut::card_description%]",
|
||||
"icon": "[%key:ui::panel::lovelace::editor::card::generic::icon%]",
|
||||
"color": "[%key:ui::panel::lovelace::editor::card::tile::color%]",
|
||||
"content_layout": "[%key:ui::panel::lovelace::editor::card::tile::content_layout%]",
|
||||
"hold_action": "[%key:ui::panel::lovelace::editor::card::generic::hold_action%]",
|
||||
"double_tap_action": "[%key:ui::panel::lovelace::editor::card::generic::double_tap_action%]"
|
||||
},
|
||||
"selector": {
|
||||
"content_layout": {
|
||||
"options": {
|
||||
"horizontal": "[%key:ui::panel::lovelace::editor::card::tile::content_layout_options::horizontal%]",
|
||||
"vertical": "[%key:ui::panel::lovelace::editor::card::tile::content_layout_options::vertical%]"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"map": {
|
||||
"name": "Map",
|
||||
@@ -12316,7 +12435,31 @@
|
||||
},
|
||||
"description": "This card gives you a quick overview of a sensor's state with an optional graph to visualize change over time.",
|
||||
"limit_min": "Minimum value",
|
||||
"limit_max": "Maximum value"
|
||||
"limit_max": "Maximum value",
|
||||
"data": {
|
||||
"entity": "[%key:ui::panel::lovelace::editor::card::generic::entity%]",
|
||||
"name": "[%key:ui::panel::lovelace::editor::card::generic::name%]",
|
||||
"icon": "[%key:ui::panel::lovelace::editor::card::generic::icon%]",
|
||||
"color": "[%key:ui::panel::lovelace::editor::card::tile::color%]",
|
||||
"graph": "[%key:ui::panel::lovelace::editor::card::sensor::graph_type%]",
|
||||
"unit": "[%key:ui::panel::lovelace::editor::card::generic::unit%]",
|
||||
"detail": "[%key:ui::panel::lovelace::editor::card::sensor::show_more_detail%]",
|
||||
"theme": "[%key:ui::panel::lovelace::editor::card::generic::theme%]",
|
||||
"hours_to_show": "[%key:ui::panel::lovelace::editor::card::generic::hours_to_show%]",
|
||||
"min": "[%key:ui::panel::lovelace::editor::card::sensor::limit_min%]",
|
||||
"max": "[%key:ui::panel::lovelace::editor::card::sensor::limit_max%]"
|
||||
},
|
||||
"data_description": {
|
||||
"color": "[%key:ui::panel::lovelace::editor::card::tile::color_helper%]"
|
||||
},
|
||||
"selector": {
|
||||
"graph": {
|
||||
"options": {
|
||||
"none": "[%key:ui::panel::lovelace::editor::card::sensor::graph_options::none%]",
|
||||
"line": "[%key:ui::panel::lovelace::editor::card::sensor::graph_options::line%]"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"timer-list": {
|
||||
"name": "Timer list",
|
||||
|
||||
Reference in new issue
Block a user