[modules/battery] gracefully handle "no batteries" case
if no batteries are found, assume the machine is running on AC. fixes #636
This commit is contained in:
parent
be008c0a6f
commit
caf2fea04b
1 changed files with 14 additions and 7 deletions
|
@ -114,22 +114,29 @@ class Module(core.module.Module):
|
|||
os.path.basename(battery)
|
||||
for battery in glob.glob("/sys/class/power_supply/BAT*")
|
||||
]
|
||||
if len(self._batteries) == 0:
|
||||
raise Exception("no batteries configured/found")
|
||||
core.input.register(
|
||||
self, button=core.input.LEFT_MOUSE, cmd="gnome-power-statistics"
|
||||
)
|
||||
|
||||
if len(self._batteries) == 0:
|
||||
widget = self.add_widget(full_text=self.ac, name="ac")
|
||||
widget.set("ac", True)
|
||||
widget.set("capacity", 100)
|
||||
else:
|
||||
if util.format.asbool(self.parameter("compact-devices", False)):
|
||||
widget = self.add_widget(full_text=self.capacity, name="all-batteries")
|
||||
else:
|
||||
for battery in self._batteries:
|
||||
log.debug("adding new widget for {}".format(battery))
|
||||
widget = self.add_widget(full_text=self.capacity, name=battery)
|
||||
|
||||
for w in self.widgets():
|
||||
if util.format.asbool(self.parameter("decorate", True)) == False:
|
||||
widget.set("theme.exclude", "suffix")
|
||||
|
||||
def ac(self, widget):
|
||||
return "ac"
|
||||
|
||||
def capacity(self, widget):
|
||||
if widget.name == "all-batteries":
|
||||
capacity = self.__manager.capacity_all(self._batteries)
|
||||
|
|
Loading…
Reference in a new issue