[modules/battery] Display AC when no battery is present
This commit is contained in:
parent
d37068b442
commit
3293cbaac4
1 changed files with 13 additions and 3 deletions
|
@ -1,5 +1,6 @@
|
|||
import datetime
|
||||
import bumblebee.module
|
||||
import os.path
|
||||
|
||||
def description():
|
||||
return "Displays battery status, percentage and whether it's charging or discharging."
|
||||
|
@ -11,11 +12,17 @@ class Module(bumblebee.module.Module):
|
|||
def __init__(self, output, config, alias):
|
||||
super(Module, self).__init__(output, config, alias)
|
||||
self._battery = config.parameter("device", "BAT0")
|
||||
self._capacity = 0
|
||||
self._capacity = 100
|
||||
self._status = "Unknown"
|
||||
|
||||
def widgets(self):
|
||||
with open("/sys/class/power_supply/{}/capacity".format(self._battery)) as f:
|
||||
self._AC = False;
|
||||
self._path = "/sys/class/power_supply/{}".format(self._battery)
|
||||
if not os.path.exists(self._path):
|
||||
self._AC = True;
|
||||
return bumblebee.output.Widget(self,"AC")
|
||||
|
||||
with open(self._path + "/capacity") as f:
|
||||
self._capacity = int(f.read())
|
||||
self._capacity = self._capacity if self._capacity < 100 else 100
|
||||
|
||||
|
@ -28,7 +35,10 @@ class Module(bumblebee.module.Module):
|
|||
return self._capacity < self._config.parameter("critical", 10)
|
||||
|
||||
def state(self, widget):
|
||||
with open("/sys/class/power_supply/{}/status".format(self._battery)) as f:
|
||||
if self._AC:
|
||||
return "AC"
|
||||
|
||||
with open(self._path + "/status") as f:
|
||||
self._status = f.read().strip()
|
||||
|
||||
if self._status == "Discharging":
|
||||
|
|
Loading…
Reference in a new issue