Fix battery module status bug
This commit is contained in:
parent
743373fde6
commit
8ef891cef6
@ -68,6 +68,7 @@ class BatteryChecker(IntervalModule):
|
|||||||
"battery_ident", "format",
|
"battery_ident", "format",
|
||||||
("alert", "Display a libnotify-notification on low battery"),
|
("alert", "Display a libnotify-notification on low battery"),
|
||||||
"alert_percentage", "alert_format_title", "alert_format_body", "alert_percentage",
|
"alert_percentage", "alert_format_title", "alert_format_body", "alert_percentage",
|
||||||
|
"path",
|
||||||
)
|
)
|
||||||
battery_ident = "BAT0"
|
battery_ident = "BAT0"
|
||||||
format = "{status} {remaining_hm}"
|
format = "{status} {remaining_hm}"
|
||||||
@ -77,14 +78,17 @@ class BatteryChecker(IntervalModule):
|
|||||||
alert_format_title = "Low battery"
|
alert_format_title = "Low battery"
|
||||||
alert_format_body = "Battery {battery_ident} has only {percentage:.2f}% ({remaining_hm}) remaining!"
|
alert_format_body = "Battery {battery_ident} has only {percentage:.2f}% ({remaining_hm}) remaining!"
|
||||||
|
|
||||||
|
path = None
|
||||||
|
|
||||||
def init(self):
|
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):
|
def run(self):
|
||||||
urgent = False
|
urgent = False
|
||||||
color = "#ffffff"
|
color = "#ffffff"
|
||||||
|
|
||||||
battery = Battery(self.base_path)
|
battery = Battery(self.path)
|
||||||
|
|
||||||
status = battery.STATUS
|
status = battery.STATUS
|
||||||
energy_now = battery.ENERGY_NOW
|
energy_now = battery.ENERGY_NOW
|
||||||
@ -101,10 +105,7 @@ class BatteryChecker(IntervalModule):
|
|||||||
"percentage_design": (energy_now / battery.ENERGY_FULL_DESIGN) * 100,
|
"percentage_design": (energy_now / battery.ENERGY_FULL_DESIGN) * 100,
|
||||||
"consumption": power_now / 1000000,
|
"consumption": power_now / 1000000,
|
||||||
}
|
}
|
||||||
|
if power_now:
|
||||||
if status == "Full" or fdict["percentage"] > 99:
|
|
||||||
fdict["status"] = "FULL"
|
|
||||||
elif power_now:
|
|
||||||
if status == "Discharging":
|
if status == "Discharging":
|
||||||
fdict["status"] = "DIS"
|
fdict["status"] = "DIS"
|
||||||
remaining = RemainingCalculator(energy_now, power_now)
|
remaining = RemainingCalculator(energy_now, power_now)
|
||||||
@ -115,6 +116,8 @@ class BatteryChecker(IntervalModule):
|
|||||||
fdict["status"] = "CHR"
|
fdict["status"] = "CHR"
|
||||||
remaining = RemainingCalculator(energy_full-energy_now, power_now)
|
remaining = RemainingCalculator(energy_full-energy_now, power_now)
|
||||||
fdict.update(remaining.get_dict("remaining_"))
|
fdict.update(remaining.get_dict("remaining_"))
|
||||||
|
else:
|
||||||
|
fdict["status"] = "FULL"
|
||||||
|
|
||||||
if self.alert and fdict["percentage"] <= self.alert_percentage:
|
if self.alert and fdict["percentage"] <= self.alert_percentage:
|
||||||
display_notification(
|
display_notification(
|
||||||
|
2
setup.py
2
setup.py
@ -3,7 +3,7 @@
|
|||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
|
|
||||||
setup(name="i3pystatus",
|
setup(name="i3pystatus",
|
||||||
version="3.5",
|
version="3.6",
|
||||||
description="Like i3status, this generates status line for i3bar / i3wm",
|
description="Like i3status, this generates status line for i3bar / i3wm",
|
||||||
url="http://github.com/enkore/i3pystatus",
|
url="http://github.com/enkore/i3pystatus",
|
||||||
license="MIT",
|
license="MIT",
|
||||||
|
Loading…
Reference in New Issue
Block a user