sermatec-opensource / homeassistant-sermatec-inverter

Home Assistant custom component for the Sermatec solar inverter.
MIT License
9 stars 2 forks source link

Incorrect battery power calculation #12

Closed andreondra closed 1 year ago

andreondra commented 1 year ago

Battery power is not calculated properly when the current is lower than 1 (floating type error = fix types, use float explicitly).

mathieupotier commented 1 year ago

I suggest this: power (int) = ceil((int)voltage * (float) current)

Can you just confirm that the current value is coming as a float ?

andreondra commented 1 year ago

Yes, both voltage and current are floats rounded to 1 decimal place, thus we shouldn't reduce precision where it's not necessary - I left the calculations and also the result as a float.