diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2017-02-05 22:54:48 +0100 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2017-02-05 22:54:48 +0100 |
commit | ba2fdbd15f43bf2f82458d39310edd0bc2c57588 (patch) | |
tree | 84954a32e63aa67fcf0c6123e0deba7472dd6d6c | |
parent | b1faa75d9108d3897d3f51176a663f17b7c076f0 (diff) | |
download | psutil-ba2fdbd15f43bf2f82458d39310edd0bc2c57588.tar.gz |
battery: handle the case where AC0/online is AC/online
-rw-r--r-- | psutil/_pslinux.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index 4720e762..80de7b80 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -1167,12 +1167,13 @@ def sensors_battery(): return None # Is AC power cable plugged in? - # Note: AC0 is not always available. Sometimes (e.g. CentOS7) + # Note: AC0 is not always available and sometimes (e.g. CentOS7) # it's called "AC". - if os.path.exists(os.path.join(POWER_SUPPLY_PATH, "AC0/online")): - power_plugged = cat( - os.path.join(POWER_SUPPLY_PATH, "AC0/online"), - fallback=b"0") == b"1" + online = multi_cat( + os.path.join(POWER_SUPPLY_PATH, "AC0/online"), + os.path.join(POWER_SUPPLY_PATH, "AC/online")) + if online is not None: + power_plugged = online == 1 elif os.path.exists(root + "/status"): status = cat(root + "/status", fallback="", binary=False).lower() if status == "discharging": |