From 7e2bf920e17cb590f451e5a439ff60521c30aa08 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Mon, 17 May 2021 16:57:43 +0200 Subject: [PATCH] Correct types for script automation editors (#9184) --- .../config/automation/ha-automation-editor.ts | 13 ++++++++----- src/panels/config/script/ha-script-editor.ts | 13 ++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/panels/config/automation/ha-automation-editor.ts b/src/panels/config/automation/ha-automation-editor.ts index 7b4ad82315..b0780ea237 100644 --- a/src/panels/config/automation/ha-automation-editor.ts +++ b/src/panels/config/automation/ha-automation-editor.ts @@ -75,7 +75,7 @@ declare global { export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) { @property({ attribute: false }) public hass!: HomeAssistant; - @property() public automationId!: string; + @property() public automationId: string | null = null; @property() public automations!: AutomationEntity[]; @@ -178,14 +178,14 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) { aria-label=${this.hass.localize( "ui.panel.config.automation.picker.delete_automation" )} - class=${classMap({ warning: this.automationId })} + class=${classMap({ warning: Boolean(this.automationId) })} graphic="icon" > ${this.hass.localize( "ui.panel.config.automation.picker.delete_automation" )} @@ -349,7 +349,10 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) { private async _loadConfig() { try { - const config = await getAutomationConfig(this.hass, this.automationId); + const config = await getAutomationConfig( + this.hass, + this.automationId as string + ); // Normalize data: ensure trigger, action and condition are lists // Happens when people copy paste their automations into the config @@ -470,7 +473,7 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) { } private async _delete() { - await deleteAutomation(this.hass, this.automationId); + await deleteAutomation(this.hass, this.automationId as string); history.back(); } diff --git a/src/panels/config/script/ha-script-editor.ts b/src/panels/config/script/ha-script-editor.ts index bd11dc5bba..fc17217056 100644 --- a/src/panels/config/script/ha-script-editor.ts +++ b/src/panels/config/script/ha-script-editor.ts @@ -61,7 +61,7 @@ import { configSections } from "../ha-panel-config"; export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) { @property({ attribute: false }) public hass!: HomeAssistant; - @property() public scriptEntityId!: string; + @property() public scriptEntityId: string | null = null; @property() public route!: Route; @@ -161,12 +161,12 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) { aria-label=${this.hass.localize( "ui.panel.config.script.editor.delete_script" )} - class=${classMap({ warning: this.scriptEntityId })} + class=${classMap({ warning: Boolean(this.scriptEntityId) })} graphic="icon" > ${this.hass.localize("ui.panel.config.script.editor.delete_script")} @@ -470,7 +470,7 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) { private async _runScript(ev) { ev.stopPropagation(); - await triggerScript(this.hass, this.scriptEntityId); + await triggerScript(this.hass, this.scriptEntityId as string); showToast(this, { message: this.hass.localize( "ui.notification_toast.triggered", @@ -620,7 +620,10 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) { } private async _delete() { - await deleteScript(this.hass, computeObjectId(this.scriptEntityId)); + await deleteScript( + this.hass, + computeObjectId(this.scriptEntityId as string) + ); history.back(); }