From 2cfb0997a04d7043d0e174e4c2612d5c1477242d Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Sat, 5 Nov 2016 13:09:28 +0100 Subject: [PATCH] [modules] Re-enable battery module Enable battery module with new states: * discharging-[10,25,50,80,100] * charging * charged --- bumblebee/module.py | 3 ++- bumblebee/modules/battery.py | 29 ++++++++++------------- bumblebee/modules/cpu.py | 1 - bumblebee/themes/solarized-powerline.json | 10 ++++---- 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/bumblebee/module.py b/bumblebee/module.py index 9c4ab4b..c2fc585 100644 --- a/bumblebee/module.py +++ b/bumblebee/module.py @@ -33,7 +33,8 @@ class ModuleDescription(object): class Module(object): def __init__(self, output, config): - pass + self._config = config + self._output = output def data(self): pass diff --git a/bumblebee/modules/battery.py b/bumblebee/modules/battery.py index a83a2fd..83c5580 100644 --- a/bumblebee/modules/battery.py +++ b/bumblebee/modules/battery.py @@ -11,40 +11,37 @@ def description(): return "Displays battery status, percentage and whether it's charging or discharging." class Module(bumblebee.module.Module): - def __init__(self, output, args): - super(Module, self).__init__(args) - self._battery = "BAT0" if not args else args[0] + def __init__(self, output, config): + super(Module, self).__init__(output, config) + self._battery = config.parameter("battery.device", "BAT0") self._capacity = 0 self._status = "Unknown" - def data(self): + def widgets(self): with open("/sys/class/power_supply/{}/capacity".format(self._battery)) as f: self._capacity = int(f.read()) self._capacity = self._capacity if self._capacity < 100 else 100 - return "{:02d}%".format(self._capacity) + return [ + bumblebee.output.Widget(self,"{:02d}%".format(self._capacity)) + ] def warning(self): - return self._capacity < 20 + return self._capacity < self._config.parameter("battery.warning", 20) def critical(self): - return self._capacity < 10 + return self._capacity < self._config.parameter("battery.critical", 10) def state(self): with open("/sys/class/power_supply/{}/status".format(self._battery)) as f: self._status = f.read().strip() + if self._status == "Discharging": - if self._capacity < 10: - return "discharging_critical" - if self._capacity < 25: - return "discharging_low" - if self._capacity < 50: - return "discharging_medium" - if self._capacity < 75: - return "discharging_high" - return "discharging_full" + status = "discharging-{}".format(min([ 10, 25, 50, 80, 100] , key=lambda i:abs(i-self._capacity))) + return status else: if self._capacity > 95: return "charged" return "charging" + # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/bumblebee/modules/cpu.py b/bumblebee/modules/cpu.py index bfadcdd..4e58a21 100644 --- a/bumblebee/modules/cpu.py +++ b/bumblebee/modules/cpu.py @@ -14,7 +14,6 @@ class Module(bumblebee.module.Module): def __init__(self, output, config): super(Module, self).__init__(output, config) self._perc = psutil.cpu_percent(percpu=False) - self._config = config # TODO # output.add_callback(module=self.__module__, button=1, diff --git a/bumblebee/themes/solarized-powerline.json b/bumblebee/themes/solarized-powerline.json index 0996104..9554c45 100644 --- a/bumblebee/themes/solarized-powerline.json +++ b/bumblebee/themes/solarized-powerline.json @@ -99,23 +99,23 @@ "prefix": [ "  ", "  ", "  ", "  ", "  " ], "suffix": "  " }, - "discharging-critical": { + "discharging-10": { "prefix": "  ", "suffix": "  " }, - "discharging-low": { + "discharging-25": { "prefix": "  ", "suffix": "  " }, - "discharging-medium": { + "discharging-50": { "prefix": "  ", "suffix": "  " }, - "discharging-high": { + "discharging-80": { "prefix": "  ", "suffix": "  " }, - "discharging-full": { + "discharging-100": { "prefix": "  ", "suffix": "  " }