From e56ac45549ea83e35524052bc2039de15f829516 Mon Sep 17 00:00:00 2001 From: Jakub Dabrowski Date: Fri, 9 Apr 2021 23:03:04 +0200 Subject: [PATCH 1/3] Add picking entity on click on scene edtior --- src/panels/config/scene/ha-scene-editor.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/panels/config/scene/ha-scene-editor.ts b/src/panels/config/scene/ha-scene-editor.ts index 1f02dec32c95..c3ab2be53622 100644 --- a/src/panels/config/scene/ha-scene-editor.ts +++ b/src/panels/config/scene/ha-scene-editor.ts @@ -497,6 +497,7 @@ export class HaSceneEditor extends SubscribeMixin( private _showMoreInfo(ev: Event) { const entityId = (ev.currentTarget as any).entityId; fireEvent(this, "hass-more-info", { entityId }); + this._pickEntity(entityId); } private async _loadConfig() { @@ -549,10 +550,7 @@ export class HaSceneEditor extends SubscribeMixin( } } } - - private _entityPicked(ev: CustomEvent) { - const entityId = ev.detail.value; - (ev.target as any).value = ""; + private _pickEntity(entityId: string) { if (this._entities.includes(entityId)) { return; } @@ -573,6 +571,12 @@ export class HaSceneEditor extends SubscribeMixin( this._dirty = true; } + private _entityPicked(ev: CustomEvent) { + const entityId = ev.detail.value; + (ev.target as any).value = ""; + this._pickEntity(entityId); + } + private _deleteEntity(ev: Event) { ev.stopPropagation(); const deleteEntityId = (ev.target as any).entityId; From ad30a9de5a5469c23ca371e9cbae2ac8f2784236 Mon Sep 17 00:00:00 2001 From: Jakub Dabrowski Date: Fri, 9 Apr 2021 23:46:36 +0200 Subject: [PATCH 2/3] Fix code formatting --- src/panels/config/scene/ha-scene-editor.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/panels/config/scene/ha-scene-editor.ts b/src/panels/config/scene/ha-scene-editor.ts index c3ab2be53622..a9bbca44f614 100644 --- a/src/panels/config/scene/ha-scene-editor.ts +++ b/src/panels/config/scene/ha-scene-editor.ts @@ -550,6 +550,7 @@ export class HaSceneEditor extends SubscribeMixin( } } } + private _pickEntity(entityId: string) { if (this._entities.includes(entityId)) { return; From 7f9b4f53e1a3b3036445943467367cac59b3c574 Mon Sep 17 00:00:00 2001 From: Jakub Dabrowski Date: Sun, 11 Apr 2021 08:52:09 +0200 Subject: [PATCH 3/3] Fix logic --- src/panels/config/scene/ha-scene-editor.ts | 37 ++++++++++------------ 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/panels/config/scene/ha-scene-editor.ts b/src/panels/config/scene/ha-scene-editor.ts index a9bbca44f614..c3c9c32450b9 100644 --- a/src/panels/config/scene/ha-scene-editor.ts +++ b/src/panels/config/scene/ha-scene-editor.ts @@ -497,7 +497,6 @@ export class HaSceneEditor extends SubscribeMixin( private _showMoreInfo(ev: Event) { const entityId = (ev.currentTarget as any).entityId; fireEvent(this, "hass-more-info", { entityId }); - this._pickEntity(entityId); } private async _loadConfig() { @@ -551,33 +550,27 @@ export class HaSceneEditor extends SubscribeMixin( } } - private _pickEntity(entityId: string) { + private _entityPicked(ev: CustomEvent) { + const entityId = ev.detail.value; + (ev.target as any).value = ""; if (this._entities.includes(entityId)) { return; } - this._entities = [...this._entities, entityId]; - this._storeState(entityId); - const entityRegistry = this._entityRegistryEntries.find( (entityReg) => entityReg.entity_id === entityId ); - if ( entityRegistry?.device_id && !this._devices.includes(entityRegistry.device_id) ) { - this._devices = [...this._devices, entityRegistry.device_id]; + this._pickDevice(entityRegistry.device_id); + } else { + this._entities = [...this._entities, entityId]; + this._storeState(entityId); } - this._dirty = true; } - private _entityPicked(ev: CustomEvent) { - const entityId = ev.detail.value; - (ev.target as any).value = ""; - this._pickEntity(entityId); - } - private _deleteEntity(ev: Event) { ev.stopPropagation(); const deleteEntityId = (ev.target as any).entityId; @@ -587,14 +580,12 @@ export class HaSceneEditor extends SubscribeMixin( this._dirty = true; } - private _devicePicked(ev: CustomEvent) { - const device = ev.detail.value; - (ev.target as any).value = ""; - if (this._devices.includes(device)) { + private _pickDevice(device_id: string) { + if (this._devices.includes(device_id)) { return; } - this._devices = [...this._devices, device]; - const deviceEntities = this._deviceEntityLookup[device]; + this._devices = [...this._devices, device_id]; + const deviceEntities = this._deviceEntityLookup[device_id]; if (!deviceEntities) { return; } @@ -605,6 +596,12 @@ export class HaSceneEditor extends SubscribeMixin( this._dirty = true; } + private _devicePicked(ev: CustomEvent) { + const device = ev.detail.value; + (ev.target as any).value = ""; + this._pickDevice(device); + } + private _deleteDevice(ev: Event) { const deviceId = (ev.target as any).device; this._devices = this._devices.filter((device) => device !== deviceId);