[modules] Re-enable battery module
Enable battery module with new states: * discharging-[10,25,50,80,100] * charging * charged
This commit is contained in:
parent
18d7e1befb
commit
2cfb0997a0
4 changed files with 20 additions and 23 deletions
|
@ -33,7 +33,8 @@ class ModuleDescription(object):
|
||||||
|
|
||||||
class Module(object):
|
class Module(object):
|
||||||
def __init__(self, output, config):
|
def __init__(self, output, config):
|
||||||
pass
|
self._config = config
|
||||||
|
self._output = output
|
||||||
|
|
||||||
def data(self):
|
def data(self):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -11,40 +11,37 @@ def description():
|
||||||
return "Displays battery status, percentage and whether it's charging or discharging."
|
return "Displays battery status, percentage and whether it's charging or discharging."
|
||||||
|
|
||||||
class Module(bumblebee.module.Module):
|
class Module(bumblebee.module.Module):
|
||||||
def __init__(self, output, args):
|
def __init__(self, output, config):
|
||||||
super(Module, self).__init__(args)
|
super(Module, self).__init__(output, config)
|
||||||
self._battery = "BAT0" if not args else args[0]
|
self._battery = config.parameter("battery.device", "BAT0")
|
||||||
self._capacity = 0
|
self._capacity = 0
|
||||||
self._status = "Unknown"
|
self._status = "Unknown"
|
||||||
|
|
||||||
def data(self):
|
def widgets(self):
|
||||||
with open("/sys/class/power_supply/{}/capacity".format(self._battery)) as f:
|
with open("/sys/class/power_supply/{}/capacity".format(self._battery)) as f:
|
||||||
self._capacity = int(f.read())
|
self._capacity = int(f.read())
|
||||||
self._capacity = self._capacity if self._capacity < 100 else 100
|
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):
|
def warning(self):
|
||||||
return self._capacity < 20
|
return self._capacity < self._config.parameter("battery.warning", 20)
|
||||||
|
|
||||||
def critical(self):
|
def critical(self):
|
||||||
return self._capacity < 10
|
return self._capacity < self._config.parameter("battery.critical", 10)
|
||||||
|
|
||||||
def state(self):
|
def state(self):
|
||||||
with open("/sys/class/power_supply/{}/status".format(self._battery)) as f:
|
with open("/sys/class/power_supply/{}/status".format(self._battery)) as f:
|
||||||
self._status = f.read().strip()
|
self._status = f.read().strip()
|
||||||
|
|
||||||
if self._status == "Discharging":
|
if self._status == "Discharging":
|
||||||
if self._capacity < 10:
|
status = "discharging-{}".format(min([ 10, 25, 50, 80, 100] , key=lambda i:abs(i-self._capacity)))
|
||||||
return "discharging_critical"
|
return status
|
||||||
if self._capacity < 25:
|
|
||||||
return "discharging_low"
|
|
||||||
if self._capacity < 50:
|
|
||||||
return "discharging_medium"
|
|
||||||
if self._capacity < 75:
|
|
||||||
return "discharging_high"
|
|
||||||
return "discharging_full"
|
|
||||||
else:
|
else:
|
||||||
if self._capacity > 95:
|
if self._capacity > 95:
|
||||||
return "charged"
|
return "charged"
|
||||||
return "charging"
|
return "charging"
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
|
@ -14,7 +14,6 @@ class Module(bumblebee.module.Module):
|
||||||
def __init__(self, output, config):
|
def __init__(self, output, config):
|
||||||
super(Module, self).__init__(output, config)
|
super(Module, self).__init__(output, config)
|
||||||
self._perc = psutil.cpu_percent(percpu=False)
|
self._perc = psutil.cpu_percent(percpu=False)
|
||||||
self._config = config
|
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
# output.add_callback(module=self.__module__, button=1,
|
# output.add_callback(module=self.__module__, button=1,
|
||||||
|
|
|
@ -99,23 +99,23 @@
|
||||||
"prefix": [ " ", " ", " ", " ", " " ],
|
"prefix": [ " ", " ", " ", " ", " " ],
|
||||||
"suffix": " "
|
"suffix": " "
|
||||||
},
|
},
|
||||||
"discharging-critical": {
|
"discharging-10": {
|
||||||
"prefix": " ",
|
"prefix": " ",
|
||||||
"suffix": " "
|
"suffix": " "
|
||||||
},
|
},
|
||||||
"discharging-low": {
|
"discharging-25": {
|
||||||
"prefix": " ",
|
"prefix": " ",
|
||||||
"suffix": " "
|
"suffix": " "
|
||||||
},
|
},
|
||||||
"discharging-medium": {
|
"discharging-50": {
|
||||||
"prefix": " ",
|
"prefix": " ",
|
||||||
"suffix": " "
|
"suffix": " "
|
||||||
},
|
},
|
||||||
"discharging-high": {
|
"discharging-80": {
|
||||||
"prefix": " ",
|
"prefix": " ",
|
||||||
"suffix": " "
|
"suffix": " "
|
||||||
},
|
},
|
||||||
"discharging-full": {
|
"discharging-100": {
|
||||||
"prefix": " ",
|
"prefix": " ",
|
||||||
"suffix": " "
|
"suffix": " "
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue