Skip to content

Commit

Permalink
Fix issue where invalid power from grid entity would blank whole card
Browse files Browse the repository at this point in the history
  • Loading branch information
davet2001 committed Jan 5, 2025
1 parent 7e36b14 commit 6b8f856
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 6b8f856

Please sign in to comment.