[modules/battery] Handle inexistent battery more gracefully
This commit is contained in:
parent
716bafa90e
commit
a1455c9687
1 changed files with 6 additions and 3 deletions
|
@ -19,7 +19,7 @@ class Module(bumblebee.engine.Module):
|
||||||
super(Module, self).__init__(engine, config,
|
super(Module, self).__init__(engine, config,
|
||||||
bumblebee.output.Widget(full_text=self.capacity)
|
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._path = "/sys/class/power_supply/{}".format(battery)
|
||||||
self._capacity = 100
|
self._capacity = 100
|
||||||
|
|
||||||
|
@ -32,8 +32,11 @@ class Module(bumblebee.engine.Module):
|
||||||
if not os.path.exists(self._path):
|
if not os.path.exists(self._path):
|
||||||
self._ac = True
|
self._ac = True
|
||||||
|
|
||||||
with open(self._path + "/capacity") as f:
|
try:
|
||||||
self._capacity = int(f.read())
|
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
|
self._capacity = self._capacity if self._capacity < 100 else 100
|
||||||
|
|
||||||
def state(self, widget):
|
def state(self, widget):
|
||||||
|
|
Loading…
Reference in a new issue