Convert entity picker to ha-combo (#11560)

* Convert entity picker to ha-combo

* Update ha-entity-picker.ts

* Handle empty better

* Clear value when no device/area/entity
This commit is contained in:
Bram Kragten
2022-02-07 10:59:11 +01:00
committed by GitHub
parent d05f807b9d
commit 76af6e48cd
6 changed files with 77 additions and 129 deletions

View File

@@ -38,7 +38,7 @@ export type HaDevicePickerDeviceFilterFunc = (
) => boolean;
const rowRenderer: ComboBoxLitRenderer<Device> = (item) => html`<mwc-list-item
twoline
.twoline=${!!item.area}
>
<span>${item.name}</span>
<span slot="secondary">${item.area}</span>
@@ -105,7 +105,7 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
if (!devices.length) {
return [
{
id: "",
id: "no_devices",
area: "",
name: this.hass.localize("ui.components.device-picker.no_devices"),
},
@@ -201,7 +201,7 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
if (!outputDevices.length) {
return [
{
id: "",
id: "no_devices",
area: "",
name: this.hass.localize("ui.components.device-picker.no_match"),
},
@@ -270,7 +270,6 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
.renderer=${rowRenderer}
.disabled=${this.disabled}
item-value-path="id"
item-id-path="id"
item-label-path="name"
@opened-changed=${this._openedChanged}
@value-changed=${this._deviceChanged}
@@ -284,7 +283,11 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
private _deviceChanged(ev: PolymerChangedEvent<string>) {
ev.stopPropagation();
const newValue = ev.detail.value;
let newValue = ev.detail.value;
if (newValue === "no_devices") {
newValue = "";
}
if (newValue !== this._value) {
this._setValue(newValue);