From 2626001ca2f30e51678c82c5ed3369bac43804d3 Mon Sep 17 00:00:00 2001 From: Mindfreeze Date: Wed, 16 Nov 2022 17:38:02 +0200 Subject: [PATCH] feat: allow children of `remaining_parent_state` entities --- src/chart.ts | 48 +++++++++++++++++++++++------------------------- src/utils.ts | 5 +---- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/src/chart.ts b/src/chart.ts index f878789..81aca85 100644 --- a/src/chart.ts +++ b/src/chart.ts @@ -72,31 +72,29 @@ export class Chart extends LitElement { if (ent.type === 'entity') { this.entityIds.push(ent.entity_id); } - if (ent.type !== 'remaining_parent_state') { - ent.children.forEach((childId) => { - const child = this.config.sections[sectionIndex + 1]?.entities.find((e) => e.entity_id === childId); - if (!child) { - throw new Error(localize('common.missing_child') + ' ' + childId); - } - const connection: ConnectionState = { - parent: ent, - child, - state: 0, - prevParentState: 0, - prevChildState: 0, - ready: false, - }; - this.connections.push(connection); - if (!this.connectionsByParent.has(ent)) { - this.connectionsByParent.set(ent, []); - } - this.connectionsByParent.get(ent)!.push(connection); - if (!this.connectionsByChild.has(child)) { - this.connectionsByChild.set(child, []); - } - this.connectionsByChild.get(child)!.push(connection); - }); - } + ent.children.forEach((childId) => { + const child = this.config.sections[sectionIndex + 1]?.entities.find((e) => e.entity_id === childId); + if (!child) { + throw new Error(localize('common.missing_child') + ' ' + childId); + } + const connection: ConnectionState = { + parent: ent, + child, + state: 0, + prevParentState: 0, + prevChildState: 0, + ready: false, + }; + this.connections.push(connection); + if (!this.connectionsByParent.has(ent)) { + this.connectionsByParent.set(ent, []); + } + this.connectionsByParent.get(ent)!.push(connection); + if (!this.connectionsByChild.has(child)) { + this.connectionsByChild.set(child, []); + } + this.connectionsByChild.get(child)!.push(connection); + }); }); }); } diff --git a/src/utils.ts b/src/utils.ts index 6c84401..3414662 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -43,9 +43,6 @@ export function getEntityId(entity: EntityConfigOrStr): string { } export function getChildConnections(parent: Box, children: Box[], connections?: ConnectionState[]): Connection[] { - if (parent.config.type === 'remaining_parent_state') { - return []; - } return children.map(child => { const connection = connections?.find(c => c.child.entity_id === child.entity_id); if (!connection) { @@ -134,7 +131,7 @@ export function normalizeConfig(conf: SankeyChartConfig): Config { entity_id: newChildId, type: 'remaining_parent_state', remaining: undefined, - // children: [], + children: [], // accountedState: 0, // foundChildren: [], },