1
0
Fork 0

fix battery indicator when no battery found

This commit is contained in:
Luca Bilke 2022-07-19 15:50:04 +02:00
parent d4b3c9b6e8
commit f68beec525
1 changed files with 15 additions and 13 deletions

View File

@ -31,22 +31,24 @@ def get_battery():
# return ret + PLUGGED_ICONS[min(PLUGGED_ICONS.keys(), key=lambda x: abs(x - battery.percent))]
# return ret + UNPLUGGED_ICONS[min(UNPLUGGED_ICONS.keys(), key=lambda x: abs(x - battery.percent))]
battery = psutil.sensors_battery()
ret = str(round(battery.percent)) + "% "
if not battery:
return ret + UNKOWN_ICON
if battery.power_plugged:
try:
ret = str(round(battery.percent)) + "% "
if not battery:
return ret + UNKOWN_ICON
if battery.power_plugged:
return (
ret
+ PLUGGED_ICONS[
min(PLUGGED_ICONS.keys(), key=lambda x: abs(x * 10 - battery.percent))
]
)
return (
ret
+ PLUGGED_ICONS[
min(PLUGGED_ICONS.keys(), key=lambda x: abs(x * 10 - battery.percent))
+ UNPLUGGED_ICONS[
min(UNPLUGGED_ICONS.keys(), key=lambda x: abs(x * 10 - battery.percent))
]
)
return (
ret
+ UNPLUGGED_ICONS[
min(UNPLUGGED_ICONS.keys(), key=lambda x: abs(x * 10 - battery.percent))
]
)
except AttributeError:
return ""
print(get_battery())