* check if charging in laptop with battery * using both battery and ac adapter to check if charging also battery status unknown is now recognized as charging
This commit is contained in:
parent
59996baeba
commit
897664aa3d
|
@ -168,10 +168,13 @@ def charging():
|
||||||
|
|
||||||
computer_type = getoutput("dmidecode --string chassis-type")
|
computer_type = getoutput("dmidecode --string chassis-type")
|
||||||
if computer_type in ["Notebook", "Laptop", "Convertible", "Portable"]:
|
if computer_type in ["Notebook", "Laptop", "Convertible", "Portable"]:
|
||||||
|
# AC adapter states: 0, 1, unknown
|
||||||
|
ac_info = getoutput(f"grep . {power_dir}A*/online").splitlines()
|
||||||
# Battery statuses: Full, Charging, Discharging, Unknown
|
# Battery statuses: Full, Charging, Discharging, Unknown
|
||||||
battery_status = getoutput(f"grep . {power_dir}B*/status").splitlines()
|
battery_status = getoutput(f"grep . {power_dir}B*/status").splitlines()
|
||||||
# if there's one battery charging, ac_state is True
|
# if there's one battery charging, or if there's one ac-adapter on-line, ac_state is True
|
||||||
ac_state = any(["Full" in ac or "Charging" in ac for ac in battery_status])
|
ac_state = (any([not "Discharging" in ac for ac in battery_status]) or
|
||||||
|
any(["1" in ac.split(":")[-1] for ac in ac_info]))
|
||||||
else:
|
else:
|
||||||
has_battery = psutil.sensors_battery() is not None
|
has_battery = psutil.sensors_battery() is not None
|
||||||
if has_battery:
|
if has_battery:
|
||||||
|
|
Loading…
Reference in New Issue