mirror of
https://github.com/home-assistant/frontend.git
synced 2025-04-26 06:17:20 +00:00
Exclude config and diagnostic entities from scenes (#13072)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
parent
b70eee77ef
commit
8fd5f53f96
@ -107,6 +107,8 @@ export class HaSceneEditor extends SubscribeMixin(
|
|||||||
|
|
||||||
@state() private _entities: string[] = [];
|
@state() private _entities: string[] = [];
|
||||||
|
|
||||||
|
private _single_entities: string[] = [];
|
||||||
|
|
||||||
@state() private _devices: string[] = [];
|
@state() private _devices: string[] = [];
|
||||||
|
|
||||||
@state()
|
@state()
|
||||||
@ -121,7 +123,7 @@ export class HaSceneEditor extends SubscribeMixin(
|
|||||||
|
|
||||||
private _unsubscribeEvents?: () => void;
|
private _unsubscribeEvents?: () => void;
|
||||||
|
|
||||||
@state() private _deviceEntityLookup: DeviceEntitiesLookup = {};
|
private _deviceEntityLookup: DeviceEntitiesLookup = {};
|
||||||
|
|
||||||
private _activateContextId?: string;
|
private _activateContextId?: string;
|
||||||
|
|
||||||
@ -520,9 +522,11 @@ export class HaSceneEditor extends SubscribeMixin(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (changedProps.has("_entityRegistryEntries")) {
|
if (changedProps.has("_entityRegistryEntries")) {
|
||||||
|
this._deviceEntityLookup = {};
|
||||||
for (const entity of this._entityRegistryEntries) {
|
for (const entity of this._entityRegistryEntries) {
|
||||||
if (
|
if (
|
||||||
!entity.device_id ||
|
!entity.device_id ||
|
||||||
|
entity.entity_category ||
|
||||||
SCENE_IGNORED_DOMAINS.includes(computeDomain(entity.entity_id))
|
SCENE_IGNORED_DOMAINS.includes(computeDomain(entity.entity_id))
|
||||||
) {
|
) {
|
||||||
continue;
|
continue;
|
||||||
@ -530,13 +534,10 @@ export class HaSceneEditor extends SubscribeMixin(
|
|||||||
if (!(entity.device_id in this._deviceEntityLookup)) {
|
if (!(entity.device_id in this._deviceEntityLookup)) {
|
||||||
this._deviceEntityLookup[entity.device_id] = [];
|
this._deviceEntityLookup[entity.device_id] = [];
|
||||||
}
|
}
|
||||||
if (
|
this._deviceEntityLookup[entity.device_id].push(entity.entity_id);
|
||||||
!this._deviceEntityLookup[entity.device_id].includes(entity.entity_id)
|
|
||||||
) {
|
|
||||||
this._deviceEntityLookup[entity.device_id].push(entity.entity_id);
|
|
||||||
}
|
|
||||||
if (
|
if (
|
||||||
this._entities.includes(entity.entity_id) &&
|
this._entities.includes(entity.entity_id) &&
|
||||||
|
!this._single_entities.includes(entity.device_id) &&
|
||||||
!this._devices.includes(entity.device_id)
|
!this._devices.includes(entity.device_id)
|
||||||
) {
|
) {
|
||||||
this._devices = [...this._devices, entity.device_id];
|
this._devices = [...this._devices, entity.device_id];
|
||||||
@ -625,12 +626,24 @@ export class HaSceneEditor extends SubscribeMixin(
|
|||||||
private _initEntities(config: SceneConfig) {
|
private _initEntities(config: SceneConfig) {
|
||||||
this._entities = Object.keys(config.entities);
|
this._entities = Object.keys(config.entities);
|
||||||
this._entities.forEach((entity) => this._storeState(entity));
|
this._entities.forEach((entity) => this._storeState(entity));
|
||||||
|
this._single_entities = [];
|
||||||
|
|
||||||
const filteredEntityReg = this._entityRegistryEntries.filter((entityReg) =>
|
const filteredEntityReg = this._entityRegistryEntries.filter((entityReg) =>
|
||||||
this._entities.includes(entityReg.entity_id)
|
this._entities.includes(entityReg.entity_id)
|
||||||
);
|
);
|
||||||
const newDevices: string[] = [];
|
const newDevices: string[] = [];
|
||||||
|
|
||||||
|
if (config.metadata) {
|
||||||
|
Object.keys(config.entities).forEach((entity) => {
|
||||||
|
if (
|
||||||
|
!this._single_entities.includes(entity) &&
|
||||||
|
config.metadata![entity].entity_only
|
||||||
|
) {
|
||||||
|
this._single_entities.push(entity);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
for (const entityReg of filteredEntityReg) {
|
for (const entityReg of filteredEntityReg) {
|
||||||
if (!entityReg.device_id) {
|
if (!entityReg.device_id) {
|
||||||
continue;
|
continue;
|
||||||
@ -654,6 +667,7 @@ export class HaSceneEditor extends SubscribeMixin(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._entities = [...this._entities, entityId];
|
this._entities = [...this._entities, entityId];
|
||||||
|
this._single_entities.push(entityId);
|
||||||
this._storeState(entityId);
|
this._storeState(entityId);
|
||||||
this._dirty = true;
|
this._dirty = true;
|
||||||
}
|
}
|
||||||
@ -664,6 +678,9 @@ export class HaSceneEditor extends SubscribeMixin(
|
|||||||
this._entities = this._entities.filter(
|
this._entities = this._entities.filter(
|
||||||
(entityId) => entityId !== deleteEntityId
|
(entityId) => entityId !== deleteEntityId
|
||||||
);
|
);
|
||||||
|
this._single_entities = this._single_entities.filter(
|
||||||
|
(entityId) => entityId !== deleteEntityId
|
||||||
|
);
|
||||||
this._dirty = true;
|
this._dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -815,19 +832,15 @@ export class HaSceneEditor extends SubscribeMixin(
|
|||||||
private _calculateMetaData(): SceneMetaData {
|
private _calculateMetaData(): SceneMetaData {
|
||||||
const output: SceneMetaData = {};
|
const output: SceneMetaData = {};
|
||||||
|
|
||||||
for (const entityReg of this._entityRegistryEntries) {
|
for (const entityId of this._single_entities) {
|
||||||
if (!this._entities.includes(entityReg.entity_id)) {
|
const entityState = this._getCurrentState(entityId);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const entityState = this._getCurrentState(entityReg.entity_id);
|
|
||||||
|
|
||||||
if (!entityState) {
|
if (!entityState) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
output[entityReg.entity_id] = {
|
output[entityId] = {
|
||||||
entity_only: !this._devices.includes(entityReg.device_id!),
|
entity_only: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user