Skip to content

Commit 7618348

Browse files
committed
feat: add support for directional power flow for individual objects
Integrated commit c00dd74 from hobbymachinist/power-flow-card-plus (PR flixlix#873): **Changes:** - Modified `getIndividualState()` to return signed values (removed Math.abs) - Added `absState` calculation in `getIndividualObject()` to handle negative states - State values now retain directionality while display shows absolute values - Enables proper animation inversion for bidirectional devices (V2H/V2G) **Impact:** - Individual objects can now properly display power flow direction - Supports Vehicle-to-Home (V2H) and Vehicle-to-Grid (V2G) scenarios - Animation correctly inverts when power flow reverses **Note on commit 2342177 from dpayk/power-flow-card-plus:** This commit fixes battery charging flow calculation, but a more comprehensive solution was already applied via PR flixlix#878 which handles grid export and uses more robust Math.max/Math.min logic. Build verified successful.
1 parent ee182a7 commit 7618348

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/states/raw/individual/getIndividualObject.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,13 @@ export const getIndividualObject = (hass: HomeAssistant, field: IndividualDevice
7575
const userConfiguredInvertAnimation = field?.inverted_animation || false;
7676
const invertAnimation = isStateNegative ? !userConfiguredInvertAnimation : userConfiguredInvertAnimation;
7777
const color = field?.color && typeof field?.color === "string" ? field?.color : null;
78+
const absState = state && state < 0 ? -state : state;
7879

7980
return {
8081
field,
8182
entity,
8283
has,
83-
state,
84+
state: absState,
8485
displayZero,
8586
displayZeroTolerance,
8687
icon: computeFieldIcon(hass, field, "mdi:flash"),

src/states/raw/individual/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const getIndividualState = (hass: HomeAssistant, field: IndividualDeviceT
1111

1212
const individualStateWatts = getEntityStateWatts(hass, entity);
1313

14-
return Math.abs(individualStateWatts);
14+
return individualStateWatts;
1515
};
1616

1717
export const getIndividualSecondaryState = (hass: HomeAssistant, field: IndividualDeviceType) => {

0 commit comments

Comments
 (0)