Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude external batteries from sensors_battery #2305

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -1471,9 +1471,13 @@ def multi_bcat(*paths):
except ValueError:
return ret.strip()
return None
# The final check verifies if the reported battery is internal
# since the existence of the device/path file represent an available
# ACPI path to the battery itself.
bats = [x for x in os.listdir(POWER_SUPPLY_PATH) if x.startswith('BAT')
or 'battery' in x.lower() and
os.path.exists(os.path.join(POWER_SUPPLY_PATH, x, "device/path"))]

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
Expand Down