Calculate battery percentage from energy instead of average of batteries (#563)

* Calculate battery percentage from energy instead of average of batteries

Average only works if all batteries have the same max energy level. If setups with different sizes the smaller ones influence the percentage overproportianly strong

* check for battery type before calculating percentage, use old way if needed

* translate charge into energy to always calculate correct percentage
This commit is contained in:
pajowu 2017-05-03 10:36:35 +03:00 committed by Facetoe
parent a62282f0f2
commit 2ff5ea0262

View File

@ -78,6 +78,9 @@ class BatteryCharge(Battery):
def wh_remaining(self):
return self.battery_info['CHARGE_NOW'] * self.battery_info['VOLTAGE_NOW']
def wh_total(self):
return self.battery_info['CHARGE_FULL'] * self.battery_info['VOLTAGE_NOW']
def wh_depleted(self):
return (self.battery_info['CHARGE_FULL'] - self.battery_info['CHARGE_NOW']) * self.battery_info['VOLTAGE_NOW']
@ -103,6 +106,9 @@ class BatteryEnergy(Battery):
def wh_remaining(self):
return self.battery_info['ENERGY_NOW']
def wh_total(self):
return self.battery_info['ENERGY_FULL']
def wh_depleted(self):
return self.battery_info['ENERGY_FULL'] - self.battery_info['ENERGY_NOW']
@ -220,10 +226,9 @@ class BatteryChecker(IntervalModule):
paths = []
def percentage(self, batteries, design=False):
total = 0
for battery in batteries:
total += battery.percentage(design)
return total / len(batteries)
total_now = [battery.wh_remaining() for battery in batteries]
total_full = [battery.wh_total() for battery in batteries]
return sum(total_now) / sum(total_full) * 100
def consumption(self, batteries):
consumption = 0