Fix tag trigger (#13540)

* Fix tag trigger

* Fix
This commit is contained in:
Bram Kragten 2022-08-31 18:28:50 +02:00 committed by GitHub
parent 775837b60f
commit 774aee406c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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`
<ha-select
.label=${this.hass.localize(
"ui.panel.config.automation.editor.triggers.type.tag.label"
)}
.disabled=${this._tags.length === 0}
.value=${tag_id}
.value=${this.trigger.tag_id}
@selected=${this._tagChanged}
>
${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", {