On laptops/notebooks, check if charging via BAT* status (#274)

This commit is contained in:
AmitGolden 2021-11-14 10:40:29 +02:00 committed by GitHub
parent 95e30e3975
commit f2fb6aafb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -168,10 +168,10 @@ def charging():
computer_type = getoutput("dmidecode --string chassis-type")
if computer_type in ["Notebook", "Laptop", "Convertible", "Portable"]:
# AC adapter states: 0, 1, unknown
ac_info = getoutput(f"grep . {power_dir}A*/online").splitlines()
# if there's one ac-adapter on-line, ac_state is True
ac_state = any(["1" in ac.split(":")[-1] for ac in ac_info])
# Battery statuses: Full, Charging, Discharging, Unknown
battery_status = getoutput(f"grep . {power_dir}B*/status").splitlines()
# if there's one battery charging, ac_state is True
ac_state = any(["Full" in ac or "Charging" in ac for ac in battery_status])
else:
has_battery = psutil.sensors_battery() is not None
if has_battery: