From c8c0d85685ec5199e4cf51c7d1c45abd43f6e5ac Mon Sep 17 00:00:00 2001 From: Oliver Stock Date: Mon, 7 Oct 2024 13:04:48 +0200 Subject: [PATCH 1/2] Add support for negative values in secondary info --- src/energy-flow-card-plus.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/energy-flow-card-plus.ts b/src/energy-flow-card-plus.ts index 176137a..2857362 100644 --- a/src/energy-flow-card-plus.ts +++ b/src/energy-flow-card-plus.ts @@ -365,9 +365,9 @@ export default class EnergyFlowCardPlus extends SubscribeMixin(LitElement) { const secondaryState = secondaryEntity && this.getEntityStateWatthours(secondaryEntity, wantsInstantaneousValue); if (typeof secondaryState === 'number') { if (this.entityInverted(name)) { - return Math.abs(Math.min(secondaryState, 0)); + return -secondaryState; // Invert the sign if entityInverted returns true } else { - return Math.max(secondaryState, 0); + return secondaryState; // Return the value as is if entityInverted returns false } } else if (typeof secondaryState === 'string') { return secondaryState; From 28b790ea633c5ebb49241f0ed34698c1447fab22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luca=20F=C3=A9lix?= Date: Sun, 13 Oct 2024 19:24:23 +0200 Subject: [PATCH 2/2] refactor: :recycle: shorter code --- src/energy-flow-card-plus.ts | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/energy-flow-card-plus.ts b/src/energy-flow-card-plus.ts index 2857362..9a0522d 100644 --- a/src/energy-flow-card-plus.ts +++ b/src/energy-flow-card-plus.ts @@ -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 -secondaryState; // Invert the sign if entityInverted returns true - } else { - return secondaryState; // Return the value as is if entityInverted returns false - } - } 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; };