From 8ef891cef6738056eef838e1bb7158e662633391 Mon Sep 17 00:00:00 2001 From: enkore Date: Thu, 7 Mar 2013 22:39:36 +0100 Subject: [PATCH] Fix battery module status bug --- i3pystatus/battery.py | 15 +++++++++------ setup.py | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/i3pystatus/battery.py b/i3pystatus/battery.py index 044573a..2a6e68b 100644 --- a/i3pystatus/battery.py +++ b/i3pystatus/battery.py @@ -68,6 +68,7 @@ class BatteryChecker(IntervalModule): "battery_ident", "format", ("alert", "Display a libnotify-notification on low battery"), "alert_percentage", "alert_format_title", "alert_format_body", "alert_percentage", + "path", ) battery_ident = "BAT0" format = "{status} {remaining_hm}" @@ -77,14 +78,17 @@ class BatteryChecker(IntervalModule): alert_format_title = "Low battery" alert_format_body = "Battery {battery_ident} has only {percentage:.2f}% ({remaining_hm}) remaining!" + path = None + def init(self): - self.base_path = "/sys/class/power_supply/{0}/uevent".format(self.battery_ident) + if not self.path: + self.path = "/sys/class/power_supply/{0}/uevent".format(self.battery_ident) def run(self): urgent = False color = "#ffffff" - battery = Battery(self.base_path) + battery = Battery(self.path) status = battery.STATUS energy_now = battery.ENERGY_NOW @@ -101,10 +105,7 @@ class BatteryChecker(IntervalModule): "percentage_design": (energy_now / battery.ENERGY_FULL_DESIGN) * 100, "consumption": power_now / 1000000, } - - if status == "Full" or fdict["percentage"] > 99: - fdict["status"] = "FULL" - elif power_now: + if power_now: if status == "Discharging": fdict["status"] = "DIS" remaining = RemainingCalculator(energy_now, power_now) @@ -115,6 +116,8 @@ class BatteryChecker(IntervalModule): fdict["status"] = "CHR" remaining = RemainingCalculator(energy_full-energy_now, power_now) fdict.update(remaining.get_dict("remaining_")) + else: + fdict["status"] = "FULL" if self.alert and fdict["percentage"] <= self.alert_percentage: display_notification( diff --git a/setup.py b/setup.py index 0829549..56b2e56 100755 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup setup(name="i3pystatus", - version="3.5", + version="3.6", description="Like i3status, this generates status line for i3bar / i3wm", url="http://github.com/enkore/i3pystatus", license="MIT",