From f4048747672224444e11b2c22735579587aae120 Mon Sep 17 00:00:00 2001 From: plumps Date: Mon, 10 Aug 2015 18:41:49 +0200 Subject: [PATCH 1/4] added the alert_command option running a shell command before the battery is completely discharged --- i3pystatus/battery.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/i3pystatus/battery.py b/i3pystatus/battery.py index db100da..95bb978 100644 --- a/i3pystatus/battery.py +++ b/i3pystatus/battery.py @@ -5,6 +5,7 @@ import configparser from i3pystatus import IntervalModule, formatp from i3pystatus.core.util import lchop, TimeWrapper, make_bar from i3pystatus.core.desktop import DesktopNotification +from i3pystatus.core.command import run_through_shell class UEventParser(configparser.ConfigParser): @@ -138,6 +139,7 @@ class BatteryChecker(IntervalModule): "format", ("not_present_text", "Text displayed if the battery is not present. No formatters are available"), ("alert", "Display a libnotify-notification on low battery"), + ("alert_command", "Runs a shell command of low-battery emergency"), "alert_percentage", ("alert_format_title", "The title of the notification, all formatters can be used"), ("alert_format_body", "The body text of the notification, all formatters can be used"), @@ -165,6 +167,7 @@ class BatteryChecker(IntervalModule): not_present_text = "Battery {battery_ident} not present" alert = False + alert_command = "" alert_percentage = 10 alert_format_title = "Low battery" alert_format_body = "Battery {battery_ident} has only {percentage:.2f}% ({remaining:%E%hh:%Mm}) remaining!" @@ -292,6 +295,8 @@ class BatteryChecker(IntervalModule): else: fdict["status"] = "FULL" color = self.full_color + if self.alert_command and fdict["status"] == "DIS" and fdict["percentage"] <= 1: + run_through_shell(self.alert_command, enable_shell=True) if self.alert and fdict["status"] == "DIS" and fdict["percentage"] <= self.alert_percentage: DesktopNotification( From f6d30ab0932805366893c631e79499bda984cb67 Mon Sep 17 00:00:00 2001 From: plumps Date: Fri, 14 Aug 2015 11:45:56 +0200 Subject: [PATCH 2/4] changed alert_command to critical_level_command this change is made to differentiate the low-energy from the critical level one better. new options: - critical_level_command="" - critical_level_percentage=int --- i3pystatus/battery.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/i3pystatus/battery.py b/i3pystatus/battery.py index 95bb978..2672340 100644 --- a/i3pystatus/battery.py +++ b/i3pystatus/battery.py @@ -139,7 +139,8 @@ class BatteryChecker(IntervalModule): "format", ("not_present_text", "Text displayed if the battery is not present. No formatters are available"), ("alert", "Display a libnotify-notification on low battery"), - ("alert_command", "Runs a shell command of low-battery emergency"), + ("critical_level_command", "Runs a shell command in the case of a critical power state"), + "critical_level_percentage" "alert_percentage", ("alert_format_title", "The title of the notification, all formatters can be used"), ("alert_format_body", "The body text of the notification, all formatters can be used"), @@ -167,7 +168,8 @@ class BatteryChecker(IntervalModule): not_present_text = "Battery {battery_ident} not present" alert = False - alert_command = "" + critical_level_command = "" + critical_percentage = 1 alert_percentage = 10 alert_format_title = "Low battery" alert_format_body = "Battery {battery_ident} has only {percentage:.2f}% ({remaining:%E%hh:%Mm}) remaining!" @@ -295,8 +297,8 @@ class BatteryChecker(IntervalModule): else: fdict["status"] = "FULL" color = self.full_color - if self.alert_command and fdict["status"] == "DIS" and fdict["percentage"] <= 1: - run_through_shell(self.alert_command, enable_shell=True) + if self.critical_level_command and fdict["status"] == "DIS" and fdict["percentage"] <= self.critical_percentage: + run_through_shell(self.critical_level_command, enable_shell=True) if self.alert and fdict["status"] == "DIS" and fdict["percentage"] <= self.alert_percentage: DesktopNotification( From 873de772946d0764d1ea06ca4c7ff438b1de6f8a Mon Sep 17 00:00:00 2001 From: plumps Date: Fri, 14 Aug 2015 11:48:35 +0200 Subject: [PATCH 3/4] little typo in critical_level --- i3pystatus/battery.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/i3pystatus/battery.py b/i3pystatus/battery.py index 2672340..0e20452 100644 --- a/i3pystatus/battery.py +++ b/i3pystatus/battery.py @@ -169,7 +169,7 @@ class BatteryChecker(IntervalModule): alert = False critical_level_command = "" - critical_percentage = 1 + critical_level_percentage = 1 alert_percentage = 10 alert_format_title = "Low battery" alert_format_body = "Battery {battery_ident} has only {percentage:.2f}% ({remaining:%E%hh:%Mm}) remaining!" @@ -297,7 +297,7 @@ class BatteryChecker(IntervalModule): else: fdict["status"] = "FULL" color = self.full_color - if self.critical_level_command and fdict["status"] == "DIS" and fdict["percentage"] <= self.critical_percentage: + 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: From d1e3ee701ab45445779b42c2635afbef7849b856 Mon Sep 17 00:00:00 2001 From: plumps Date: Fri, 14 Aug 2015 11:53:13 +0200 Subject: [PATCH 4/4] small typo --- i3pystatus/battery.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/i3pystatus/battery.py b/i3pystatus/battery.py index 0e20452..f181a41 100644 --- a/i3pystatus/battery.py +++ b/i3pystatus/battery.py @@ -140,7 +140,7 @@ class BatteryChecker(IntervalModule): ("not_present_text", "Text displayed if the battery is not present. No formatters are available"), ("alert", "Display a libnotify-notification on low battery"), ("critical_level_command", "Runs a shell command in the case of a critical power state"), - "critical_level_percentage" + "critical_level_percentage", "alert_percentage", ("alert_format_title", "The title of the notification, all formatters can be used"), ("alert_format_body", "The body text of the notification, all formatters can be used"),