Skip to content

Commit

Permalink
Add max branches configuration from GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
davet2001 committed Jan 6, 2025
1 parent 8316699 commit 1fe4426
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/hui-power-flow-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ class HuiPowerFlowCard extends LitElement implements LovelaceCard {
delete (config.generation_entity)
}

const maxConsumerBranches = this._config.max_consumer_branches || 0;

let gridInRoute: ElecRoute | null = null;
if (config.power_from_grid_entity) {
const stateObj = this.hass.states[config.power_from_grid_entity];
Expand Down Expand Up @@ -322,6 +324,7 @@ class HuiPowerFlowCard extends LitElement implements LovelaceCard {
.gridOutRoute=${gridOutRoute || undefined}
.generationInRoutes=${generationInRoutes}
.consumerRoutes=${consumerRoutes}
.maxConsumerBranches=${maxConsumerBranches}
></ha-elec-sankey>
</div>
</ha-card>
Expand Down
16 changes: 16 additions & 0 deletions src/power-flow-card-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ const schema = [
}
}
},
{
name: "max_consumer_branches",
selector: {
number: {
min: 0,
max: 10,
mode: "slider",
}
}
}
// { name: "group_small", selector: { boolean: {} } },
];

Expand All @@ -61,6 +71,7 @@ export class PowerFlowCardEditor extends LitElement implements LovelaceCardEdito
case "power_from_grid_entity": return "Power from grid";
case "group_small": return "Group low values together";
case "generation_entity": return "Power from generation (optional)";
case "max_consumer_branches": return "Limit displayed consumer branches (0 for unlimited)";
}
console.error("Error name key missing for '" + schema.name + "'")
return ""
Expand Down Expand Up @@ -145,6 +156,11 @@ export class PowerFlowCardEditor extends LitElement implements LovelaceCardEdito
configValue = "generation_entity";
value = value.generation_entity;
}
else if (value.max_consumer_branches
!== this._config.max_consumer_branches || -1) {
configValue = "max_consumer_branches";
value = value.max_consumer_branches;
}
else {
console.warn("unhandled change in <ha-form>");
}
Expand Down

0 comments on commit 1fe4426

Please sign in to comment.