From cc58817978e4806c29c19cbe2e163909dd6c3b1f Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Sun, 20 Oct 2019 09:58:12 +0200 Subject: [PATCH] [modules/battery_all] Better error handling if battery not found When there are errors identifying the battery, make sure that the module returns "n/a" instead of just throwing an error. fixes #455 --- bumblebee/modules/battery_all.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/bumblebee/modules/battery_all.py b/bumblebee/modules/battery_all.py index 8f4cebc..52849bd 100644 --- a/bumblebee/modules/battery_all.py +++ b/bumblebee/modules/battery_all.py @@ -25,9 +25,12 @@ except ImportError: class Module(bumblebee.engine.Module): def __init__(self, engine, config): self._batteries = [] - for battery in os.listdir('/sys/class/power_supply/'): - if not any(i in battery for i in ['AC', 'hidpp']): - self._batteries.append("/sys/class/power_supply/" + battery) + try: + for battery in os.listdir('/sys/class/power_supply/'): + if not any(i in battery for i in ['AC', 'hidpp']): + self._batteries.append("/sys/class/power_supply/" + battery) + except: + pass super(Module, self).__init__(engine, config, bumblebee.output.Widget(full_text=self.capacity)) @@ -67,11 +70,7 @@ class Module(bumblebee.engine.Module): errors += 1 if errors == len(self._batteries): - # if all batteries return errors, but we are still running - # assume we are on A/C - widget.set("ac", True) - widget.set("capacity", 100) - return "ac" + return "n/a" capacity = int( float(self.energy_now) / float(self.energy_full) * 100.0) capacity = capacity if capacity < 100 else 100