mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 01:06:35 +00:00
parent
775837b60f
commit
774aee406c
@ -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", {
|
||||
|
Loading…
x
Reference in New Issue
Block a user