From 0c8f975e5d9e76bc30e6fb44d8f32567cfbf6a2b Mon Sep 17 00:00:00 2001 From: borisneubert Date: Mon, 2 Feb 2009 18:29:33 +0000 Subject: [PATCH] - fixes the rare but relevant case of two subsequent calls within one seconds (previously led to a division by zero error) git-svn-id: https://svn.fhem.de/fhem/trunk@346 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/13_KS300.pm | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/fhem/FHEM/13_KS300.pm b/fhem/FHEM/13_KS300.pm index 0b4e6ae30..1d7c96c2a 100755 --- a/fhem/FHEM/13_KS300.pm +++ b/fhem/FHEM/13_KS300.pm @@ -173,20 +173,20 @@ KS300_Parse($$) # The code also handles counter resets after battery replacement my $rain_raw_delta= $rain_raw- $rain_raw_prev; - my $thours_delta= ($tsecs- $tsecs_prev)/3600.0; # in hours - my $rain_raw_per_hour= $rain_raw_delta/$thours_delta; - if(($rain_raw_delta<0) || ($rain_raw_per_hour> 200.0)) { - $rain_raw_ofs= $rain_raw_ofs_prev-$rain_raw_delta; - # If the switch in the tick count occurs simultaneously with an - # increase due to rain, the tick is lost. We therefore assume that - # offsets between -5 and 0 are indeed rain. - if(($rain_raw_ofs>=-5) && ($rain_raw_ofs<0)) { $rain_raw_ofs= 0; } - $r->{rain_raw_ofs}{TIME} = $tm; - $r->{rain_raw_ofs}{VAL} = $rain_raw_ofs; - $def->{CHANGED}[$n++] = "rain_raw_ofs: $rain_raw_ofs"; - + if($tsecs!= $tsecs_prev) { # avoids a rare but relevant condition + my $thours_delta= ($tsecs- $tsecs_prev)/3600.0; # in hours + my $rain_raw_per_hour= $rain_raw_delta/$thours_delta; + if(($rain_raw_delta<0) || ($rain_raw_per_hour> 200.0)) { + $rain_raw_ofs= $rain_raw_ofs_prev-$rain_raw_delta; + # If the switch in the tick count occurs simultaneously with an + # increase due to rain, the tick is lost. We therefore assume that + # offsets between -5 and 0 are indeed rain. + if(($rain_raw_ofs>=-5) && ($rain_raw_ofs<0)) { $rain_raw_ofs= 0; } + $r->{rain_raw_ofs}{TIME} = $tm; + $r->{rain_raw_ofs}{VAL} = $rain_raw_ofs; + $def->{CHANGED}[$n++] = "rain_raw_ofs: $rain_raw_ofs"; + } } - $rain_raw_adj= $rain_raw+ $rain_raw_ofs; }