diff --git a/i3pystatus/battery.py b/i3pystatus/battery.py index c45ec76..f1fd8ce 100644 --- a/i3pystatus/battery.py +++ b/i3pystatus/battery.py @@ -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