From 574f9e89362efed7f0a636321a5695af86d49b20 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Tue, 29 Apr 2025 14:34:09 +0200 Subject: [PATCH] Add message when no entities found in the entity picker (#25222) --- src/components/entity/ha-entity-combo-box.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/components/entity/ha-entity-combo-box.ts b/src/components/entity/ha-entity-combo-box.ts index 8deb6abc29..2aa96604f6 100644 --- a/src/components/entity/ha-entity-combo-box.ts +++ b/src/components/entity/ha-entity-combo-box.ts @@ -57,6 +57,7 @@ interface EntityComboBoxItem extends HassEntity { export type HaEntityComboBoxEntityFilterFunc = (entity: HassEntity) => boolean; const CREATE_ID = "___create-new-entity___"; +const NO_ENTITIES_ID = "___no-entities___"; const DOMAIN_STYLE = styleMap({ fontSize: "var(--ha-font-size-s)", @@ -252,6 +253,7 @@ export class HaEntityComboBox extends LitElement { { ...FAKE_ENTITY, label: "", + entity_id: NO_ENTITIES_ID, primary: this.hass!.localize( "ui.components.entity.entity-picker.no_entities" ), @@ -367,6 +369,7 @@ export class HaEntityComboBox extends LitElement { { ...FAKE_ENTITY, label: "", + entity_id: NO_ENTITIES_ID, primary: this.hass!.localize( "ui.components.entity.entity-picker.no_match" ), @@ -499,7 +502,21 @@ export class HaEntityComboBox extends LitElement { const results = fuse.multiTermsSearch(filterString); if (results) { - target.filteredItems = results.map((result) => result.item); + if (results.length === 0) { + target.filteredItems = [ + { + ...FAKE_ENTITY, + label: "", + entity_id: NO_ENTITIES_ID, + primary: this.hass!.localize( + "ui.components.entity.entity-picker.no_match" + ), + icon_path: mdiMagnify, + }, + ] as EntityComboBoxItem[]; + } else { + target.filteredItems = results.map((result) => result.item); + } } else { target.filteredItems = this._items; }