slipx06 / sunsynk-power-flow-card

⚡A customizable Home Assistant card to emulate the Sunsynk System flow that's displayed on the Inverter screen.
MIT License
161 stars 48 forks source link

Feature/custom_entity #305

Closed Pho3niX90 closed 3 months ago

Pho3niX90 commented 3 months ago

The new CustomEntity interface allows for streamlined handling of state-related tasks and boilerplate code reduction. Additionally, the full battery capacity computation logic is now encapsulated within the getBatteryCapacity method. This promotes better organization and clarity throughout the codebase.

I added the co-authored tag. Although I "think" I got all the logic, I might not have understood the intent at all of the calculations, so just need another pair of eyes.

slipx06 commented 3 months ago

I'm getting this error

image

Edit found the problem

Pho3niX90 commented 3 months ago

@slipx06 should be fixed now, was because toNum() was called on the state, and since state was of type any, it didn't throw type safety errors.

I have fixed the state, by changing it to back to string (HassEntity type).

slipx06 commented 3 months ago

The last update broke battery energy. Its a problem with state_battery_rated_capacity

slipx06 commented 3 months ago

I think this is good to merge now.

Is there a better way to handle this error. Happens when you set battery_energy: null

image

Pho3niX90 commented 3 months ago

That should fix it. The optional chaining operator fixes these issues ?, it will then only call toString() if the object is not null.