summaryrefslogtreecommitdiff
path: root/.local/bin/lemonbar/modules/battery.py
diff options
context:
space:
mode:
authorAndrew <saintruler@gmail.com>2021-05-10 16:44:03 +0400
committerAndrew <saintruler@gmail.com>2021-05-10 16:44:03 +0400
commit2415600f57020fba9e43542bc226a4631a1b8e2d (patch)
tree7bdb82d3263f92d3ab060454e4d39fa7d62d4f69 /.local/bin/lemonbar/modules/battery.py
parenta6fda248d39119304f64b65c544285141ca58546 (diff)
Added checks for some errors in lemonbar config
Diffstat (limited to '.local/bin/lemonbar/modules/battery.py')
-rw-r--r--.local/bin/lemonbar/modules/battery.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/.local/bin/lemonbar/modules/battery.py b/.local/bin/lemonbar/modules/battery.py
index cb93f03..7cf3c54 100644
--- a/.local/bin/lemonbar/modules/battery.py
+++ b/.local/bin/lemonbar/modules/battery.py
@@ -4,8 +4,11 @@ def read_file(filename):
def callback():
battery = "BAT0"
- now = int(read_file(f"/sys/class/power_supply/{battery}/energy_now"))
- full = int(read_file(f"/sys/class/power_supply/{battery}/energy_full"))
- percent = round(now / full * 100)
- return f"BAT: {percent}%"
+ try:
+ now = int(read_file(f"/sys/class/power_supply/{battery}/energy_now"))
+ full = int(read_file(f"/sys/class/power_supply/{battery}/energy_full"))
+ percent = round(now / full * 100)
+ return f"BAT: {percent}%"
+ except FileNotFoundError:
+ return f"BAT: Disabled"