diff --git a/bumblebee_status/modules/contrib/battery.py b/bumblebee_status/modules/contrib/battery.py index 7c65642..21951c1 100644 --- a/bumblebee_status/modules/contrib/battery.py +++ b/bumblebee_status/modules/contrib/battery.py @@ -130,8 +130,14 @@ class Module(core.module.Module): 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: + try: + with open("/sys/class/power_supply/{}/model_name".format(battery)) as f: + widget.set("pen", ("Pen" in f.read().strip())) + except Exception: + pass + + if util.format.asbool(self.parameter("decorate", True)) == False: + for widget in self.widgets(): widget.set("theme.exclude", "suffix") def hidden(self): @@ -147,15 +153,16 @@ class Module(core.module.Module): capacity = self.__manager.capacity(widget.name) widget.set("capacity", capacity) widget.set("ac", self.__manager.isac_any(self._batteries)) - widget.set("theme.minwidth", "100%") # Read power conumption if util.format.asbool(self.parameter("showpowerconsumption", False)): output = "{}% ({})".format( capacity, self.__manager.consumption(widget.name) ) - else: + elif capacity < 100: output = "{}%".format(capacity) + else: + output = "" if ( util.format.asbool(self.parameter("showremaining", True)) @@ -167,6 +174,16 @@ class Module(core.module.Module): output, util.format.duration(remaining, compact=True, unit=True) ) +# if bumblebee.util.asbool(self.parameter("rate", True)): +# try: +# with open("{}/power_now".format(widget.name)) as f: +# rate = (float(f.read())/1000000) +# if rate > 0: +# output = "{} {:.2f}w".format(output, rate) +# except Exception: +# pass + + if util.format.asbool(self.parameter("showdevice", False)): output = "{} ({})".format(output, widget.name) @@ -176,6 +193,9 @@ class Module(core.module.Module): state = [] capacity = widget.get("capacity") + if widget.get("pen"): + state.append("PEN") + if capacity < 0: log.debug("battery state: {}".format(state)) return ["critical", "unknown"] @@ -187,16 +207,10 @@ class Module(core.module.Module): charge = self.__manager.charge_any(self._batteries) else: charge = self.__manager.charge(widget.name) - if charge == "Discharging": + if charge in ["Discharging", "Unknown"]: state.append( "discharging-{}".format( - min([10, 25, 50, 80, 100], key=lambda i: abs(i - capacity)) - ) - ) - elif charge == "Unknown": - state.append( - "unknown-{}".format( - min([10, 25, 50, 80, 100], key=lambda i: abs(i - capacity)) + min([5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100], key=lambda i: abs(i - capacity)) ) ) else: