From 3293cbaac4de9373cda86c4720b53d07b1f6d640 Mon Sep 17 00:00:00 2001 From: Pavle Portic Date: Thu, 17 Nov 2016 23:02:49 +0100 Subject: [PATCH] [modules/battery] Display AC when no battery is present --- bumblebee/modules/battery.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/bumblebee/modules/battery.py b/bumblebee/modules/battery.py index 10a2600..2a570df 100644 --- a/bumblebee/modules/battery.py +++ b/bumblebee/modules/battery.py @@ -1,5 +1,6 @@ import datetime import bumblebee.module +import os.path def description(): return "Displays battery status, percentage and whether it's charging or discharging." @@ -11,11 +12,17 @@ class Module(bumblebee.module.Module): def __init__(self, output, config, alias): super(Module, self).__init__(output, config, alias) self._battery = config.parameter("device", "BAT0") - self._capacity = 0 + self._capacity = 100 self._status = "Unknown" def widgets(self): - with open("/sys/class/power_supply/{}/capacity".format(self._battery)) as f: + self._AC = False; + self._path = "/sys/class/power_supply/{}".format(self._battery) + if not os.path.exists(self._path): + self._AC = True; + return bumblebee.output.Widget(self,"AC") + + with open(self._path + "/capacity") as f: self._capacity = int(f.read()) self._capacity = self._capacity if self._capacity < 100 else 100 @@ -28,7 +35,10 @@ class Module(bumblebee.module.Module): return self._capacity < self._config.parameter("critical", 10) def state(self, widget): - with open("/sys/class/power_supply/{}/status".format(self._battery)) as f: + if self._AC: + return "AC" + + with open(self._path + "/status") as f: self._status = f.read().strip() if self._status == "Discharging":