mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 17:56:46 +00:00
parent
775837b60f
commit
774aee406c
@ -15,7 +15,7 @@ export class HaTagTrigger extends LitElement implements TriggerElement {
|
|||||||
|
|
||||||
@property() public trigger!: TagTrigger;
|
@property() public trigger!: TagTrigger;
|
||||||
|
|
||||||
@state() private _tags: Tag[] = [];
|
@state() private _tags?: Tag[];
|
||||||
|
|
||||||
public static get defaultConfig() {
|
public static get defaultConfig() {
|
||||||
return { tag_id: "" };
|
return { tag_id: "" };
|
||||||
@ -27,14 +27,16 @@ export class HaTagTrigger extends LitElement implements TriggerElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
const { tag_id } = this.trigger;
|
if (!this._tags) {
|
||||||
|
return html``;
|
||||||
|
}
|
||||||
return html`
|
return html`
|
||||||
<ha-select
|
<ha-select
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.triggers.type.tag.label"
|
"ui.panel.config.automation.editor.triggers.type.tag.label"
|
||||||
)}
|
)}
|
||||||
.disabled=${this._tags.length === 0}
|
.disabled=${this._tags.length === 0}
|
||||||
.value=${tag_id}
|
.value=${this.trigger.tag_id}
|
||||||
@selected=${this._tagChanged}
|
@selected=${this._tagChanged}
|
||||||
>
|
>
|
||||||
${this._tags.map(
|
${this._tags.map(
|
||||||
@ -49,14 +51,17 @@ export class HaTagTrigger extends LitElement implements TriggerElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _fetchTags() {
|
private async _fetchTags() {
|
||||||
this._tags = await fetchTags(this.hass);
|
this._tags = (await fetchTags(this.hass)).sort((a, b) =>
|
||||||
this._tags.sort((a, b) =>
|
|
||||||
caseInsensitiveStringCompare(a.name || a.id, b.name || b.id)
|
caseInsensitiveStringCompare(a.name || a.id, b.name || b.id)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _tagChanged(ev) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
fireEvent(this, "value-changed", {
|
fireEvent(this, "value-changed", {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user