From 9b4d1c52e63727718f479269b5b067742d4b9135 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 3 Nov 2018 17:52:02 +0100 Subject: [PATCH 1/2] Improved battery module for 2 batteries --- bumblebee/modules/battery.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/bumblebee/modules/battery.py b/bumblebee/modules/battery.py index 5367d5f..2754d33 100644 --- a/bumblebee/modules/battery.py +++ b/bumblebee/modules/battery.py @@ -78,17 +78,18 @@ class Module(bumblebee.engine.Module): return "n/a" capacity = capacity if capacity < 100 else 100 widget.set("capacity", capacity) - if bumblebee.util.asbool(self.parameter("showdevice", False)): - widget.set("theme.minwidth", "100% ({})".format(os.path.basename(widget.name))) - return "{}% ({})".format(capacity, os.path.basename(widget.name)) + output = "{}%".format(capacity) 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("showremaining", True)): - remaining = self.remaining() - - return "{}%{}".format(capacity, "" if not remaining else " ({})".format(remaining)) + if bumblebee.util.asbool(self.parameter("showdevice", True)): + output = "{} ({})".format(output, os.path.basename(widget.name)) + return output + def state(self, widget): state = [] capacity = widget.get("capacity") @@ -104,14 +105,11 @@ class Module(bumblebee.engine.Module): if widget.get("ac"): state.append("AC") else: - charge = "" - try: - with open("{}/status".format(widget.name)) as f: - charge = f.read().strip() - except IOError: - pass + charge = self.getCharge(widget) if charge == "Discharging": state.append("discharging-{}".format(min([10, 25, 50, 80, 100], key=lambda i: abs(i-capacity)))) + elif charge == "Unknown": + state.append("unknown") else: if capacity > 95: state.append("charged") @@ -120,4 +118,12 @@ class Module(bumblebee.engine.Module): 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 From 17d111314168583c6c9462abb3ef9ddaaff09f30 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 3 Nov 2018 18:27:19 +0100 Subject: [PATCH 2/2] changed default parameter for tests --- bumblebee/modules/battery.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bumblebee/modules/battery.py b/bumblebee/modules/battery.py index 2754d33..bdd21ef 100644 --- a/bumblebee/modules/battery.py +++ b/bumblebee/modules/battery.py @@ -85,7 +85,7 @@ class Module(bumblebee.engine.Module): and self.getCharge(widget) == "Discharging": output = "{} {}".format(output, self.remaining()) - if bumblebee.util.asbool(self.parameter("showdevice", True)): + if bumblebee.util.asbool(self.parameter("showdevice", False)): output = "{} ({})".format(output, os.path.basename(widget.name)) return output