Change to calculate estimate time and percentage

This commit is contained in:
Christoph Stoettner 2019-04-22 17:28:25 +02:00
parent 011b3b631b
commit d2e2b21f1a
No known key found for this signature in database
GPG key ID: B0B7D3A8F7B77110

View file

@ -27,7 +27,6 @@ class Module(bumblebee.engine.Module):
# TODO: list all batteries # TODO: list all batteries
self._batteries.append("/sys/class/power_supply/BAT0") self._batteries.append("/sys/class/power_supply/BAT0")
self._batteries.append("/sys/class/power_supply/BAT1") self._batteries.append("/sys/class/power_supply/BAT1")
self._batteries.append("/sys/class/power_supply/battery")
super(Module, self).__init__(engine, config, bumblebee.output.Widget(full_text=self.capacity)) super(Module, self).__init__(engine, config, bumblebee.output.Widget(full_text=self.capacity))
@ -42,19 +41,21 @@ class Module(bumblebee.engine.Module):
# do not show remaining if on AC # do not show remaining if on AC
if estimate == power.common.TIME_REMAINING_UNLIMITED: if estimate == power.common.TIME_REMAINING_UNLIMITED:
return None return None
elif estimate == power.common.TIME_REMAINING_UNKNOWN: if estimate == power.common.TIME_REMAINING_UNKNOWN:
return "" return ""
else: # commented out, this will not use the PowerManagement result, instead it calculates the remaining time
for path in self._batteries: # with actual energy level, but shows in my case remaining 40 minutes instead of 12 hours
try: # else:
with open("{}/power_now".format(path)) as o: # for path in self._batteries:
power_now += int(o.read()) # try:
except IOError: # with open("{}/power_now".format(path)) as o:
return "n/a" # power_now += int(o.read())
except Exception: # except IOError:
errors += 1 # return "n/a"
# except Exception:
estimate = float( self.energy_now / power_now) # errors += 1
#
# estimate = float( self.energy_now / power_now)
except Exception: except Exception:
return "" return ""
return bumblebee.util.durationfmt(estimate*60, shorten=True, suffix=True) # estimate is in minutes return bumblebee.util.durationfmt(estimate*60, shorten=True, suffix=True) # estimate is in minutes
@ -84,7 +85,7 @@ class Module(bumblebee.engine.Module):
widget.set("capacity", 100) widget.set("capacity", 100)
return "ac" return "ac"
capacity = int( self.energy_now / self.energy_full * 100) capacity = int( float(self.energy_now) / float(self.energy_full) * 100)
capacity = capacity if capacity < 100 else 100 capacity = capacity if capacity < 100 else 100
widget.set("capacity", capacity) widget.set("capacity", capacity)
output = "{}%".format(capacity) output = "{}%".format(capacity)