[modules/battery] Handle inexistent battery more gracefully

This commit is contained in:
Tobi-wan Kenobi 2016-12-10 19:54:31 +01:00
parent 716bafa90e
commit a1455c9687

View file

@ -19,7 +19,7 @@ class Module(bumblebee.engine.Module):
super(Module, self).__init__(engine, config,
bumblebee.output.Widget(full_text=self.capacity)
)
battery = self.parameter("device", "BAT0")
battery = self.parameter("device", "BAT1")
self._path = "/sys/class/power_supply/{}".format(battery)
self._capacity = 100
@ -32,8 +32,11 @@ class Module(bumblebee.engine.Module):
if not os.path.exists(self._path):
self._ac = True
try:
with open(self._path + "/capacity") as f:
self._capacity = int(f.read())
except IOError:
self._capacity = 100
self._capacity = self._capacity if self._capacity < 100 else 100
def state(self, widget):