Skip to content

Commit

Permalink
Merge pull request #19 from flixlix/18-bug-battery-capacity-show-alwa…
Browse files Browse the repository at this point in the history
…ys-0

fix: state of charge not working
  • Loading branch information
flixlix committed May 22, 2023
2 parents 410126d + 1c255d0 commit 3abf18c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/energy-flow-card-plus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,12 @@ export default class EnergyFlowCardPlus extends SubscribeMixin(LitElement) {
return 1.66;
};

private getEntityState = (entity: string | undefined): number => {
private getEntityState = (entity: string | undefined, instantaneousValue?: boolean): number => {
if (!entity || !this.entityAvailable(entity)) {
this.unavailableOrMisconfiguredError(entity);
return 0;
}
const stateObj = this._config?.energy_date_selection !== false ? this.states[entity] : this.hass?.states[entity];
const stateObj = this._config?.energy_date_selection !== false && !instantaneousValue ? this.states[entity] : this.hass?.states[entity];
return coerceNumber(stateObj.state);
};

Expand All @@ -203,7 +203,7 @@ export default class EnergyFlowCardPlus extends SubscribeMixin(LitElement) {
}
const stateObj = this._config?.energy_date_selection !== false ? this.states[entity] : this.hass?.states[entity];
const value = coerceNumber(stateObj?.state);
if (stateObj.attributes.unit_of_measurement?.toUpperCase().startsWith('KWH')) return value * 1000; // case insensitive check `KWH`
if (stateObj?.attributes.unit_of_measurement?.toUpperCase().startsWith('KWH')) return value * 1000; // case insensitive check `KWH`
return value;
};

Expand Down Expand Up @@ -716,7 +716,7 @@ export default class EnergyFlowCardPlus extends SubscribeMixin(LitElement) {
(batteryFromGrid ?? 0) +
(batteryToGrid ?? 0);

const batteryChargeState = entities.battery?.state_of_charge?.length ? this.getEntityState(entities.battery?.state_of_charge) : null;
const batteryChargeState = entities?.battery?.state_of_charge ? this.getEntityState(entities.battery?.state_of_charge, true) : null;

let batteryIcon = 'mdi:battery-high';
if (batteryChargeState === null) {
Expand Down

0 comments on commit 3abf18c

Please sign in to comment.