Correct types for script automation editors (#9184)

This commit is contained in:
Bram Kragten 2021-05-17 16:57:43 +02:00 committed by GitHub
parent 1f65328f2d
commit 7e2bf920e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 10 deletions

View File

@ -75,7 +75,7 @@ declare global {
export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) { export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
@property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public hass!: HomeAssistant;
@property() public automationId!: string; @property() public automationId: string | null = null;
@property() public automations!: AutomationEntity[]; @property() public automations!: AutomationEntity[];
@ -178,14 +178,14 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
aria-label=${this.hass.localize( aria-label=${this.hass.localize(
"ui.panel.config.automation.picker.delete_automation" "ui.panel.config.automation.picker.delete_automation"
)} )}
class=${classMap({ warning: this.automationId })} class=${classMap({ warning: Boolean(this.automationId) })}
graphic="icon" graphic="icon"
> >
${this.hass.localize( ${this.hass.localize(
"ui.panel.config.automation.picker.delete_automation" "ui.panel.config.automation.picker.delete_automation"
)} )}
<ha-svg-icon <ha-svg-icon
class=${classMap({ warning: this.automationId })} class=${classMap({ warning: Boolean(this.automationId) })}
slot="graphic" slot="graphic"
.path=${mdiDelete} .path=${mdiDelete}
> >
@ -349,7 +349,10 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
private async _loadConfig() { private async _loadConfig() {
try { 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 // Normalize data: ensure trigger, action and condition are lists
// Happens when people copy paste their automations into the config // Happens when people copy paste their automations into the config
@ -470,7 +473,7 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
} }
private async _delete() { private async _delete() {
await deleteAutomation(this.hass, this.automationId); await deleteAutomation(this.hass, this.automationId as string);
history.back(); history.back();
} }

View File

@ -61,7 +61,7 @@ import { configSections } from "../ha-panel-config";
export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) { export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
@property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public hass!: HomeAssistant;
@property() public scriptEntityId!: string; @property() public scriptEntityId: string | null = null;
@property() public route!: Route; @property() public route!: Route;
@ -161,12 +161,12 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
aria-label=${this.hass.localize( aria-label=${this.hass.localize(
"ui.panel.config.script.editor.delete_script" "ui.panel.config.script.editor.delete_script"
)} )}
class=${classMap({ warning: this.scriptEntityId })} class=${classMap({ warning: Boolean(this.scriptEntityId) })}
graphic="icon" graphic="icon"
> >
${this.hass.localize("ui.panel.config.script.editor.delete_script")} ${this.hass.localize("ui.panel.config.script.editor.delete_script")}
<ha-svg-icon <ha-svg-icon
class=${classMap({ warning: this.scriptEntityId })} class=${classMap({ warning: Boolean(this.scriptEntityId) })}
slot="graphic" slot="graphic"
.path=${mdiDelete} .path=${mdiDelete}
> >
@ -470,7 +470,7 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
private async _runScript(ev) { private async _runScript(ev) {
ev.stopPropagation(); ev.stopPropagation();
await triggerScript(this.hass, this.scriptEntityId); await triggerScript(this.hass, this.scriptEntityId as string);
showToast(this, { showToast(this, {
message: this.hass.localize( message: this.hass.localize(
"ui.notification_toast.triggered", "ui.notification_toast.triggered",
@ -620,7 +620,10 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
} }
private async _delete() { private async _delete() {
await deleteScript(this.hass, computeObjectId(this.scriptEntityId)); await deleteScript(
this.hass,
computeObjectId(this.scriptEntityId as string)
);
history.back(); history.back();
} }