From 5c56fe12edbad56584e3511e3792f37ccde9931f Mon Sep 17 00:00:00 2001 From: chestm007 Date: Mon, 10 Feb 2020 23:51:12 +1100 Subject: [PATCH] alert on design percentage if desired (#756) * needs testing. * formatting fix --- i3pystatus/battery.py | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/i3pystatus/battery.py b/i3pystatus/battery.py index dc8e756..15830f3 100644 --- a/i3pystatus/battery.py +++ b/i3pystatus/battery.py @@ -209,6 +209,7 @@ class BatteryChecker(IntervalModule): "The text to display when the battery is not present. Provides {battery_ident} as formatting option"), ("no_text_full", "Don't display text when battery is full - 100%"), ("glyphs", "Arbitrarily long string of characters (or array of strings) to represent battery charge percentage"), + ("use_design_percentage", "Use design percentage rather then absolute percentage for alerts") ) battery_ident = "ALL" @@ -236,6 +237,7 @@ class BatteryChecker(IntervalModule): not_present_color = "#ffffff" no_text_full = False glyphs = "▁▂▃▄▅▆▇█" + use_design_percentage = False battery_prefix = 'BAT' base_path = '/sys/class/power_supply' @@ -362,20 +364,7 @@ class BatteryChecker(IntervalModule): if self.critical_level_command and fdict["status"] == "DIS" and fdict["percentage"] <= self.critical_level_percentage: run_through_shell(self.critical_level_command, enable_shell=True) - if self.alert and fdict["status"] == "DIS" and fdict["percentage"] <= self.alert_percentage: - title, body = formatp(self.alert_format_title, **fdict), formatp(self.alert_format_body, **fdict) - if self.notification is None: - self.notification = DesktopNotification( - title=title, - body=body, - icon="battery-caution", - urgency=2, - timeout=self.alert_timeout, - ) - self.notification.display() - else: - self.notification.update(title=title, - body=body) + self.alert_if_low_battery(fdict) if self.levels and fdict['status'] == 'DIS': self.levels.setdefault(0, self.status.get('DPL', 'DPL')) @@ -393,3 +382,24 @@ class BatteryChecker(IntervalModule): "urgent": urgent, "color": color, } + + def alert_if_low_battery(self, fdict): + if self.use_design_percentage: + percentage = fdict['percentage_design'] + else: + percentage = fdict['percentage'] + + if self.alert and fdict["status"] == "DIS" and percentage <= self.alert_percentage: + title, body = formatp(self.alert_format_title, **fdict), formatp(self.alert_format_body, **fdict) + if self.notification is None: + self.notification = DesktopNotification( + title=title, + body=body, + icon="battery-caution", + urgency=2, + timeout=self.alert_timeout, + ) + self.notification.display() + else: + self.notification.update(title=title, + body=body)