Skip to content

Commit

Permalink
Merge pull request #142 from derolli1976/negative-secondary
Browse files Browse the repository at this point in the history
feat: Add support for negative values in secondary info
  • Loading branch information
flixlix authored Oct 13, 2024
2 parents 41336b3 + 28b790e commit 8909255
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/energy-flow-card-plus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,15 +363,8 @@ export default class EnergyFlowCardPlus extends SubscribeMixin(LitElement) {
const secondaryEntity = field?.entity;
const wantsInstantaneousValue = field?.energyDateSelection !== true;
const secondaryState = secondaryEntity && this.getEntityStateWatthours(secondaryEntity, wantsInstantaneousValue);
if (typeof secondaryState === 'number') {
if (this.entityInverted(name)) {
return Math.abs(Math.min(secondaryState, 0));
} else {
return Math.max(secondaryState, 0);
}
} else if (typeof secondaryState === 'string') {
return secondaryState;
}
if (typeof secondaryState === 'number') return secondaryState * (this.entityInverted(name) ? -1 : 1);
if (typeof secondaryState === 'string') return secondaryState;
}
return null;
};
Expand Down

0 comments on commit 8909255

Please sign in to comment.