summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraristocratos <gnmjpl@gmail.com>2020-09-27 00:42:25 +0200
committerGitHub <noreply@github.com>2020-09-27 00:42:25 +0200
commit549200d214a00f972361c01ea2c8f0b7561b927b (patch)
tree3b9fc6a7e5396ec0b7015f64df153f3471f8ffa1
parentfbcbd8edd030f83767a9b83ee25cd7a142d6171e (diff)
downloadpsutil-549200d214a00f972361c01ea2c8f0b7561b927b.tar.gz
Expanded battery sensor detection (#1837)
-rw-r--r--psutil/_pslinux.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py
index 52f7dd97..4a96c906 100644
--- a/psutil/_pslinux.py
+++ b/psutil/_pslinux.py
@@ -1340,7 +1340,8 @@ def sensors_battery():
return int(ret) if ret.isdigit() else ret
return None
- bats = [x for x in os.listdir(POWER_SUPPLY_PATH) if x.startswith('BAT')]
+ bats = [x for x in os.listdir(POWER_SUPPLY_PATH) if x.startswith('BAT') or
+ 'battery' in x.lower()]
if not bats:
return None
# Get the first available battery. Usually this is "BAT0", except
@@ -1358,12 +1359,14 @@ def sensors_battery():
energy_full = multi_cat(
root + "/energy_full",
root + "/charge_full")
- if energy_now is None or power_now is None:
+ time_to_empty = multi_cat(root + "/time_to_empty_now")
+
+ if (energy_now is None or power_now is None) and time_to_empty is None:
return None
# Percent. If we have energy_full the percentage will be more
# accurate compared to reading /capacity file (float vs. int).
- if energy_full is not None:
+ if energy_full is not None and energy_now is not None:
try:
percent = 100.0 * energy_now / energy_full
except ZeroDivisionError:
@@ -1395,11 +1398,15 @@ def sensors_battery():
# 013937745fd9050c30146290e8f963d65c0179e6/bin/battery.py#L55
if power_plugged:
secsleft = _common.POWER_TIME_UNLIMITED
- else:
+ elif energy_now is not None and power_now is not None:
try:
secsleft = int(energy_now / power_now * 3600)
except ZeroDivisionError:
secsleft = _common.POWER_TIME_UNKNOWN
+ elif time_to_empty is not None:
+ secsleft = int(time_to_empty * 60)
+ if secsleft < 0:
+ secsleft = _common.POWER_TIME_UNKNOWN
return _common.sbattery(percent, secsleft, power_plugged)