[modules] Re-enable battery module

Enable battery module with new states:
* discharging-[10,25,50,80,100]
* charging
* charged
This commit is contained in:
Tobias Witek 2016-11-05 13:09:28 +01:00
parent 18d7e1befb
commit 2cfb0997a0
4 changed files with 20 additions and 23 deletions

View file

@ -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

View file

@ -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

View file

@ -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,

View file

@ -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": "  "
}