mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 19:56:42 +00:00
Don't update entity picker items while open (#5588)
* Don't update entity picker items while open * Update items in updated, when we open the dropdown
This commit is contained in:
parent
2503fabe1d
commit
355f40d740
@ -12,6 +12,7 @@ import {
|
|||||||
property,
|
property,
|
||||||
PropertyValues,
|
PropertyValues,
|
||||||
TemplateResult,
|
TemplateResult,
|
||||||
|
query,
|
||||||
} from "lit-element";
|
} from "lit-element";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { fireEvent } from "../../common/dom/fire_event";
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
@ -91,12 +92,13 @@ class HaEntityPicker extends LitElement {
|
|||||||
|
|
||||||
@property() public entityFilter?: HaEntityPickerEntityFilterFunc;
|
@property() public entityFilter?: HaEntityPickerEntityFilterFunc;
|
||||||
|
|
||||||
@property({ type: Boolean }) private _opened?: boolean;
|
@property({ type: Boolean }) private _opened = false;
|
||||||
|
|
||||||
@property() private _hass?: HomeAssistant;
|
@query("vaadin-combo-box-light") private _comboBox!: HTMLElement;
|
||||||
|
|
||||||
private _getStates = memoizeOne(
|
private _getStates = memoizeOne(
|
||||||
(
|
(
|
||||||
|
_opened: boolean,
|
||||||
hass: this["hass"],
|
hass: this["hass"],
|
||||||
includeDomains: this["includeDomains"],
|
includeDomains: this["includeDomains"],
|
||||||
excludeDomains: this["excludeDomains"],
|
excludeDomains: this["excludeDomains"],
|
||||||
@ -147,27 +149,28 @@ class HaEntityPicker extends LitElement {
|
|||||||
);
|
);
|
||||||
|
|
||||||
protected updated(changedProps: PropertyValues) {
|
protected updated(changedProps: PropertyValues) {
|
||||||
super.updated(changedProps);
|
if (changedProps.has("_opened") && this._opened) {
|
||||||
|
|
||||||
if (changedProps.has("hass") && !this._opened) {
|
|
||||||
this._hass = this.hass;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
|
||||||
const states = this._getStates(
|
const states = this._getStates(
|
||||||
this._hass,
|
this._opened,
|
||||||
|
this.hass,
|
||||||
this.includeDomains,
|
this.includeDomains,
|
||||||
this.excludeDomains,
|
this.excludeDomains,
|
||||||
this.entityFilter,
|
this.entityFilter,
|
||||||
this.includeDeviceClasses
|
this.includeDeviceClasses
|
||||||
);
|
);
|
||||||
|
(this._comboBox as any).items = states;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected render(): TemplateResult {
|
||||||
|
if (!this.hass) {
|
||||||
|
return html``;
|
||||||
|
}
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<vaadin-combo-box-light
|
<vaadin-combo-box-light
|
||||||
item-value-path="entity_id"
|
item-value-path="entity_id"
|
||||||
item-label-path="entity_id"
|
item-label-path="entity_id"
|
||||||
.items=${states}
|
|
||||||
.value=${this._value}
|
.value=${this._value}
|
||||||
.allowCustomValue=${this.allowCustomEntity}
|
.allowCustomValue=${this.allowCustomEntity}
|
||||||
.renderer=${rowRenderer}
|
.renderer=${rowRenderer}
|
||||||
@ -176,8 +179,8 @@ class HaEntityPicker extends LitElement {
|
|||||||
>
|
>
|
||||||
<paper-input
|
<paper-input
|
||||||
.autofocus=${this.autofocus}
|
.autofocus=${this.autofocus}
|
||||||
.label=${this.label === undefined && this._hass
|
.label=${this.label === undefined
|
||||||
? this._hass.localize("ui.components.entity.entity-picker.entity")
|
? this.hass.localize("ui.components.entity.entity-picker.entity")
|
||||||
: this.label}
|
: this.label}
|
||||||
.value=${this._value}
|
.value=${this._value}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
@ -190,7 +193,7 @@ class HaEntityPicker extends LitElement {
|
|||||||
${this.value
|
${this.value
|
||||||
? html`
|
? html`
|
||||||
<paper-icon-button
|
<paper-icon-button
|
||||||
aria-label=${this.hass!.localize(
|
aria-label=${this.hass.localize(
|
||||||
"ui.components.entity.entity-picker.clear"
|
"ui.components.entity.entity-picker.clear"
|
||||||
)}
|
)}
|
||||||
slot="suffix"
|
slot="suffix"
|
||||||
@ -203,10 +206,9 @@ class HaEntityPicker extends LitElement {
|
|||||||
</paper-icon-button>
|
</paper-icon-button>
|
||||||
`
|
`
|
||||||
: ""}
|
: ""}
|
||||||
${states.length > 0
|
|
||||||
? html`
|
|
||||||
<paper-icon-button
|
<paper-icon-button
|
||||||
aria-label=${this.hass!.localize(
|
aria-label=${this.hass.localize(
|
||||||
"ui.components.entity.entity-picker.show_entities"
|
"ui.components.entity.entity-picker.show_entities"
|
||||||
)}
|
)}
|
||||||
slot="suffix"
|
slot="suffix"
|
||||||
@ -215,8 +217,6 @@ class HaEntityPicker extends LitElement {
|
|||||||
>
|
>
|
||||||
Toggle
|
Toggle
|
||||||
</paper-icon-button>
|
</paper-icon-button>
|
||||||
`
|
|
||||||
: ""}
|
|
||||||
</paper-input>
|
</paper-input>
|
||||||
</vaadin-combo-box-light>
|
</vaadin-combo-box-light>
|
||||||
`;
|
`;
|
||||||
|
@ -24,7 +24,7 @@ export class HaSceneAction extends LitElement implements ActionElement {
|
|||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.value=${scene}
|
.value=${scene}
|
||||||
@value-changed=${this._entityPicked}
|
@value-changed=${this._entityPicked}
|
||||||
.includeDomains=${["scene"]}
|
include-domains="['scene']"
|
||||||
allow-custom-entity
|
allow-custom-entity
|
||||||
></ha-entity-picker>
|
></ha-entity-picker>
|
||||||
`;
|
`;
|
||||||
|
@ -34,6 +34,8 @@ export class HaServiceAction extends LitElement implements ActionElement {
|
|||||||
return { service: "", data: {} };
|
return { service: "", data: {} };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _domain = memoizeOne((service: string) => [computeDomain(service)]);
|
||||||
|
|
||||||
private _getServiceData = memoizeOne((service: string) => {
|
private _getServiceData = memoizeOne((service: string) => {
|
||||||
if (!service) {
|
if (!service) {
|
||||||
return [];
|
return [];
|
||||||
@ -85,7 +87,7 @@ export class HaServiceAction extends LitElement implements ActionElement {
|
|||||||
.value=${entity_id}
|
.value=${entity_id}
|
||||||
.label=${entity.description}
|
.label=${entity.description}
|
||||||
@value-changed=${this._entityPicked}
|
@value-changed=${this._entityPicked}
|
||||||
.includeDomains=${[computeDomain(service)]}
|
.includeDomains=${this._domain(service)}
|
||||||
allow-custom-entity
|
allow-custom-entity
|
||||||
></ha-entity-picker>
|
></ha-entity-picker>
|
||||||
`
|
`
|
||||||
|
@ -46,7 +46,7 @@ export class HaZoneCondition extends LitElement {
|
|||||||
@value-changed=${this._zonePicked}
|
@value-changed=${this._zonePicked}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
allow-custom-entity
|
allow-custom-entity
|
||||||
.includeDomains=${["zone"]}
|
include-domains="['zone']"
|
||||||
></ha-entity-picker>
|
></ha-entity-picker>
|
||||||
<label id="eventlabel">
|
<label id="eventlabel">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
|
@ -42,7 +42,7 @@ export default class HaGeolocationTrigger extends LitElement {
|
|||||||
@value-changed=${this._zonePicked}
|
@value-changed=${this._zonePicked}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
allow-custom-entity
|
allow-custom-entity
|
||||||
.includeDomains=${["zone"]}
|
include-domains="['zone']"
|
||||||
></ha-entity-picker>
|
></ha-entity-picker>
|
||||||
<label id="eventlabel">
|
<label id="eventlabel">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
|
@ -49,7 +49,7 @@ export class HaZoneTrigger extends LitElement {
|
|||||||
@value-changed=${this._zonePicked}
|
@value-changed=${this._zonePicked}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
allow-custom-entity
|
allow-custom-entity
|
||||||
.includeDomains=${["zone"]}
|
include-domains="['zone']"
|
||||||
></ha-entity-picker>
|
></ha-entity-picker>
|
||||||
<label id="eventlabel">
|
<label id="eventlabel">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user