parent
8f0ac4bdb6
commit
00c230f4f8
@ -49,16 +49,23 @@ class Battery:
|
|||||||
return self._percentage("_DESIGN" if design else "") * 100
|
return self._percentage("_DESIGN" if design else "") * 100
|
||||||
|
|
||||||
def status(self):
|
def status(self):
|
||||||
if self.consumption():
|
if self.consumption() > 0.1:
|
||||||
return "Discharging" if self.battery_info["STATUS"] == "Discharging" else "Charging"
|
return "Discharging" if self.battery_info["STATUS"] == "Discharging" else "Charging"
|
||||||
else:
|
else:
|
||||||
return "Full"
|
return "Full"
|
||||||
|
|
||||||
|
def consumption(self, val):
|
||||||
|
return val if val > 0.1 else 0
|
||||||
|
|
||||||
|
|
||||||
class BatteryCharge(Battery):
|
class BatteryCharge(Battery):
|
||||||
|
def __init__(self, bi):
|
||||||
|
bi["CHARGE_FULL"] = bi["CHARGE_FULL_DESIGN"] if bi["CHARGE_NOW"] > bi["CHARGE_FULL"] else bi["CHARGE_FULL"]
|
||||||
|
super().__init__(bi)
|
||||||
|
|
||||||
def consumption(self):
|
def consumption(self):
|
||||||
if "VOLTAGE_NOW" in self.battery_info and "CURRENT_NOW" in self.battery_info:
|
if "VOLTAGE_NOW" in self.battery_info and "CURRENT_NOW" in self.battery_info:
|
||||||
return self.battery_info["VOLTAGE_NOW"] * self.battery_info["CURRENT_NOW"] # V * A = W
|
return super().consumption(self.battery_info["VOLTAGE_NOW"] * self.battery_info["CURRENT_NOW"]) # V * A = W
|
||||||
else:
|
else:
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
@ -79,7 +86,7 @@ class BatteryCharge(Battery):
|
|||||||
|
|
||||||
class BatteryEnergy(Battery):
|
class BatteryEnergy(Battery):
|
||||||
def consumption(self):
|
def consumption(self):
|
||||||
return self.battery_info["POWER_NOW"]
|
return super().consumption(self.battery_info["POWER_NOW"])
|
||||||
|
|
||||||
def _percentage(self, design):
|
def _percentage(self, design):
|
||||||
return self.battery_info["ENERGY_NOW"] / self.battery_info["ENERGY_FULL" + design]
|
return self.battery_info["ENERGY_NOW"] / self.battery_info["ENERGY_FULL" + design]
|
||||||
|
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.29",
|
version="3.30",
|
||||||
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",
|
||||||
|
8
tests/test_battery.py
Executable file → Normal file
8
tests/test_battery.py
Executable file → Normal file
@ -9,7 +9,6 @@ def factory(path, format, expected):
|
|||||||
def test():
|
def test():
|
||||||
bc = battery.BatteryChecker(path=path, format=format)
|
bc = battery.BatteryChecker(path=path, format=format)
|
||||||
bc.run()
|
bc.run()
|
||||||
print(bc.output["full_text"])
|
|
||||||
assert bc.output["full_text"] == expected
|
assert bc.output["full_text"] == expected
|
||||||
test.description = path + ":" + format
|
test.description = path + ":" + format
|
||||||
return test
|
return test
|
||||||
@ -17,15 +16,16 @@ def factory(path, format, expected):
|
|||||||
|
|
||||||
def basic_test_generator():
|
def basic_test_generator():
|
||||||
cases = [
|
cases = [
|
||||||
("test_battery_basic1", "FULL", "0.000", ""),
|
("test_battery_basic1", "FULL", "0.000", "0h:00m"),
|
||||||
("test_battery_basic2", "FULL", "0.000", ""),
|
("test_battery_basic2", "FULL", "0.000", "0h:00m"),
|
||||||
("test_battery_basic3", "DIS", "15.624", "4h:04m"),
|
("test_battery_basic3", "DIS", "15.624", "4h:04m"),
|
||||||
("test_battery_basic4", "DIS", "17.510", "1h:46m"),
|
("test_battery_basic4", "DIS", "17.510", "1h:46m"),
|
||||||
("test_battery_basic5", "DIS", "11.453", "4h:52m"),
|
("test_battery_basic5", "DIS", "11.453", "4h:52m"),
|
||||||
("test_battery_basic6", "CHR", "30.764", "0h:20m"),
|
("test_battery_basic6", "CHR", "30.764", "0h:20m"),
|
||||||
("test_battery_basic7", "DIS", "27.303", "1h:44m"),
|
("test_battery_basic7", "DIS", "27.303", "1h:44m"),
|
||||||
|
("test_battery_broken1", "FULL", "0.000", "0h:00m"),
|
||||||
]
|
]
|
||||||
for path, status, consumption, remaining in cases:
|
for path, status, consumption, remaining in cases:
|
||||||
yield factory(path, "{status}", status)
|
yield factory(path, "{status}", status)
|
||||||
yield factory(path, "{consumption:.3f}", consumption)
|
yield factory(path, "{consumption:.3f}", consumption)
|
||||||
yield factory(path, "{remaining_hm}", remaining)
|
yield factory(path, "{remaining:%hh:%Mm}", remaining)
|
||||||
|
15
tests/test_battery_broken1
Normal file
15
tests/test_battery_broken1
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
POWER_SUPPLY_NAME=BAT0
|
||||||
|
POWER_SUPPLY_STATUS=Full
|
||||||
|
POWER_SUPPLY_PRESENT=1
|
||||||
|
POWER_SUPPLY_TECHNOLOGY=Li-ion
|
||||||
|
POWER_SUPPLY_CYCLE_COUNT=0
|
||||||
|
POWER_SUPPLY_VOLTAGE_MIN_DESIGN=11100000
|
||||||
|
POWER_SUPPLY_VOLTAGE_NOW=12532000
|
||||||
|
POWER_SUPPLY_CURRENT_NOW=1000
|
||||||
|
POWER_SUPPLY_CHARGE_FULL_DESIGN=5600000
|
||||||
|
POWER_SUPPLY_CHARGE_FULL=1187000
|
||||||
|
POWER_SUPPLY_CHARGE_NOW=5600000
|
||||||
|
POWER_SUPPLY_CAPACITY=471
|
||||||
|
POWER_SUPPLY_MODEL_NAME=DELL H139107
|
||||||
|
POWER_SUPPLY_MANUFACTURER=Samsung SDI
|
||||||
|
POWER_SUPPLY_SERIAL_NUMBER=13685
|
Loading…
Reference in New Issue
Block a user