mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 00:06:35 +00:00
Camera view options translated (#25119)
* Camera view options translated * Swap around changes * Clean up * Clean up
This commit is contained in:
parent
713dd68089
commit
3647722824
@ -1,7 +1,9 @@
|
|||||||
|
import memoizeOne from "memoize-one";
|
||||||
import { mdiGestureTap } from "@mdi/js";
|
import { mdiGestureTap } from "@mdi/js";
|
||||||
import { html, LitElement, nothing } from "lit";
|
import { html, LitElement, nothing } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { any, assert, literal, object, optional, string } from "superstruct";
|
import { any, assert, literal, object, optional, string } from "superstruct";
|
||||||
|
import type { LocalizeFunc } from "../../../../../common/translations/localize";
|
||||||
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 { SchemaUnion } from "../../../../../components/ha-form/types";
|
import type { SchemaUnion } from "../../../../../components/ha-form/types";
|
||||||
@ -27,61 +29,6 @@ const imageElementConfigStruct = object({
|
|||||||
aspect_ratio: optional(string()),
|
aspect_ratio: optional(string()),
|
||||||
});
|
});
|
||||||
|
|
||||||
const SCHEMA = [
|
|
||||||
{ name: "entity", selector: { entity: {} } },
|
|
||||||
{ name: "title", selector: { text: {} } },
|
|
||||||
{
|
|
||||||
name: "interactions",
|
|
||||||
type: "expandable",
|
|
||||||
flatten: true,
|
|
||||||
iconPath: mdiGestureTap,
|
|
||||||
schema: [
|
|
||||||
{
|
|
||||||
name: "tap_action",
|
|
||||||
selector: {
|
|
||||||
ui_action: {
|
|
||||||
default_action: "more-info",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "hold_action",
|
|
||||||
selector: {
|
|
||||||
ui_action: {
|
|
||||||
default_action: "more-info",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "",
|
|
||||||
type: "optional_actions",
|
|
||||||
flatten: true,
|
|
||||||
schema: [
|
|
||||||
{
|
|
||||||
name: "double_tap_action",
|
|
||||||
selector: {
|
|
||||||
ui_action: {
|
|
||||||
default_action: "none",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{ name: "image", selector: { image: {} } },
|
|
||||||
{ name: "camera_image", selector: { entity: { domain: "camera" } } },
|
|
||||||
{
|
|
||||||
name: "camera_view",
|
|
||||||
selector: { select: { options: ["auto", "live"] } },
|
|
||||||
},
|
|
||||||
{ name: "state_image", selector: { object: {} } },
|
|
||||||
{ name: "filter", selector: { text: {} } },
|
|
||||||
{ name: "state_filter", selector: { object: {} } },
|
|
||||||
{ name: "aspect_ratio", selector: { text: {} } },
|
|
||||||
{ name: "style", selector: { object: {} } },
|
|
||||||
] as const;
|
|
||||||
|
|
||||||
@customElement("hui-image-element-editor")
|
@customElement("hui-image-element-editor")
|
||||||
export class HuiImageElementEditor
|
export class HuiImageElementEditor
|
||||||
extends LitElement
|
extends LitElement
|
||||||
@ -96,6 +43,74 @@ export class HuiImageElementEditor
|
|||||||
this._config = config;
|
this._config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _schema = memoizeOne(
|
||||||
|
(localize: LocalizeFunc) =>
|
||||||
|
[
|
||||||
|
{ name: "entity", selector: { entity: {} } },
|
||||||
|
{ name: "title", selector: { text: {} } },
|
||||||
|
{
|
||||||
|
name: "interactions",
|
||||||
|
type: "expandable",
|
||||||
|
flatten: true,
|
||||||
|
iconPath: mdiGestureTap,
|
||||||
|
schema: [
|
||||||
|
{
|
||||||
|
name: "tap_action",
|
||||||
|
selector: {
|
||||||
|
ui_action: {
|
||||||
|
default_action: "more-info",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "hold_action",
|
||||||
|
selector: {
|
||||||
|
ui_action: {
|
||||||
|
default_action: "more-info",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "",
|
||||||
|
type: "optional_actions",
|
||||||
|
flatten: true,
|
||||||
|
schema: [
|
||||||
|
{
|
||||||
|
name: "double_tap_action",
|
||||||
|
selector: {
|
||||||
|
ui_action: {
|
||||||
|
default_action: "none",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{ name: "image", selector: { image: {} } },
|
||||||
|
{ name: "camera_image", selector: { entity: { domain: "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",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ name: "state_image", selector: { object: {} } },
|
||||||
|
{ name: "filter", selector: { text: {} } },
|
||||||
|
{ name: "state_filter", selector: { object: {} } },
|
||||||
|
{ name: "aspect_ratio", selector: { text: {} } },
|
||||||
|
{ name: "style", selector: { object: {} } },
|
||||||
|
] as const
|
||||||
|
);
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
if (!this.hass || !this._config) {
|
if (!this.hass || !this._config) {
|
||||||
return nothing;
|
return nothing;
|
||||||
@ -105,7 +120,7 @@ export class HuiImageElementEditor
|
|||||||
<ha-form
|
<ha-form
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.data=${this._config}
|
.data=${this._config}
|
||||||
.schema=${SCHEMA}
|
.schema=${this._schema(this.hass.localize)}
|
||||||
.computeLabel=${this._computeLabelCallback}
|
.computeLabel=${this._computeLabelCallback}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
></ha-form>
|
></ha-form>
|
||||||
@ -116,7 +131,9 @@ export class HuiImageElementEditor
|
|||||||
fireEvent(this, "config-changed", { config: ev.detail.value });
|
fireEvent(this, "config-changed", { config: ev.detail.value });
|
||||||
}
|
}
|
||||||
|
|
||||||
private _computeLabelCallback = (schema: SchemaUnion<typeof SCHEMA>) =>
|
private _computeLabelCallback = (
|
||||||
|
schema: SchemaUnion<ReturnType<typeof this._schema>>
|
||||||
|
) =>
|
||||||
this.hass!.localize(
|
this.hass!.localize(
|
||||||
`ui.panel.lovelace.editor.card.generic.${schema.name}`
|
`ui.panel.lovelace.editor.card.generic.${schema.name}`
|
||||||
) ||
|
) ||
|
||||||
|
@ -25,6 +25,7 @@ import { computeDomain } from "../../../../common/entity/compute_domain";
|
|||||||
import { caseInsensitiveStringCompare } from "../../../../common/string/compare";
|
import { caseInsensitiveStringCompare } from "../../../../common/string/compare";
|
||||||
import type { SelectOption } from "../../../../data/selector";
|
import type { SelectOption } from "../../../../data/selector";
|
||||||
import { getSensorNumericDeviceClasses } from "../../../../data/sensor";
|
import { getSensorNumericDeviceClasses } from "../../../../data/sensor";
|
||||||
|
import type { LocalizeFunc } from "../../../../common/translations/localize";
|
||||||
|
|
||||||
const cardConfigStruct = assign(
|
const cardConfigStruct = assign(
|
||||||
baseLovelaceCardConfig,
|
baseLovelaceCardConfig,
|
||||||
@ -53,6 +54,7 @@ export class HuiAreaCardEditor
|
|||||||
|
|
||||||
private _schema = memoizeOne(
|
private _schema = memoizeOne(
|
||||||
(
|
(
|
||||||
|
localize: LocalizeFunc,
|
||||||
showCamera: boolean,
|
showCamera: boolean,
|
||||||
binaryClasses: SelectOption[],
|
binaryClasses: SelectOption[],
|
||||||
sensorClasses: SelectOption[]
|
sensorClasses: SelectOption[]
|
||||||
@ -64,7 +66,17 @@ export class HuiAreaCardEditor
|
|||||||
? ([
|
? ([
|
||||||
{
|
{
|
||||||
name: "camera_view",
|
name: "camera_view",
|
||||||
selector: { select: { options: ["auto", "live"] } },
|
selector: {
|
||||||
|
select: {
|
||||||
|
options: ["auto", "live"].map((value) => ({
|
||||||
|
value,
|
||||||
|
label: localize(
|
||||||
|
`ui.panel.lovelace.editor.card.generic.camera_view_options.${value}`
|
||||||
|
),
|
||||||
|
})),
|
||||||
|
mode: "dropdown",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
] as const)
|
] as const)
|
||||||
: []),
|
: []),
|
||||||
@ -212,6 +224,7 @@ export class HuiAreaCardEditor
|
|||||||
);
|
);
|
||||||
|
|
||||||
const schema = this._schema(
|
const schema = this._schema(
|
||||||
|
this.hass.localize,
|
||||||
this._config.show_camera || false,
|
this._config.show_camera || false,
|
||||||
binarySelectOptions,
|
binarySelectOptions,
|
||||||
sensorSelectOptions
|
sensorSelectOptions
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import memoizeOne from "memoize-one";
|
||||||
import type { CSSResultGroup } from "lit";
|
import type { CSSResultGroup } from "lit";
|
||||||
import { html, LitElement, nothing } from "lit";
|
import { html, LitElement, nothing } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
@ -11,7 +12,6 @@ import {
|
|||||||
string,
|
string,
|
||||||
type,
|
type,
|
||||||
} from "superstruct";
|
} from "superstruct";
|
||||||
import memoizeOne from "memoize-one";
|
|
||||||
import type { HASSDomEvent } from "../../../../common/dom/fire_event";
|
import type { HASSDomEvent } from "../../../../common/dom/fire_event";
|
||||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
import "../../../../components/ha-card";
|
import "../../../../components/ha-card";
|
||||||
@ -84,7 +84,17 @@ export class HuiPictureElementsCardEditor
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "camera_view",
|
name: "camera_view",
|
||||||
selector: { select: { options: ["auto", "live"] } },
|
selector: {
|
||||||
|
select: {
|
||||||
|
options: ["auto", "live"].map((value) => ({
|
||||||
|
value,
|
||||||
|
label: localize(
|
||||||
|
`ui.panel.lovelace.editor.card.generic.camera_view_options.${value}`
|
||||||
|
),
|
||||||
|
})),
|
||||||
|
mode: "dropdown",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{ name: "theme", selector: { theme: {} } },
|
{ name: "theme", selector: { theme: {} } },
|
||||||
{ name: "state_filter", selector: { object: {} } },
|
{ name: "state_filter", selector: { object: {} } },
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
import memoizeOne from "memoize-one";
|
||||||
import { mdiGestureTap } from "@mdi/js";
|
import { mdiGestureTap } from "@mdi/js";
|
||||||
import type { CSSResultGroup } from "lit";
|
import type { CSSResultGroup } from "lit";
|
||||||
import { html, LitElement, nothing } from "lit";
|
import { html, LitElement, nothing } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import memoizeOne from "memoize-one";
|
|
||||||
import {
|
import {
|
||||||
assert,
|
assert,
|
||||||
assign,
|
assign,
|
||||||
|
@ -173,13 +173,11 @@ export class HuiPictureGlanceCardEditor
|
|||||||
|
|
||||||
const data = { camera_view: "auto", fit_mode: "cover", ...this._config };
|
const data = { camera_view: "auto", fit_mode: "cover", ...this._config };
|
||||||
|
|
||||||
const schema = this._schema(this.hass.localize);
|
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-form
|
<ha-form
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.data=${data}
|
.data=${data}
|
||||||
.schema=${schema}
|
.schema=${this._schema(this.hass.localize)}
|
||||||
.computeLabel=${this._computeLabelCallback}
|
.computeLabel=${this._computeLabelCallback}
|
||||||
.computeHelper=${this._computeHelperCallback}
|
.computeHelper=${this._computeHelperCallback}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user