Skip to content

Commit

Permalink
feat: allow children of remaining_parent_state entities
Browse files Browse the repository at this point in the history
  • Loading branch information
MindFreeze committed Nov 16, 2022
1 parent ea6f91c commit 2626001
Showing 2 changed files with 24 additions and 29 deletions.
48 changes: 23 additions & 25 deletions src/chart.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
}
5 changes: 1 addition & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -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: [],
},

0 comments on commit 2626001

Please sign in to comment.