2016-10-30 18:10:25 +01:00
|
|
|
import datetime
|
|
|
|
import bumblebee.module
|
|
|
|
|
|
|
|
class Module(bumblebee.module.Module):
|
2016-10-31 10:45:15 +01:00
|
|
|
def __init__(self, args):
|
|
|
|
super(Module, self).__init__(args)
|
2016-10-30 18:10:25 +01:00
|
|
|
self._battery = "BAT0" if not args else args[0]
|
|
|
|
self._capacity = 0
|
|
|
|
self._status = "Unknown"
|
|
|
|
|
|
|
|
def data(self):
|
2016-10-31 07:46:21 +01:00
|
|
|
with open("/sys/class/power_supply/{}/capacity".format(self._battery)) as f:
|
2016-10-30 18:10:25 +01:00
|
|
|
self._capacity = int(f.read())
|
|
|
|
|
2016-10-31 07:46:21 +01:00
|
|
|
return "{:02d}%".format(self._capacity)
|
2016-10-30 18:10:25 +01:00
|
|
|
|
2016-10-31 07:34:43 +01:00
|
|
|
def state(self):
|
2016-10-31 07:46:21 +01:00
|
|
|
with open("/sys/class/power_supply/{}/status".format(self._battery)) as f:
|
2016-10-31 07:34:43 +01:00
|
|
|
self._status = f.read().strip()
|
|
|
|
if self._status == "Discharging":
|
2016-10-31 11:35:12 +01:00
|
|
|
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"
|
2016-10-31 07:34:43 +01:00
|
|
|
else:
|
|
|
|
return "charging"
|
2016-10-30 18:10:25 +01:00
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|