From 3042e18ab0a3b2a720222a3cd7ab1ccdd6a70f8c Mon Sep 17 00:00:00 2001 From: Yannik Schmidt Date: Tue, 14 May 2024 21:40:49 +0200 Subject: [PATCH] fix: battery query crashes on missing history --- herbstluftwm/autostart | 2 +- herbstluftwm/hl_status_deamon.py | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/herbstluftwm/autostart b/herbstluftwm/autostart index f40e629..f9c3842 100755 --- a/herbstluftwm/autostart +++ b/herbstluftwm/autostart @@ -63,7 +63,7 @@ fi hc keybind $Mod-p spawn pavucontrol 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-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-Shift-e spawn rofi -show run hc keybind $Mod-u spawn /usr/bin/pulseaudio -k diff --git a/herbstluftwm/hl_status_deamon.py b/herbstluftwm/hl_status_deamon.py index ebeeefe..ef05d9f 100755 --- a/herbstluftwm/hl_status_deamon.py +++ b/herbstluftwm/hl_status_deamon.py @@ -111,7 +111,11 @@ def battery(): spm = 60 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 bat_prev @@ -120,6 +124,9 @@ def battery(): bat_avg = "unkown" else: 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 ## if len(battery_average) > VALUES_KEPT: