@@ -7640,7 +7640,7 @@ let HausgeistCardEditor = class HausgeistCardEditor extends i$x {
76407640 this.rulesJson = '';
76417641 this.notify = false;
76427642 this.highThreshold = 2000;
7643- this._hasHaEntityComboBox = !!customElements.get('ha-entity-combo-box') ;
7643+ this._selectorReady = false ;
76447644 this._lastAreas = [];
76457645 // Use arrow function to auto-bind 'this'
76467646 this._onDebugChange = (e) => {
@@ -7715,16 +7715,12 @@ let HausgeistCardEditor = class HausgeistCardEditor extends i$x {
77157715 }
77167716 set hass(hass) {
77177717 this._hass = hass;
7718+ this._ensureSelectorSystem();
77187719 this.requestUpdate();
77197720 }
77207721 connectedCallback() {
77217722 super.connectedCallback();
7722- this._ensureHaEntityComboBox();
7723- customElements.whenDefined('ha-entity-combo-box').then(() => {
7724- if (!this.isConnected)
7725- return;
7726- this._hasHaEntityComboBox = true;
7727- });
7723+ this._ensureSelectorSystem();
77287724 }
77297725 // Handle sensor selection change for a specific area and type
77307726 _onAreaSensorChange(areaId, type, value) {
@@ -8065,59 +8061,41 @@ let HausgeistCardEditor = class HausgeistCardEditor extends i$x {
80658061 </div>
80668062 `;
80678063 }
8068- async _ensureHaEntityComboBox() {
8069- if (this._hasHaEntityComboBox) {
8070- return;
8071- }
8072- const helpersLoader = window?.loadCardHelpers;
8073- if (typeof helpersLoader === 'function') {
8074- try {
8075- const helpers = await helpersLoader();
8076- const glanceCard = await helpers?.createCardElement?.({ type: 'glance' });
8077- await glanceCard?.getConfigElement?.();
8078- }
8079- catch (error) {
8080- if (this.config?.debug) {
8081- console.warn('Failed to load card helpers for ha-entity-combo-box', error);
8082- }
8083- }
8084- }
8085- const glanceCtor = customElements.get('hui-glance-card');
8086- if (glanceCtor?.getConfigElement) {
8087- try {
8088- await glanceCtor.getConfigElement();
8089- }
8090- catch (error) {
8091- if (this.config?.debug) {
8092- console.warn('Failed to load hui-glance-card editor', error);
8093- }
8094- }
8095- }
8096- this._hasHaEntityComboBox = !!customElements.get('ha-entity-combo-box');
8097- }
80988064 _renderEntityPicker({ value, includeDomains, area, options, placeholder, onChange, }) {
8099- if (this._hasHaEntityComboBox) {
8065+ const optionList = options?.length
8066+ ? [...options]
8067+ : this._createOptionsForDomains(includeDomains, area);
8068+ if (value && !optionList.some(option => option.entity_id === value)) {
8069+ optionList.unshift({ entity_id: value, label: value });
8070+ }
8071+ const selectorConfig = optionList.length
8072+ ? { entity: { entity_id: optionList.map(option => option.entity_id) } }
8073+ : includeDomains?.length
8074+ ? { entity: { domain: includeDomains.length === 1 ? includeDomains[0] : includeDomains } }
8075+ : { entity: {} };
8076+ if (this._selectorReady && customElements.get('ha-selector')) {
81008077 return x$6 `
8101- <ha-entity-combo-box
8078+ <ha-selector
81028079 .hass=${this.hass}
8080+ .selector=${selectorConfig}
81038081 .value=${value || ''}
8104- .includeDomains=${includeDomains}
8105- .area=${area}
8106- @value-changed=${(e) => onChange(e.detail?.value ?? '')}
8107- ></ha-entity-combo-box>
8082+ .label=${placeholder || undefined}
8083+ @value-changed=${(e) => onChange((e.detail && 'value' in e.detail) ? e.detail.value || '' : '')}
8084+ ></ha-selector>
81088085 `;
81098086 }
8110- const fallbackOptions = options?.length
8111- ? options
8112- : this._createOptionsForDomains(includeDomains, area);
81138087 return x$6 `
8114- <select
8088+ <mwc-select
8089+ outlined
81158090 .value=${value || ''}
8116- @change=${(event) => onChange(event.target.value)}
8091+ @selected=${(event) => {
8092+ const select = event.target;
8093+ onChange(select?.value || '');
8094+ }}
81178095 >
8118- <option value="">${placeholder || 'Select entity '}</option >
8119- ${fallbackOptions .map(option => x$6 `<option value=${option.entity_id}>${option.label}</option >`)}
8120- </select>
8096+ <mwc-list-item value="">${placeholder || 'Keine Auswahl '}</mwc-list-item >
8097+ ${optionList .map(option => x$6 `<mwc-list-item value=${option.entity_id}>${option.label}</mwc-list-item >`)}
8098+ </mwc- select>
81218099 `;
81228100 }
81238101 _createOptionsForDomains(includeDomains, area) {
@@ -8151,6 +8129,38 @@ let HausgeistCardEditor = class HausgeistCardEditor extends i$x {
81518129 options.sort((a, b) => a.label.localeCompare(b.label));
81528130 return options;
81538131 }
8132+ async _ensureSelectorSystem() {
8133+ if (this._selectorReady) {
8134+ return;
8135+ }
8136+ const helpersLoader = window?.loadCardHelpers;
8137+ if (typeof helpersLoader === 'function') {
8138+ try {
8139+ const helpers = await helpersLoader();
8140+ await helpers?.loadHaForm?.();
8141+ }
8142+ catch (error) {
8143+ if (this.config?.debug) {
8144+ console.warn('Failed to load selector helpers', error);
8145+ }
8146+ }
8147+ }
8148+ if (customElements.get('ha-selector')) {
8149+ this._selectorReady = true;
8150+ return;
8151+ }
8152+ try {
8153+ await customElements.whenDefined('ha-selector');
8154+ if (this.isConnected) {
8155+ this._selectorReady = true;
8156+ }
8157+ }
8158+ catch (error) {
8159+ if (this.config?.debug) {
8160+ console.warn('ha-selector never became available', error);
8161+ }
8162+ }
8163+ }
81548164};
81558165__decorate$1([
81568166 n$H({ type: Object })
@@ -8169,7 +8179,7 @@ __decorate$1([
81698179], HausgeistCardEditor.prototype, "highThreshold", void 0);
81708180__decorate$1([
81718181 r$l()
8172- ], HausgeistCardEditor.prototype, "_hasHaEntityComboBox ", void 0);
8182+ ], HausgeistCardEditor.prototype, "_selectorReady ", void 0);
81738183HausgeistCardEditor = __decorate$1([
81748184 t$p('hausgeist-card-editor')
81758185], HausgeistCardEditor);
0 commit comments