Improved battery module for 2 batteries
This commit is contained in:
parent
316dde0dbe
commit
9b4d1c52e6
1 changed files with 20 additions and 14 deletions
|
@ -78,17 +78,18 @@ class Module(bumblebee.engine.Module):
|
||||||
return "n/a"
|
return "n/a"
|
||||||
capacity = capacity if capacity < 100 else 100
|
capacity = capacity if capacity < 100 else 100
|
||||||
widget.set("capacity", capacity)
|
widget.set("capacity", capacity)
|
||||||
if bumblebee.util.asbool(self.parameter("showdevice", False)):
|
output = "{}%".format(capacity)
|
||||||
widget.set("theme.minwidth", "100% ({})".format(os.path.basename(widget.name)))
|
|
||||||
return "{}% ({})".format(capacity, os.path.basename(widget.name))
|
|
||||||
widget.set("theme.minwidth", "100%")
|
widget.set("theme.minwidth", "100%")
|
||||||
|
|
||||||
|
if bumblebee.util.asbool(self.parameter("showremaining", True))\
|
||||||
|
and self.getCharge(widget) == "Discharging":
|
||||||
|
output = "{} {}".format(output, self.remaining())
|
||||||
|
|
||||||
remaining = None
|
if bumblebee.util.asbool(self.parameter("showdevice", True)):
|
||||||
if bumblebee.util.asbool(self.parameter("showremaining", True)):
|
output = "{} ({})".format(output, os.path.basename(widget.name))
|
||||||
remaining = self.remaining()
|
|
||||||
|
|
||||||
return "{}%{}".format(capacity, "" if not remaining else " ({})".format(remaining))
|
|
||||||
|
|
||||||
|
return output
|
||||||
|
|
||||||
def state(self, widget):
|
def state(self, widget):
|
||||||
state = []
|
state = []
|
||||||
capacity = widget.get("capacity")
|
capacity = widget.get("capacity")
|
||||||
|
@ -104,14 +105,11 @@ class Module(bumblebee.engine.Module):
|
||||||
if widget.get("ac"):
|
if widget.get("ac"):
|
||||||
state.append("AC")
|
state.append("AC")
|
||||||
else:
|
else:
|
||||||
charge = ""
|
charge = self.getCharge(widget)
|
||||||
try:
|
|
||||||
with open("{}/status".format(widget.name)) as f:
|
|
||||||
charge = f.read().strip()
|
|
||||||
except IOError:
|
|
||||||
pass
|
|
||||||
if charge == "Discharging":
|
if charge == "Discharging":
|
||||||
state.append("discharging-{}".format(min([10, 25, 50, 80, 100], key=lambda i: abs(i-capacity))))
|
state.append("discharging-{}".format(min([10, 25, 50, 80, 100], key=lambda i: abs(i-capacity))))
|
||||||
|
elif charge == "Unknown":
|
||||||
|
state.append("unknown")
|
||||||
else:
|
else:
|
||||||
if capacity > 95:
|
if capacity > 95:
|
||||||
state.append("charged")
|
state.append("charged")
|
||||||
|
@ -120,4 +118,12 @@ class Module(bumblebee.engine.Module):
|
||||||
|
|
||||||
return state
|
return state
|
||||||
|
|
||||||
|
def getCharge(self, widget):
|
||||||
|
charge = ""
|
||||||
|
try:
|
||||||
|
with open("{}/status".format(widget.name)) as f:
|
||||||
|
charge = f.read().strip()
|
||||||
|
except IOError:
|
||||||
|
pass
|
||||||
|
return charge
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
Loading…
Reference in a new issue