2016-10-30 18:10:25 +01:00
|
|
|
import datetime
|
|
|
|
import bumblebee.module
|
|
|
|
|
|
|
|
class Module(bumblebee.module.Module):
|
|
|
|
def __init__(self, theme, args):
|
|
|
|
super(Module, self).__init__(theme, args)
|
|
|
|
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":
|
|
|
|
return "discharging"
|
|
|
|
else:
|
|
|
|
return "charging"
|
2016-10-30 18:10:25 +01:00
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|