From 9b96c142d5338fdb9d30ceb9b04b93839d738d90 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Fri, 6 Mar 2020 20:37:46 +0100 Subject: [PATCH] [modules/battery] Migrate constructor --- modules/core/battery.py | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/modules/core/battery.py b/modules/core/battery.py index 09c1a30..31aae42 100644 --- a/modules/core/battery.py +++ b/modules/core/battery.py @@ -13,30 +13,28 @@ Parameters: import os import glob +import power -import bumblebee.input -import bumblebee.output -import bumblebee.engine -import bumblebee.util +import core.module +import core.widget +import core.input -try: - import power -except ImportError: - pass +import util.format -class Module(bumblebee.engine.Module): - def __init__(self, engine, config): +class Module(core.module.Module): + def __init__(self, config=None): widgets = [] - super(Module, self).__init__(engine, config, widgets) - self._batteries = self.parameter('device', 'auto').split(',') + super().__init__(config, widgets) + + self._batteries = util.format.aslist(self.parameter('device', 'auto')) if self._batteries[0] == 'auto': self._batteries = glob.glob('/sys/class/power_supply/BAT*') else: self._batteries = ['/sys/class/power_supply/{}'.format(b) for b in self._batteries] if len(self._batteries) == 0: - self._batteries = ['/sys/class/power_supply/BAT0'] - self.update(widgets) - engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE, + raise Exceptions('no batteries configured/found') + self.update() + core.input.register(self, button=core.input.LEFT_MOUSE, cmd='gnome-power-statistics') def update(self, widgets):