fix: battery query crashes on missing history

This commit is contained in:
2024-05-14 21:40:49 +02:00
parent 46053ac19e
commit 3042e18ab0
2 changed files with 9 additions and 2 deletions

View File

@@ -63,7 +63,7 @@ fi
hc keybind $Mod-p spawn pavucontrol hc keybind $Mod-p spawn pavucontrol
hc keybind $Mod-Shift-l spawn libreoffice hc keybind $Mod-Shift-l spawn libreoffice
hc keybind $Mod-t spawn /bin/bash -c "LC_ALL=en_DK.utf8 && export LC_ALL && thunderbird" hc keybind $Mod-t spawn /bin/bash -c "LC_ALL=en_DK.utf8 && export LC_ALL && thunderbird"
hc keybind $Mod-Shift-j spawn urxvt -e ssh -p 7022 sheppy@atlantishq.de -t 'tmux a -d' hc keybind $Mod-Shift-j spawn urxvt -e ssh sheppy@irc-new.atlantishq.de -t 'tmux a -d'
hc keybind $Mod-e spawn rofi -combi-mode window,run -show combi -modi combi hc keybind $Mod-e spawn rofi -combi-mode window,run -show combi -modi combi
hc keybind $Mod-Shift-e spawn rofi -show run hc keybind $Mod-Shift-e spawn rofi -show run
hc keybind $Mod-u spawn /usr/bin/pulseaudio -k hc keybind $Mod-u spawn /usr/bin/pulseaudio -k

View File

@@ -111,7 +111,11 @@ def battery():
spm = 60 spm = 60
cur_time = bat.split('%, ')[1].split(' ')[0].split(':') cur_time = bat.split('%, ')[1].split(' ')[0].split(':')
cur = int(cur_time[0]) * sph + int(cur_time[1]) * spm + int(cur_time[2]) cur = 0
try:
cur = int(cur_time[0]) * sph + int(cur_time[1]) * spm + int(cur_time[2])
except ValueError:
pass
global battery_average global battery_average
global bat_prev global bat_prev
@@ -121,6 +125,9 @@ def battery():
else: else:
bat_avg=int(sum(battery_average) / float(len(battery_average))) bat_avg=int(sum(battery_average) / float(len(battery_average)))
if len(battery_average) > 100:
battery_average = battery_average[:-100]
## keep max 10 items in queue ## ## keep max 10 items in queue ##
if len(battery_average) > VALUES_KEPT: if len(battery_average) > VALUES_KEPT:
battery_average = battery_average[1:] battery_average = battery_average[1:]