flixlix/power-flow-card-plus

[BUG] Reports a negative entity in an individual device as positive

Opened this issue · 2 comments

Screenshot 2024-09-27 at 10 13 02 Screenshot 2024-09-27 at 10 13 18 **Describe the bug** I track the current import cost as an individual device reporting an entity that calculates to cost based on usage and tariff. I am on Octopus AGILE tariff so I sometimes have negative rates and for a period of time negative import cost. The underlying entity correctly reports the negative number. The power flow card individual circle reports the correct number but without the negative ('-') sign.

To Reproduce
Steps to reproduce the behavior:

  1. Set up an individual device that tracks a sensor that can report a negative value
  2. Check the power flow card when it should be negative. It is positive.

Expected behavior
I would like the number reported as negative

Screenshots
Attached showing the entity and the card.

Desktop (please complete the following information):

  • iOS 18, Chrome, Safari

Smartphone (please complete the following information):

  • Any device

Please make sure all of this applies and check the checkboxes, by writing "X" inside of them.

  • [ X I understand that this is a channel for reporting bugs, not a support forum (If you need help configuring the card, go to: Discussions).

  • I have the latest version of the card installed.

  • I have cleared my browser cache after installing, updating and configuring the card.

  • The issue is not related to the UI-Editor not being rendered: "s.entries is not a function". This is a known bug, and is caused by Card Mod. Check the warning this readme section for more information on how to fix it.

Seeing a similar issue with a secondary battery that I've added as an individual device. Regardless of whether the battery is charging or discharging, it shows the same direction:

Screenshot_20241010_233708
Screenshot_20241011_094628

The I/O alpha value on the right is the raw sensor value, and the purple device labelled alpha is the corresponding representation. It has been set to "Invert Animation".

So the bidirectional feature was added before v0.2.0 and it looks like the issue was introduced during the refactor?

The InvidualObject has a property called isStateNegative defined at

const isStateNegative = state && state < 0;

This is set based on the value retrieved by getIndividualState() at

const state = getIndividualState(hass, field);

But getIndividualState() returns the absolute value and so will never be negative

return Math.abs(individualStateWatts);

That's the cause, but I'm not sure if it's safe to simply return the original value since it may have an unintended consequence elsewhere if that value is negative.