Fix entity and device selector with multiple: true

This commit is contained in:
Philip Allgaier 2022-04-07 21:39:04 +02:00
parent 0a4e8fd5d0
commit 8f67aa38af
4 changed files with 19 additions and 2 deletions

View File

@ -3,7 +3,7 @@ import { customElement, property } from "lit/decorators";
import { fireEvent } from "../../common/dom/fire_event"; import { fireEvent } from "../../common/dom/fire_event";
import { PolymerChangedEvent } from "../../polymer-types"; import { PolymerChangedEvent } from "../../polymer-types";
import { HomeAssistant } from "../../types"; import { HomeAssistant } from "../../types";
import "./ha-device-picker"; import { HaDevicePickerDeviceFilterFunc } from "./ha-device-picker";
@customElement("ha-devices-picker") @customElement("ha-devices-picker")
class HaDevicesPicker extends LitElement { class HaDevicesPicker extends LitElement {
@ -13,6 +13,8 @@ class HaDevicesPicker extends LitElement {
@property() public helper?: string; @property() public helper?: string;
@property({ type: Boolean }) public disabled?: boolean;
@property({ type: Boolean }) public required?: boolean; @property({ type: Boolean }) public required?: boolean;
/** /**
@ -39,6 +41,8 @@ class HaDevicesPicker extends LitElement {
@property({ attribute: "pick-device-label" }) public pickDeviceLabel?: string; @property({ attribute: "pick-device-label" }) public pickDeviceLabel?: string;
@property() public deviceFilter?: HaDevicePickerDeviceFilterFunc;
protected render(): TemplateResult { protected render(): TemplateResult {
if (!this.hass) { if (!this.hass) {
return html``; return html``;
@ -53,11 +57,13 @@ class HaDevicesPicker extends LitElement {
allow-custom-entity allow-custom-entity
.curValue=${entityId} .curValue=${entityId}
.hass=${this.hass} .hass=${this.hass}
.deviceFilter=${this.deviceFilter}
.includeDomains=${this.includeDomains} .includeDomains=${this.includeDomains}
.excludeDomains=${this.excludeDomains} .excludeDomains=${this.excludeDomains}
.includeDeviceClasses=${this.includeDeviceClasses} .includeDeviceClasses=${this.includeDeviceClasses}
.value=${entityId} .value=${entityId}
.label=${this.pickedDeviceLabel} .label=${this.pickedDeviceLabel}
.disabled=${this.disabled}
@value-changed=${this._deviceChanged} @value-changed=${this._deviceChanged}
></ha-device-picker> ></ha-device-picker>
</div> </div>
@ -65,12 +71,15 @@ class HaDevicesPicker extends LitElement {
)} )}
<div> <div>
<ha-device-picker <ha-device-picker
allow-custom-entity
.hass=${this.hass} .hass=${this.hass}
.helper=${this.helper} .helper=${this.helper}
.deviceFilter=${this.deviceFilter}
.includeDomains=${this.includeDomains} .includeDomains=${this.includeDomains}
.excludeDomains=${this.excludeDomains} .excludeDomains=${this.excludeDomains}
.includeDeviceClasses=${this.includeDeviceClasses} .includeDeviceClasses=${this.includeDeviceClasses}
.label=${this.pickDeviceLabel} .label=${this.pickDeviceLabel}
.disabled=${this.disabled}
.required=${this.required && !currentDevices.length} .required=${this.required && !currentDevices.length}
@value-changed=${this._addDevice} @value-changed=${this._addDevice}
></ha-device-picker> ></ha-device-picker>

View File

@ -14,6 +14,8 @@ class HaEntitiesPickerLight extends LitElement {
@property({ type: Array }) public value?: string[]; @property({ type: Array }) public value?: string[];
@property({ type: Boolean }) public disabled?: boolean;
@property({ type: Boolean }) public required?: boolean; @property({ type: Boolean }) public required?: boolean;
@property() public helper?: string; @property() public helper?: string;
@ -96,6 +98,7 @@ class HaEntitiesPickerLight extends LitElement {
.entityFilter=${this._entityFilter} .entityFilter=${this._entityFilter}
.value=${entityId} .value=${entityId}
.label=${this.pickedEntityLabel} .label=${this.pickedEntityLabel}
.disabled=${this.disabled}
@value-changed=${this._entityChanged} @value-changed=${this._entityChanged}
></ha-entity-picker> ></ha-entity-picker>
</div> </div>
@ -103,6 +106,7 @@ class HaEntitiesPickerLight extends LitElement {
)} )}
<div> <div>
<ha-entity-picker <ha-entity-picker
allow-custom-entity
.hass=${this.hass} .hass=${this.hass}
.includeDomains=${this.includeDomains} .includeDomains=${this.includeDomains}
.excludeDomains=${this.excludeDomains} .excludeDomains=${this.excludeDomains}
@ -113,6 +117,7 @@ class HaEntitiesPickerLight extends LitElement {
.entityFilter=${this._entityFilter} .entityFilter=${this._entityFilter}
.label=${this.pickEntityLabel} .label=${this.pickEntityLabel}
.helper=${this.helper} .helper=${this.helper}
.disabled=${this.disabled}
.required=${this.required && !currentEntities.length} .required=${this.required && !currentEntities.length}
@value-changed=${this._addEntity} @value-changed=${this._addEntity}
></ha-entity-picker> ></ha-entity-picker>

View File

@ -66,12 +66,14 @@ export class HaDeviceSelector extends LitElement {
.hass=${this.hass} .hass=${this.hass}
.value=${this.value} .value=${this.value}
.helper=${this.helper} .helper=${this.helper}
.deviceFilter=${this._filterDevices}
.includeDeviceClasses=${this.selector.device.entity?.device_class .includeDeviceClasses=${this.selector.device.entity?.device_class
? [this.selector.device.entity.device_class] ? [this.selector.device.entity.device_class]
: undefined} : undefined}
.includeDomains=${this.selector.device.entity?.domain .includeDomains=${this.selector.device.entity?.domain
? [this.selector.device.entity.domain] ? [this.selector.device.entity.domain]
: undefined} : undefined}
.disabled=${this.disabled}
.required=${this.required} .required=${this.required}
></ha-devices-picker> ></ha-devices-picker>
`; `;

View File

@ -51,9 +51,10 @@ export class HaEntitySelector extends LitElement {
.hass=${this.hass} .hass=${this.hass}
.value=${this.value} .value=${this.value}
.helper=${this.helper} .helper=${this.helper}
.entityFilter=${this._filterEntities}
.includeEntities=${this.selector.entity.include_entities} .includeEntities=${this.selector.entity.include_entities}
.excludeEntities=${this.selector.entity.exclude_entities} .excludeEntities=${this.selector.entity.exclude_entities}
.entityFilter=${this._filterEntities}
.disabled=${this.disabled}
.required=${this.required} .required=${this.required}
></ha-entities-picker> ></ha-entities-picker>
`; `;