Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue where invalid power from grid entity would blank whole card #24

Merged
merged 1 commit into from
Jan 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading