[modules/upower] Update to latest API

This commit is contained in:
tobi-wan-kenobi 2020-04-19 14:32:51 +02:00
parent 3f392be4a4
commit 9617a59d48

View file

@ -11,13 +11,13 @@ Parameters:
import dbus import dbus
import logging import logging
import bumblebee.input import core.module
import bumblebee.output import core.widget
import bumblebee.engine import core.input
import bumblebee.util
import util.format
class UPowerManager(): class UPowerManager():
def __init__(self): def __init__(self):
self.UPOWER_NAME = "org.freedesktop.UPower" self.UPOWER_NAME = "org.freedesktop.UPower"
self.UPOWER_PATH = "/org/freedesktop/UPower" self.UPOWER_PATH = "/org/freedesktop/UPower"
@ -192,19 +192,19 @@ class UPowerManager():
elif (state == 6): elif (state == 6):
return "Pending discharge" return "Pending discharge"
class Module(core.module.Module):
def __init__(self, config):
super().__init__(config, core.widget.Widget(self.capacity))
class Module(bumblebee.engine.Module):
def __init__(self, engine, config):
super(Module, self).__init__(engine, config, bumblebee.output.Widget(full_text=self.capacity))
try: try:
self.power = UPowerManager() self.power = UPowerManager()
self.device = self.power.get_display_device() self.device = self.power.get_display_device()
except Exception as e: except Exception as e:
logging.exception("unable to get battery display device: {}".format(str(e))) logging.exception("unable to get battery display device: {}".format(str(e)))
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE, core.input.register(self, button=core.input.LEFT_MOUSE,
cmd="gnome-power-statistics") cmd="gnome-power-statistics")
self._showremaining = bumblebee.util.asbool( self._showremaining = util.format.asbool(
self.parameter("showremaining", True)) self.parameter("showremaining", True))
def capacity(self, widget): def capacity(self, widget):
@ -229,7 +229,7 @@ class Module(bumblebee.engine.Module):
# state: 1 => charging, 2 => discharging, other => don't care # state: 1 => charging, 2 => discharging, other => don't care
remain = int(interface.Get( remain = int(interface.Get(
p.UPOWER_NAME+".Device", ["TimeToFull", "TimeToEmpty"][state-1])) p.UPOWER_NAME+".Device", ["TimeToFull", "TimeToEmpty"][state-1]))
remain = bumblebee.util.durationfmt(remain, shorten=True, suffix=True) remain = util.format.duration(remain, compact=True, unit=True)
output = "{} {}".format(output, remain) output = "{} {}".format(output, remain)
except IndexError: except IndexError:
pass pass