🐛 handle invalid numbers

This commit is contained in:
neingeist 2025-05-23 21:07:39 +02:00
parent 15c3d5062e
commit e4b7302210

View file

@ -4,6 +4,7 @@ use utf8;
use strict;
use warnings;
use Carp;
use Scalar::Util qw(looks_like_number);
use Sys::Filesystem ();
use Filesys::Df qw(df);
@ -112,14 +113,18 @@ sub conky_hddtemp {
my $unit = $hddtemp_output[$i*5+4];
my $color = $color_ok;
if ($temp > 40) {
if (not(looks_like_number($temp)) or $temp > 40) {
$color = $color_toohot;
} elsif ($temp < 25) {
$color = $color_toocold;
}
printf " \${color #98c2c7}%s\$color ", $dev;
printf "\${color $color}%02.f°%s\$color\n", $temp, $unit;
if (looks_like_number($temp)) {
printf "\${color $color}%02.f°%s\$color\n", $temp, $unit;
} else {
printf "\${color $color}%s°%s\$color\n", $temp, $unit;
}
}
}