From 774aee406c795245455893911a28c35cedc0665d Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Wed, 31 Aug 2022 18:28:50 +0200 Subject: [PATCH] Fix tag trigger (#13540) * Fix tag trigger * Fix --- .../trigger/types/ha-automation-trigger-tag.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-tag.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-tag.ts index 9a12ab7b55..12cb696d80 100644 --- a/src/panels/config/automation/trigger/types/ha-automation-trigger-tag.ts +++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-tag.ts @@ -15,7 +15,7 @@ export class HaTagTrigger extends LitElement implements TriggerElement { @property() public trigger!: TagTrigger; - @state() private _tags: Tag[] = []; + @state() private _tags?: Tag[]; public static get defaultConfig() { return { tag_id: "" }; @@ -27,14 +27,16 @@ export class HaTagTrigger extends LitElement implements TriggerElement { } protected render() { - const { tag_id } = this.trigger; + if (!this._tags) { + return html``; + } return html` ${this._tags.map( @@ -49,14 +51,17 @@ export class HaTagTrigger extends LitElement implements TriggerElement { } private async _fetchTags() { - this._tags = await fetchTags(this.hass); - this._tags.sort((a, b) => + this._tags = (await fetchTags(this.hass)).sort((a, b) => caseInsensitiveStringCompare(a.name || a.id, b.name || b.id) ); } private _tagChanged(ev) { - if (this.trigger.tag_id === ev.detail.value) { + if ( + !ev.detail.value || + !this._tags || + this.trigger.tag_id === ev.detail.value + ) { return; } fireEvent(this, "value-changed", {