improve battery-upower module: charging remaing time
- fix the documentation of parameters - now also show the remaining time to fully charged when charging - modify the code to reduce the frequency of making requests to D-Bus
This commit is contained in:
parent
f96844b906
commit
33a9787b2f
1 changed files with 21 additions and 10 deletions
|
@ -3,9 +3,9 @@
|
||||||
"""Displays battery status, remaining percentage and charging information.
|
"""Displays battery status, remaining percentage and charging information.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
* battery.warning : Warning threshold in % of remaining charge (defaults to 20)
|
* battery-upower.warning : Warning threshold in % of remaining charge (defaults to 20)
|
||||||
* battery.critical : Critical threshold in % of remaining charge (defaults to 10)
|
* battery-upower.critical : Critical threshold in % of remaining charge (defaults to 10)
|
||||||
* battery.showremaining : If set to true (default) shows the remaining time until the batteries are completely discharged
|
* battery-upower.showremaining : If set to true (default) shows the remaining time until the batteries are completely discharged
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import dbus
|
import dbus
|
||||||
|
@ -204,9 +204,8 @@ class Module(bumblebee.engine.Module):
|
||||||
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,
|
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,
|
||||||
cmd="gnome-power-statistics")
|
cmd="gnome-power-statistics")
|
||||||
|
|
||||||
def remaining(self):
|
self._showremaining = bumblebee.util.asbool(
|
||||||
estimate = int(self.power.get_full_device_information(self.device)['TimeToEmpty'])
|
self.parameter("showremaining", True))
|
||||||
return bumblebee.util.durationfmt(estimate, shorten=True, suffix=True) # estimate is in minutes
|
|
||||||
|
|
||||||
def capacity(self, widget):
|
def capacity(self, widget):
|
||||||
widget.set("capacity", -1)
|
widget.set("capacity", -1)
|
||||||
|
@ -218,13 +217,25 @@ class Module(bumblebee.engine.Module):
|
||||||
widget.set("capacity", capacity)
|
widget.set("capacity", capacity)
|
||||||
output = "{}%".format(capacity)
|
output = "{}%".format(capacity)
|
||||||
widget.set("theme.minwidth", "100%")
|
widget.set("theme.minwidth", "100%")
|
||||||
|
|
||||||
if bumblebee.util.asbool(self.parameter("showremaining", True)) \
|
|
||||||
and self.power.get_state(self.device) == "Discharging":
|
|
||||||
output = "{} {}".format(output, self.remaining())
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception("unable to get battery capacity: {}".format(str(e)))
|
logging.exception("unable to get battery capacity: {}".format(str(e)))
|
||||||
|
|
||||||
|
if self._showremaining:
|
||||||
|
try:
|
||||||
|
p = self.power # an alias to make each line of code shorter
|
||||||
|
proxy = p.bus.get_object(p.UPOWER_NAME, self.device)
|
||||||
|
interface = dbus.Interface(proxy, p.DBUS_PROPERTIES)
|
||||||
|
state = int(interface.Get(p.UPOWER_NAME+".Device", "State"))
|
||||||
|
# state: 1 => charging, 2 => discharging, other => don't care
|
||||||
|
remain = int(interface.Get(
|
||||||
|
p.UPOWER_NAME+".Device", ["TimeToFull", "TimeToEmpty"][state-1]))
|
||||||
|
remain = bumblebee.util.durationfmt(remain, shorten=True, suffix=True)
|
||||||
|
output = "{} {}".format(output, remain)
|
||||||
|
except IndexError:
|
||||||
|
pass
|
||||||
|
except Exception as e:
|
||||||
|
logging.exception("unable to get battery remaining time: {}".format(str(e)))
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def state(self, widget):
|
def state(self, widget):
|
||||||
|
|
Loading…
Reference in a new issue