mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +00:00
Enforce valid entity ID in card config YAML (#14792)
This commit is contained in:
parent
1c139d0bc7
commit
adb61ab99b
@ -79,7 +79,7 @@ class HuiMapCard extends LitElement implements LovelaceCard {
|
||||
config.geo_location_sources &&
|
||||
!Array.isArray(config.geo_location_sources)
|
||||
) {
|
||||
throw new Error("Geo_location_sources needs to be an array");
|
||||
throw new Error("Parameter geo_location_sources needs to be an array");
|
||||
}
|
||||
|
||||
this._config = config;
|
||||
|
@ -27,13 +27,11 @@ export const processConfigEntities = <
|
||||
config = { entity: entityConf } as T;
|
||||
} else if (typeof entityConf === "object" && !Array.isArray(entityConf)) {
|
||||
if (!("entity" in entityConf)) {
|
||||
throw new Error(
|
||||
`Entity object at position ${index} is missing entity field.`
|
||||
);
|
||||
throw new Error(`Object at position ${index} is missing entity field`);
|
||||
}
|
||||
config = entityConf as T;
|
||||
} else {
|
||||
throw new Error(`Invalid entity specified at position ${index}.`);
|
||||
throw new Error(`Invalid entity ID at position ${index}`);
|
||||
}
|
||||
|
||||
if (checkEntityId && !isValidEntityId((config as EntityConfig).entity!)) {
|
||||
|
@ -1,20 +1,21 @@
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
import { html, LitElement, TemplateResult } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { array, assert, assign, object, optional, string } from "superstruct";
|
||||
import memoizeOne from "memoize-one";
|
||||
import { array, assert, assign, object, optional, string } from "superstruct";
|
||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||
import { entityId } from "../../../../common/structs/is-entity-id";
|
||||
import type { LocalizeFunc } from "../../../../common/translations/localize";
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
import type { SchemaUnion } from "../../../../components/ha-form/types";
|
||||
import type { HomeAssistant } from "../../../../types";
|
||||
import type { AlarmPanelCardConfig } from "../../cards/types";
|
||||
import type { LovelaceCardEditor } from "../../types";
|
||||
import { baseLovelaceCardConfig } from "../structs/base-card-struct";
|
||||
import type { SchemaUnion } from "../../../../components/ha-form/types";
|
||||
import type { LocalizeFunc } from "../../../../common/translations/localize";
|
||||
|
||||
const cardConfigStruct = assign(
|
||||
baseLovelaceCardConfig,
|
||||
object({
|
||||
entity: optional(string()),
|
||||
entity: optional(entityId()),
|
||||
name: optional(string()),
|
||||
states: optional(array()),
|
||||
theme: optional(string()),
|
||||
|
@ -6,6 +6,7 @@ import { assert, assign, boolean, object, optional, string } from "superstruct";
|
||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||
import { computeDomain } from "../../../../common/entity/compute_domain";
|
||||
import { domainIcon } from "../../../../common/entity/domain_icon";
|
||||
import { entityId } from "../../../../common/structs/is-entity-id";
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
import type { SchemaUnion } from "../../../../components/ha-form/types";
|
||||
import type { HomeAssistant } from "../../../../types";
|
||||
@ -18,7 +19,7 @@ import { configElementStyle } from "./config-elements-style";
|
||||
const cardConfigStruct = assign(
|
||||
baseLovelaceCardConfig,
|
||||
object({
|
||||
entity: optional(string()),
|
||||
entity: optional(entityId()),
|
||||
name: optional(string()),
|
||||
show_name: optional(boolean()),
|
||||
icon: optional(string()),
|
||||
|
@ -1,12 +1,13 @@
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
import type { HassEntity } from "home-assistant-js-websocket/dist/types";
|
||||
import { html, LitElement, TemplateResult } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import memoizeOne from "memoize-one";
|
||||
import { assert, assign, boolean, object, optional, string } from "superstruct";
|
||||
import type { HassEntity } from "home-assistant-js-websocket/dist/types";
|
||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||
import { computeDomain } from "../../../../common/entity/compute_domain";
|
||||
import { domainIcon } from "../../../../common/entity/domain_icon";
|
||||
import { entityId } from "../../../../common/structs/is-entity-id";
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
import type { SchemaUnion } from "../../../../components/ha-form/types";
|
||||
import type { HomeAssistant } from "../../../../types";
|
||||
import type { EntityCardConfig } from "../../cards/types";
|
||||
@ -17,7 +18,7 @@ import { baseLovelaceCardConfig } from "../structs/base-card-struct";
|
||||
const cardConfigStruct = assign(
|
||||
baseLovelaceCardConfig,
|
||||
object({
|
||||
entity: optional(string()),
|
||||
entity: optional(entityId()),
|
||||
name: optional(string()),
|
||||
icon: optional(string()),
|
||||
attribute: optional(string()),
|
||||
|
@ -1,6 +1,6 @@
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
import { html, LitElement, TemplateResult } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import memoizeOne from "memoize-one";
|
||||
import {
|
||||
array,
|
||||
assert,
|
||||
@ -11,8 +11,9 @@ import {
|
||||
optional,
|
||||
string,
|
||||
} from "superstruct";
|
||||
import memoizeOne from "memoize-one";
|
||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||
import { entityId } from "../../../../common/structs/is-entity-id";
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
import type { SchemaUnion } from "../../../../components/ha-form/types";
|
||||
import type { HomeAssistant } from "../../../../types";
|
||||
import type { GaugeCardConfig } from "../../cards/types";
|
||||
@ -29,7 +30,7 @@ const cardConfigStruct = assign(
|
||||
baseLovelaceCardConfig,
|
||||
object({
|
||||
name: optional(string()),
|
||||
entity: optional(string()),
|
||||
entity: optional(entityId()),
|
||||
unit: optional(string()),
|
||||
min: optional(number()),
|
||||
max: optional(number()),
|
||||
|
@ -1,8 +1,9 @@
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
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 { entityId } from "../../../../common/structs/is-entity-id";
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
import type { SchemaUnion } from "../../../../components/ha-form/types";
|
||||
import type { HomeAssistant } from "../../../../types";
|
||||
import type { HumidifierCardConfig } from "../../cards/types";
|
||||
@ -12,7 +13,7 @@ import { baseLovelaceCardConfig } from "../structs/base-card-struct";
|
||||
const cardConfigStruct = assign(
|
||||
baseLovelaceCardConfig,
|
||||
object({
|
||||
entity: optional(string()),
|
||||
entity: optional(entityId()),
|
||||
name: optional(string()),
|
||||
theme: optional(string()),
|
||||
})
|
||||
|
@ -6,6 +6,7 @@ import { assert, assign, object, optional, string } from "superstruct";
|
||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||
import { computeDomain } from "../../../../common/entity/compute_domain";
|
||||
import { domainIcon } from "../../../../common/entity/domain_icon";
|
||||
import { entityId } from "../../../../common/structs/is-entity-id";
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
import type { SchemaUnion } from "../../../../components/ha-form/types";
|
||||
import type { HomeAssistant } from "../../../../types";
|
||||
@ -19,7 +20,7 @@ const cardConfigStruct = assign(
|
||||
baseLovelaceCardConfig,
|
||||
object({
|
||||
name: optional(string()),
|
||||
entity: optional(string()),
|
||||
entity: optional(entityId()),
|
||||
theme: optional(string()),
|
||||
icon: optional(string()),
|
||||
hold_action: optional(actionConfigStruct),
|
||||
|
@ -1,17 +1,19 @@
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import {
|
||||
array,
|
||||
assert,
|
||||
assign,
|
||||
boolean,
|
||||
number,
|
||||
object,
|
||||
optional,
|
||||
string,
|
||||
assign,
|
||||
} from "superstruct";
|
||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||
import { entityId } from "../../../../common/structs/is-entity-id";
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
import { SchemaUnion } from "../../../../components/ha-form/types";
|
||||
import "../../../../components/ha-formfield";
|
||||
import "../../../../components/ha-switch";
|
||||
import { PolymerChangedEvent } from "../../../../polymer-types";
|
||||
@ -22,11 +24,9 @@ import "../../components/hui-input-list-editor";
|
||||
import { EntityConfig } from "../../entity-rows/types";
|
||||
import { LovelaceCardEditor } from "../../types";
|
||||
import { processEditorEntities } from "../process-editor-entities";
|
||||
import { entitiesConfigStruct } from "../structs/entities-struct";
|
||||
import { baseLovelaceCardConfig } from "../structs/base-card-struct";
|
||||
import { EntitiesEditorEvent } from "../types";
|
||||
import { configElementStyle } from "./config-elements-style";
|
||||
import { baseLovelaceCardConfig } from "../structs/base-card-struct";
|
||||
import { SchemaUnion } from "../../../../components/ha-form/types";
|
||||
|
||||
const cardConfigStruct = assign(
|
||||
baseLovelaceCardConfig,
|
||||
@ -35,9 +35,10 @@ const cardConfigStruct = assign(
|
||||
aspect_ratio: optional(string()),
|
||||
default_zoom: optional(number()),
|
||||
dark_mode: optional(boolean()),
|
||||
entities: array(entitiesConfigStruct),
|
||||
entities: array(entityId()),
|
||||
hours_to_show: optional(number()),
|
||||
geo_location_sources: optional(array(string())),
|
||||
auto_fit: optional(boolean()),
|
||||
})
|
||||
);
|
||||
|
||||
|
@ -2,6 +2,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 { entityId } from "../../../../common/structs/is-entity-id";
|
||||
import "../../../../components/entity/ha-entity-picker";
|
||||
import "../../../../components/ha-theme-picker";
|
||||
import { HomeAssistant } from "../../../../types";
|
||||
@ -13,7 +14,7 @@ import { EditorTarget, EntitiesEditorEvent } from "../types";
|
||||
const cardConfigStruct = assign(
|
||||
baseLovelaceCardConfig,
|
||||
object({
|
||||
entity: optional(string()),
|
||||
entity: optional(entityId()),
|
||||
theme: optional(string()),
|
||||
})
|
||||
);
|
||||
|
@ -2,6 +2,8 @@ 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 { entityId } from "../../../../common/structs/is-entity-id";
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
import type { SchemaUnion } from "../../../../components/ha-form/types";
|
||||
import type { HomeAssistant } from "../../../../types";
|
||||
import type { PictureEntityCardConfig } from "../../cards/types";
|
||||
@ -9,12 +11,11 @@ import type { LovelaceCardEditor } from "../../types";
|
||||
import { actionConfigStruct } from "../structs/action-struct";
|
||||
import { baseLovelaceCardConfig } from "../structs/base-card-struct";
|
||||
import { configElementStyle } from "./config-elements-style";
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
|
||||
const cardConfigStruct = assign(
|
||||
baseLovelaceCardConfig,
|
||||
object({
|
||||
entity: optional(string()),
|
||||
entity: optional(entityId()),
|
||||
image: optional(string()),
|
||||
name: optional(string()),
|
||||
camera_image: optional(string()),
|
||||
|
@ -1,8 +1,9 @@
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
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 { entityId } from "../../../../common/structs/is-entity-id";
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
import type { SchemaUnion } from "../../../../components/ha-form/types";
|
||||
import type { HomeAssistant } from "../../../../types";
|
||||
import type { PlantStatusCardConfig } from "../../cards/types";
|
||||
@ -12,7 +13,7 @@ import { baseLovelaceCardConfig } from "../structs/base-card-struct";
|
||||
const cardConfigStruct = assign(
|
||||
baseLovelaceCardConfig,
|
||||
object({
|
||||
entity: optional(string()),
|
||||
entity: optional(entityId()),
|
||||
name: optional(string()),
|
||||
theme: optional(string()),
|
||||
})
|
||||
|
@ -1,4 +1,3 @@
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
import type { HassEntity } from "home-assistant-js-websocket";
|
||||
import { CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
@ -16,6 +15,8 @@ import {
|
||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||
import { computeDomain } from "../../../../common/entity/compute_domain";
|
||||
import { domainIcon } from "../../../../common/entity/domain_icon";
|
||||
import { entityId } from "../../../../common/structs/is-entity-id";
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
import type { SchemaUnion } from "../../../../components/ha-form/types";
|
||||
import type { HomeAssistant } from "../../../../types";
|
||||
import type { SensorCardConfig } from "../../cards/types";
|
||||
@ -26,7 +27,7 @@ import { configElementStyle } from "./config-elements-style";
|
||||
const cardConfigStruct = assign(
|
||||
baseLovelaceCardConfig,
|
||||
object({
|
||||
entity: optional(string()),
|
||||
entity: optional(entityId()),
|
||||
name: optional(string()),
|
||||
icon: optional(string()),
|
||||
graph: optional(union([literal("line"), literal("none")])),
|
||||
|
@ -1,8 +1,9 @@
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
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 { entityId } from "../../../../common/structs/is-entity-id";
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
import type { SchemaUnion } from "../../../../components/ha-form/types";
|
||||
import type { HomeAssistant } from "../../../../types";
|
||||
import type { ThermostatCardConfig } from "../../cards/types";
|
||||
@ -12,7 +13,7 @@ import { baseLovelaceCardConfig } from "../structs/base-card-struct";
|
||||
const cardConfigStruct = assign(
|
||||
baseLovelaceCardConfig,
|
||||
object({
|
||||
entity: optional(string()),
|
||||
entity: optional(entityId()),
|
||||
name: optional(string()),
|
||||
theme: optional(string()),
|
||||
})
|
||||
|
@ -16,6 +16,7 @@ import {
|
||||
import { fireEvent, HASSDomEvent } from "../../../../common/dom/fire_event";
|
||||
import { computeDomain } from "../../../../common/entity/compute_domain";
|
||||
import { domainIcon } from "../../../../common/entity/domain_icon";
|
||||
import { entityId } from "../../../../common/structs/is-entity-id";
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
import type { SchemaUnion } from "../../../../components/ha-form/types";
|
||||
import type { HomeAssistant } from "../../../../types";
|
||||
@ -35,7 +36,7 @@ import "./hui-tile-card-features-editor";
|
||||
const cardConfigStruct = assign(
|
||||
baseLovelaceCardConfig,
|
||||
object({
|
||||
entity: optional(string()),
|
||||
entity: optional(entityId()),
|
||||
name: optional(string()),
|
||||
icon: optional(string()),
|
||||
color: optional(string()),
|
||||
|
@ -1,23 +1,24 @@
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
import { memoize } from "@fullcalendar/common";
|
||||
import { html, LitElement, TemplateResult } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { assert, boolean, object, optional, string, assign } from "superstruct";
|
||||
import { memoize } from "@fullcalendar/common";
|
||||
import { assert, assign, boolean, object, optional, string } from "superstruct";
|
||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||
import { entityId } from "../../../../common/structs/is-entity-id";
|
||||
import type { LocalizeFunc } from "../../../../common/translations/localize";
|
||||
import "../../../../components/ha-form/ha-form";
|
||||
import type { SchemaUnion } from "../../../../components/ha-form/types";
|
||||
import { UNAVAILABLE } from "../../../../data/entity";
|
||||
import type { WeatherEntity } from "../../../../data/weather";
|
||||
import type { HomeAssistant } from "../../../../types";
|
||||
import type { WeatherForecastCardConfig } from "../../cards/types";
|
||||
import type { LovelaceCardEditor } from "../../types";
|
||||
import { actionConfigStruct } from "../structs/action-struct";
|
||||
import { baseLovelaceCardConfig } from "../structs/base-card-struct";
|
||||
import { UNAVAILABLE } from "../../../../data/entity";
|
||||
import type { WeatherEntity } from "../../../../data/weather";
|
||||
import type { LocalizeFunc } from "../../../../common/translations/localize";
|
||||
import type { SchemaUnion } from "../../../../components/ha-form/types";
|
||||
|
||||
const cardConfigStruct = assign(
|
||||
baseLovelaceCardConfig,
|
||||
object({
|
||||
entity: optional(string()),
|
||||
entity: optional(entityId()),
|
||||
name: optional(string()),
|
||||
theme: optional(string()),
|
||||
show_current: optional(boolean()),
|
||||
|
Loading…
x
Reference in New Issue
Block a user