Fix YAML validation for automation action service call enabling/disabling (#14536)

fixes undefined
This commit is contained in:
Philip Allgaier 2022-12-05 15:33:41 +01:00 committed by GitHub
parent 076ddb71b6
commit 20dff9d25d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,22 +1,13 @@
import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit";
import { customElement, property, state } from "lit/decorators";
import { any, assert, object, optional, string } from "superstruct";
import { assert } from "superstruct";
import { fireEvent } from "../../../../../common/dom/fire_event";
import { hasTemplate } from "../../../../../common/string/has-template";
import { entityIdOrAll } from "../../../../../common/structs/is-entity-id";
import "../../../../../components/ha-service-control";
import { ServiceAction } from "../../../../../data/script";
import { ServiceAction, serviceActionStruct } from "../../../../../data/script";
import type { HomeAssistant } from "../../../../../types";
import { ActionElement } from "../ha-automation-action-row";
const actionStruct = object({
alias: optional(string()),
service: optional(string()),
entity_id: optional(entityIdOrAll()),
target: optional(any()),
data: optional(any()),
});
@customElement("ha-automation-action-service")
export class HaServiceAction extends LitElement implements ActionElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@ -38,7 +29,7 @@ export class HaServiceAction extends LitElement implements ActionElement {
return;
}
try {
assert(this.action, actionStruct);
assert(this.action, serviceActionStruct);
} catch (err: any) {
fireEvent(this, "ui-mode-not-available", err);
return;