From caf2fea04b0540a9ea8092aac385f676a267e237 Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Thu, 28 May 2020 08:17:35 +0200 Subject: [PATCH] [modules/battery] gracefully handle "no batteries" case if no batteries are found, assume the machine is running on AC. fixes #636 --- bumblebee_status/modules/contrib/battery.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/bumblebee_status/modules/contrib/battery.py b/bumblebee_status/modules/contrib/battery.py index 512866d..2db2031 100644 --- a/bumblebee_status/modules/contrib/battery.py +++ b/bumblebee_status/modules/contrib/battery.py @@ -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 util.format.asbool(self.parameter("compact-devices", False)): - widget = self.add_widget(full_text=self.capacity, name="all-batteries") + if len(self._batteries) == 0: + widget = self.add_widget(full_text=self.ac, name="ac") + widget.set("ac", True) + widget.set("capacity", 100) else: - for battery in self._batteries: - log.debug("adding new widget for {}".format(battery)) - widget = self.add_widget(full_text=self.capacity, name=battery) + 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)