Fix the case that "/sys/class/power_supply" is not existing

This fixes the execution on FreeBSD.
pull/135/head
Li-Wen Hsu 2020-09-28 17:01:49 +08:00
parent 45b103adb1
commit 6643dc2605
No known key found for this signature in database
GPG Key ID: 8D7BCC7D012FD37E
1 changed files with 6 additions and 6 deletions

View File

@ -1637,12 +1637,12 @@ class CpuBox(Box, SubBox):
return False
if cls.battery_path == "":
cls.battery_path = None
if os.path.isdir("/sys/class/power_supply"):
for directory in os.listdir("/sys/class/power_supply"):
if directory.startswith('BAT') or 'battery' in directory.lower():
cls.battery_path = f'/sys/class/power_supply/{directory}/'
break
else:
cls.battery_path = None
return_true: bool = False
percent: int = ceil(getattr(psutil.sensors_battery(), "percent", 0))