Prevent duplicate entities from being chosen in the target picker (#14882)

Co-authored-by: Bram Kragten <mail@bramkragten.nl>
fixes undefined
This commit is contained in:
karwosts
2022-12-28 05:24:32 -08:00
committed by GitHub
parent 6a15216104
commit 1198f983aa
3 changed files with 51 additions and 6 deletions

View File

@@ -84,6 +84,14 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
@property({ type: Array, attribute: "include-device-classes" })
public includeDeviceClasses?: string[];
/**
* List of devices to be excluded.
* @type {Array}
* @attr exclude-devices
*/
@property({ type: Array, attribute: "exclude-devices" })
public excludeDevices?: string[];
@property() public deviceFilter?: HaDevicePickerDeviceFilterFunc;
@property({ type: Boolean }) public disabled?: boolean;
@@ -104,7 +112,8 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
includeDomains: this["includeDomains"],
excludeDomains: this["excludeDomains"],
includeDeviceClasses: this["includeDeviceClasses"],
deviceFilter: this["deviceFilter"]
deviceFilter: this["deviceFilter"],
excludeDevices: this["excludeDevices"]
): Device[] => {
if (!devices.length) {
return [
@@ -164,6 +173,12 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
});
}
if (excludeDevices) {
inputDevices = inputDevices.filter(
(device) => !excludeDevices!.includes(device.id)
);
}
if (includeDeviceClasses) {
inputDevices = inputDevices.filter((device) => {
const devEntities = deviceEntityLookup[device.id];
@@ -258,7 +273,8 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
this.includeDomains,
this.excludeDomains,
this.includeDeviceClasses,
this.deviceFilter
this.deviceFilter,
this.excludeDevices
);
}
}