Add message when no entities found in the entity picker (#25222)

This commit is contained in:
Paul Bottein 2025-04-29 14:34:09 +02:00 committed by GitHub
parent fddc00bfab
commit 574f9e8936
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -57,6 +57,7 @@ interface EntityComboBoxItem extends HassEntity {
export type HaEntityComboBoxEntityFilterFunc = (entity: HassEntity) => boolean; export type HaEntityComboBoxEntityFilterFunc = (entity: HassEntity) => boolean;
const CREATE_ID = "___create-new-entity___"; const CREATE_ID = "___create-new-entity___";
const NO_ENTITIES_ID = "___no-entities___";
const DOMAIN_STYLE = styleMap({ const DOMAIN_STYLE = styleMap({
fontSize: "var(--ha-font-size-s)", fontSize: "var(--ha-font-size-s)",
@ -252,6 +253,7 @@ export class HaEntityComboBox extends LitElement {
{ {
...FAKE_ENTITY, ...FAKE_ENTITY,
label: "", label: "",
entity_id: NO_ENTITIES_ID,
primary: this.hass!.localize( primary: this.hass!.localize(
"ui.components.entity.entity-picker.no_entities" "ui.components.entity.entity-picker.no_entities"
), ),
@ -367,6 +369,7 @@ export class HaEntityComboBox extends LitElement {
{ {
...FAKE_ENTITY, ...FAKE_ENTITY,
label: "", label: "",
entity_id: NO_ENTITIES_ID,
primary: this.hass!.localize( primary: this.hass!.localize(
"ui.components.entity.entity-picker.no_match" "ui.components.entity.entity-picker.no_match"
), ),
@ -499,7 +502,21 @@ export class HaEntityComboBox extends LitElement {
const results = fuse.multiTermsSearch(filterString); const results = fuse.multiTermsSearch(filterString);
if (results) { 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 { } else {
target.filteredItems = this._items; target.filteredItems = this._items;
} }