Skip to content

Commit

Permalink
Merge pull request #24 from davet2001/prevent-no-power-config-from-bl…
Browse files Browse the repository at this point in the history
…anking-card

Fix issue where invalid power from grid entity would blank whole card
  • Loading branch information
davet2001 authored Jan 5, 2025
2 parents 906e2ac + 6b8f856 commit dc67e89
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/hui-power-flow-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,13 @@ class HuiPowerFlowCard extends LitElement implements LovelaceCard {
if (
!config.power_from_grid_entity &&
!config.power_to_grid_entity &&
!config.generation_entities &&
!config.consumer_entities
!config.generation_entity &&
config.consumer_entities.length === 0
) {
throw new Error("Must specify at least one entity");
}
if (config.power_from_grid_entity) {
if (!isValidEntityId(config.power_from_grid_entity)) {
throw new Error("Invalid power from grid entity specified");
}
// @todo consider adding more config checks here.
this._config = { ...config };
}
// @todo consider adding more config checks here.
this._config = { ...config };
}

private static async getExtendedEntityRegistryEntries(_hass: HomeAssistant): Promise<{ [id: string]: ExtEntityRegistryEntry }> {
Expand Down Expand Up @@ -267,7 +262,7 @@ class HuiPowerFlowCard extends LitElement implements LovelaceCard {
}

const generationInRoutes: { [id: string]: ElecRoute } = {};
if (this._config.generation_entities) {
if (config.generation_entities) {
for (const entity of config.generation_entities) {
const stateObj = this.hass.states[entity];
if (!stateObj) {
Expand Down

0 comments on commit dc67e89

Please sign in to comment.