diff --git a/src/editor/components/EntitySelector.ts b/src/editor/components/EntitySelector.ts index 31db8b978d..4d749ccc62 100644 --- a/src/editor/components/EntitySelector.ts +++ b/src/editor/components/EntitySelector.ts @@ -1,14 +1,10 @@ -import { HassEntity } from 'home-assistant-js-websocket'; - -import { byPropertiesOf } from '../../helpers/sort'; import { openEntityFilter } from '../editors/entity-filter'; import { getEntities, getUiSettings } from '../haserver'; import { disableSelect2OpenOnRemove } from '../utils'; import { - createCustomIdListByProperty, createSelect2Options, isSelect2Initialized, - Select2Data, + Select2AjaxEndpoints, Tags, } from './select2'; @@ -18,17 +14,20 @@ export default class EntitySelector { #$filterType: JQuery; #$filterButton: JQuery; #entityId: string | string[]; - #select2Data: Select2Data[]; + #serverId?: string; constructor({ filterTypeSelector, entityId, + serverId, }: { filterTypeSelector: string; entityId: string | string[]; + serverId?: string; }) { this.#$filterType = $(filterTypeSelector); this.#entityId = entityId; + this.#serverId = serverId; this.#buildElements(); this.init(); @@ -55,13 +54,40 @@ export default class EntitySelector { return id; } + #generateEntityList() { + const entities = getEntities(); + const ids = !Array.isArray(this.#entityId) + ? [this.#entityId] + : this.#entityId; + + const options = ids.reduce((acc: JQuery[], id: string) => { + const text = + getUiSettings().entitySelector === 'id' + ? id + : entities.find((e) => e.entity_id === id)?.attributes + .friendly_name ?? id; + acc.push( + $('