mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 08:16:36 +00:00
Fix target selector (#14895)
This commit is contained in:
parent
0e9a013549
commit
b99a139f51
@ -1,8 +1,4 @@
|
|||||||
import {
|
import { HassEntity, HassServiceTarget } from "home-assistant-js-websocket";
|
||||||
HassEntity,
|
|
||||||
HassServiceTarget,
|
|
||||||
UnsubscribeFunc,
|
|
||||||
} from "home-assistant-js-websocket";
|
|
||||||
import {
|
import {
|
||||||
css,
|
css,
|
||||||
CSSResultGroup,
|
CSSResultGroup,
|
||||||
@ -17,8 +13,7 @@ import {
|
|||||||
DeviceRegistryEntry,
|
DeviceRegistryEntry,
|
||||||
getDeviceIntegrationLookup,
|
getDeviceIntegrationLookup,
|
||||||
} from "../../data/device_registry";
|
} from "../../data/device_registry";
|
||||||
import type { EntityRegistryEntry } from "../../data/entity_registry";
|
import { EntityRegistryEntry } from "../../data/entity_registry";
|
||||||
import { subscribeEntityRegistry } from "../../data/entity_registry";
|
|
||||||
import {
|
import {
|
||||||
EntitySources,
|
EntitySources,
|
||||||
fetchEntitySourcesWithCache,
|
fetchEntitySourcesWithCache,
|
||||||
@ -28,12 +23,11 @@ import {
|
|||||||
filterSelectorEntities,
|
filterSelectorEntities,
|
||||||
TargetSelector,
|
TargetSelector,
|
||||||
} from "../../data/selector";
|
} from "../../data/selector";
|
||||||
import { SubscribeMixin } from "../../mixins/subscribe-mixin";
|
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import "../ha-target-picker";
|
import "../ha-target-picker";
|
||||||
|
|
||||||
@customElement("ha-selector-target")
|
@customElement("ha-selector-target")
|
||||||
export class HaTargetSelector extends SubscribeMixin(LitElement) {
|
export class HaTargetSelector extends LitElement {
|
||||||
@property() public hass!: HomeAssistant;
|
@property() public hass!: HomeAssistant;
|
||||||
|
|
||||||
@property() public selector!: TargetSelector;
|
@property() public selector!: TargetSelector;
|
||||||
@ -48,18 +42,8 @@ export class HaTargetSelector extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
@state() private _entitySources?: EntitySources;
|
@state() private _entitySources?: EntitySources;
|
||||||
|
|
||||||
@state() private _entities?: EntityRegistryEntry[];
|
|
||||||
|
|
||||||
private _deviceIntegrationLookup = memoizeOne(getDeviceIntegrationLookup);
|
private _deviceIntegrationLookup = memoizeOne(getDeviceIntegrationLookup);
|
||||||
|
|
||||||
public hassSubscribe(): UnsubscribeFunc[] {
|
|
||||||
return [
|
|
||||||
subscribeEntityRegistry(this.hass.connection!, (entities) => {
|
|
||||||
this._entities = entities.filter((entity) => entity.device_id !== null);
|
|
||||||
}),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
protected updated(changedProperties: PropertyValues): void {
|
protected updated(changedProperties: PropertyValues): void {
|
||||||
super.updated(changedProperties);
|
super.updated(changedProperties);
|
||||||
if (
|
if (
|
||||||
@ -88,12 +72,19 @@ export class HaTargetSelector extends SubscribeMixin(LitElement) {
|
|||||||
.value=${this.value}
|
.value=${this.value}
|
||||||
.helper=${this.helper}
|
.helper=${this.helper}
|
||||||
.deviceFilter=${this._filterDevices}
|
.deviceFilter=${this._filterDevices}
|
||||||
.entityFilter=${this._filterEntities}
|
.entityFilter=${this._filterStates}
|
||||||
|
.entityRegFilter=${this._filterRegEntities}
|
||||||
|
.includeDeviceClasses=${this.selector.target?.entity?.device_class
|
||||||
|
? [this.selector.target?.entity.device_class]
|
||||||
|
: undefined}
|
||||||
|
.includeDomains=${this.selector.target?.entity?.domain
|
||||||
|
? [this.selector.target?.entity.domain]
|
||||||
|
: undefined}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
></ha-target-picker>`;
|
></ha-target-picker>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _filterEntities = (entity: HassEntity): boolean => {
|
private _filterStates = (entity: HassEntity): boolean => {
|
||||||
if (!this.selector.target?.entity) {
|
if (!this.selector.target?.entity) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -105,15 +96,26 @@ export class HaTargetSelector extends SubscribeMixin(LitElement) {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private _filterRegEntities = (entity: EntityRegistryEntry): boolean => {
|
||||||
|
if (this.selector.target?.entity?.integration) {
|
||||||
|
if (entity.platform !== this.selector.target.entity.integration) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
private _filterDevices = (device: DeviceRegistryEntry): boolean => {
|
private _filterDevices = (device: DeviceRegistryEntry): boolean => {
|
||||||
if (!this.selector.target?.device) {
|
if (!this.selector.target?.device) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const deviceIntegrations =
|
const deviceIntegrations = this._entitySources
|
||||||
this._entitySources && this._entities
|
? this._deviceIntegrationLookup(
|
||||||
? this._deviceIntegrationLookup(this._entitySources, this._entities)
|
this._entitySources,
|
||||||
: undefined;
|
Object.values(this.hass.entities)
|
||||||
|
)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
return filterSelectorDevices(
|
return filterSelectorDevices(
|
||||||
this.selector.target.device,
|
this.selector.target.device,
|
||||||
|
@ -358,7 +358,6 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
"ui.components.target-picker.add_device_id"
|
"ui.components.target-picker.add_device_id"
|
||||||
)}
|
)}
|
||||||
.deviceFilter=${this.deviceFilter}
|
.deviceFilter=${this.deviceFilter}
|
||||||
.entityFilter=${this.entityRegFilter}
|
|
||||||
.includeDeviceClasses=${this.includeDeviceClasses}
|
.includeDeviceClasses=${this.includeDeviceClasses}
|
||||||
.includeDomains=${this.includeDomains}
|
.includeDomains=${this.includeDomains}
|
||||||
@value-changed=${this._targetPicked}
|
@value-changed=${this._targetPicked}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user