From ba2fdbd15f43bf2f82458d39310edd0bc2c57588 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Sun, 5 Feb 2017 22:54:48 +0100 Subject: battery: handle the case where AC0/online is AC/online --- psutil/_pslinux.py | 11 ++++++----- 1 file 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": -- cgit v1.2.1