[modules/battery] Incorporate @yvesh's estimated time remaining
Move changes proposed by @yvesh to show the remaining battery time into the battery module. see #146
This commit is contained in:
parent
a312269240
commit
6a0578d2c3
2 changed files with 33 additions and 1 deletions
|
@ -17,6 +17,11 @@ import bumblebee.output
|
|||
import bumblebee.engine
|
||||
import bumblebee.util
|
||||
|
||||
try:
|
||||
import power
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
class Module(bumblebee.engine.Module):
|
||||
def __init__(self, engine, config):
|
||||
widgets = []
|
||||
|
@ -28,6 +33,7 @@ class Module(bumblebee.engine.Module):
|
|||
self._batteries = [ "/sys/class/power_supply/{}".format(b) for b in self._batteries ]
|
||||
if len(self._batteries) == 0:
|
||||
self._batteries = [ "/sys/class/power_supply/BAT0" ]
|
||||
self._estimate = "n/a"
|
||||
self.update(widgets)
|
||||
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,
|
||||
cmd="gnome-power-statistics")
|
||||
|
@ -44,6 +50,24 @@ class Module(bumblebee.engine.Module):
|
|||
for widget in new_widgets:
|
||||
widgets.append(widget)
|
||||
self._widgets = widgets
|
||||
if bumblebee.util.asbool(self.parameter("showremaining", False)):
|
||||
self._widgets.append(bumblebee.output.Widget(full_text=self.remaining))
|
||||
self._widgets[-1].set("type", "remaining")
|
||||
try:
|
||||
type = power.PowerManagement().get_providing_power_source_type()
|
||||
estimate = power.PowerManagement().get_time_remaining_estimate()
|
||||
|
||||
if type == power.POWER_TYPE_AC and estimate == -2.0:
|
||||
self._estimate = "Unlimited"
|
||||
elif estimate == -1.0:
|
||||
self._estimate = "Unknown"
|
||||
else:
|
||||
self._estimate = str(round(estimate / 60, 1)) + ' h'
|
||||
except Exception as e:
|
||||
self._estimate = "n/a"
|
||||
|
||||
def remaining(self, widget):
|
||||
return str(self._estimate)
|
||||
|
||||
def capacity(self, widget):
|
||||
widget.set("capacity", -1)
|
||||
|
@ -68,6 +92,12 @@ class Module(bumblebee.engine.Module):
|
|||
|
||||
def state(self, widget):
|
||||
state = []
|
||||
|
||||
if widget.get("type", "battery") == "remaining":
|
||||
if self._estimate == "Unlimited":
|
||||
return "unlimited"
|
||||
return "estimate"
|
||||
|
||||
capacity = widget.get("capacity")
|
||||
|
||||
if capacity < 0:
|
||||
|
|
|
@ -75,7 +75,9 @@
|
|||
"discharging-25": { "prefix": "", "suffix": "" },
|
||||
"discharging-50": { "prefix": "", "suffix": "" },
|
||||
"discharging-80": { "prefix": "", "suffix": "" },
|
||||
"discharging-100": { "prefix": "", "suffix": "" }
|
||||
"discharging-100": { "prefix": "", "suffix": "" },
|
||||
"unlimited": { "prefix": "", "suffix": "" },
|
||||
"estimate": { "prefix": "" }
|
||||
},
|
||||
"caffeine": {
|
||||
"activated": {"prefix": " " }, "deactivated": { "prefix": " " }
|
||||
|
|
Loading…
Reference in a new issue