Skip to content

Commit

Permalink
Merge pull request #8 from flixlix/fix-handle-override-state-unit
Browse files Browse the repository at this point in the history
fix: handle `override_state` unit
  • Loading branch information
flixlix committed May 13, 2023
2 parents 564dba6 + d40b7cf commit 27081bc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
Binary file added .DS_Store
Binary file not shown.
16 changes: 7 additions & 9 deletions src/energy-flow-card-plus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,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 !== 'Wh') return value * 1000;
if (stateObj.attributes.unit_of_measurement?.toUpperCase().startsWith('KWH')) return value * 1000; // case insensitive check `KWH`
return value;
};

Expand Down Expand Up @@ -868,14 +868,12 @@ export default class EnergyFlowCardPlus extends SubscribeMixin(LitElement) {
this._config.entities.home?.secondary_info?.color_value ? 'var(--text-home-color)' : 'var(--primary-text-color)',
);

const homeState = this.getEntityStateWatthours(entities.home?.entity);

const homeStateDisplay =
entities.home?.override_state && entities.home.entity
const homeUsageToDisplay =
this._config.entities.home?.override_state && this._config.entities.home.entity
? entities.home?.subtract_individual
? this.displayValue(homeState - totalIndividualConsumption)
: this.displayValue(homeState)
: entities.home?.subtract_individual
? this.displayValue(this.getEntityStateWatthours(entities.home.entity) - totalIndividualConsumption)
: this.displayValue(this.getEntityStateWatthours(entities.home.entity))
: this._config.entities.home?.subtract_individual
? this.displayValue(totalHomeConsumption - totalIndividualConsumption || 0)
: this.displayValue(totalHomeConsumption);

Expand Down Expand Up @@ -1327,7 +1325,7 @@ export default class EnergyFlowCardPlus extends SubscribeMixin(LitElement) {
`
: ''}
<ha-icon .icon=${homeIcon}></ha-icon>
${homeStateDisplay}
${homeUsageToDisplay}
<svg>
${homeSolarCircumference !== undefined
? svg`<circle
Expand Down

0 comments on commit 27081bc

Please sign in to comment.