From cea40610c097dbd0b54c2944e5dab29833a750d3 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Fri, 10 Dec 2021 14:44:40 +0100 Subject: [PATCH] Add base trigger to struct (#10851) --- src/panels/config/automation/structs.ts | 7 ++++- .../types/ha-automation-trigger-state.ts | 31 +++++++++++++------ 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/panels/config/automation/structs.ts b/src/panels/config/automation/structs.ts index eb6baefa97..d54d9761f4 100644 --- a/src/panels/config/automation/structs.ts +++ b/src/panels/config/automation/structs.ts @@ -1,4 +1,9 @@ -import { object, optional, number } from "superstruct"; +import { object, optional, number, string } from "superstruct"; + +export const baseTriggerStruct = object({ + platform: string(), + id: optional(string()), +}); export const forDictStruct = object({ days: optional(number()), diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-state.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-state.ts index e75f2f8b33..9e362634ea 100644 --- a/src/panels/config/automation/trigger/types/ha-automation-trigger-state.ts +++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-state.ts @@ -1,7 +1,15 @@ import "@polymer/paper-input/paper-input"; import { html, LitElement, PropertyValues } from "lit"; import { customElement, property } from "lit/decorators"; -import { assert, literal, object, optional, string, union } from "superstruct"; +import { + assert, + assign, + literal, + object, + optional, + string, + union, +} from "superstruct"; import { createDurationData } from "../../../../../common/datetime/create_duration_data"; import { fireEvent } from "../../../../../common/dom/fire_event"; import { hasTemplate } from "../../../../../common/string/has-template"; @@ -10,20 +18,23 @@ import "../../../../../components/entity/ha-entity-picker"; import "../../../../../components/ha-duration-input"; import { StateTrigger } from "../../../../../data/automation"; import { HomeAssistant } from "../../../../../types"; -import { forDictStruct } from "../../structs"; +import { baseTriggerStruct, forDictStruct } from "../../structs"; import { handleChangeEvent, TriggerElement, } from "../ha-automation-trigger-row"; -const stateTriggerStruct = object({ - platform: literal("state"), - entity_id: string(), - attribute: optional(string()), - from: optional(string()), - to: optional(string()), - for: optional(union([string(), forDictStruct])), -}); +const stateTriggerStruct = assign( + baseTriggerStruct, + object({ + platform: literal("state"), + entity_id: string(), + attribute: optional(string()), + from: optional(string()), + to: optional(string()), + for: optional(union([string(), forDictStruct])), + }) +); @customElement("ha-automation-trigger-state") export class HaStateTrigger extends LitElement implements TriggerElement {