98_HourCounter.pm : bug: if cvent occurs without value change, wrong calculcation of pulseTimeIncrement, pauseTimeIncrement

git-svn-id: https://svn.fhem.de/fhem/trunk@7336 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
john99sr 2014-12-27 19:04:18 +00:00
parent 23a38c6c52
commit 8f57a265ad

View File

@ -1,4 +1,4 @@
# $Id: 98_HourCounter.pm 7281 2014-12-21 12:00:00Z john $ # $Id: 98_HourCounter.pm 7336 2014-12-27 20:00:00Z john $
#################################################################################################### ####################################################################################################
# #
# 98_HourCounter.pm # 98_HourCounter.pm
@ -58,6 +58,8 @@
# 21.12.14 - 1.0.1.1 # 21.12.14 - 1.0.1.1
# bug: if OFF is not defined, nothing was counted # bug: if OFF is not defined, nothing was counted
# html : check with tidy # html : check with tidy
# 24.12.14 - 1.0.1.2
# bug: if cvent occurs without value change, wrong calculcation of pulseTimeIncrement, pauseTimeIncrement
#################################################################################################### ####################################################################################################
package main; package main;
@ -67,7 +69,7 @@ use vars qw(%defs);
use vars qw($readingFnAttributes); use vars qw($readingFnAttributes);
use vars qw(%attr); use vars qw(%attr);
use vars qw(%modules); use vars qw(%modules);
my $HourCounter_Version = "1.0.1.1 - 21.12.2014"; my $HourCounter_Version = "1.0.1.2 - 24.12.2014";
my @HourCounter_cmdQeue = (); my @HourCounter_cmdQeue = ();
@ -239,6 +241,10 @@ sub HourCounter_Define($$$)
eval { "Hallo" =~ m/^$offRegexp/ }; eval { "Hallo" =~ m/^$offRegexp/ };
return "Bad regexp_for_ON : $@" if ($@); return "Bad regexp_for_ON : $@" if ($@);
} }
#
# some inits
$hash->{VERSION} = $HourCounter_Version;
$hash->{helper}{ON_Regexp} = $onRegexp; $hash->{helper}{ON_Regexp} = $onRegexp;
$hash->{helper}{OFF_Regexp} = $offRegexp; $hash->{helper}{OFF_Regexp} = $offRegexp;
$hash->{helper}{isFirstRun} = 1; $hash->{helper}{isFirstRun} = 1;
@ -626,19 +632,22 @@ sub HourCounter_Run($)
$hasValueChanged = 1; $hasValueChanged = 1;
} }
# -------------- positive edge if ($hasValueChanged)
if ( $hasValueChanged && $valuePara == 1 )
{ {
$value = $valuePara; $value = $valuePara;
$valueOld = $valuePara; $valueOld = $valuePara;
# -------------- positive edge
if ( $valuePara == 1 )
{
# handling of counters # handling of counters
$countsPerDay += 1; $countsPerDay += 1;
$countsOverall += 1; $countsOverall += 1;
#.. handling of pause # handling of pause time
if ($isOffDefined) if ($isOffDefined)
{ {
# calc the rest of puse-time until edge
$pauseTimeIncrement += $timeIncrement; $pauseTimeIncrement += $timeIncrement;
$pauseTimePerDay += $timeIncrement; $pauseTimePerDay += $timeIncrement;
$pauseTimeOverall += $timeIncrement; $pauseTimeOverall += $timeIncrement;
@ -649,22 +658,24 @@ sub HourCounter_Run($)
} }
# ------------ negative edge # ------------ negative edge
elsif ( $hasValueChanged && $valuePara == 0 ) elsif ( $valuePara == 0 )
{
# handlich of pulse time
if ($isOffDefined)
{ {
$value = $valuePara;
$valueOld = $valuePara;
# handling of pulse time
$pulseTimeIncrement += $timeIncrement; $pulseTimeIncrement += $timeIncrement;
$pulseTimePerDay += $timeIncrement; $pulseTimePerDay += $timeIncrement;
$pulseTimeOverall += $timeIncrement; $pulseTimeOverall += $timeIncrement;
$pulseTimeEdge = $pulseTimeIncrement;
$pauseTimeIncrement = 0; $pauseTimeIncrement = 0;
$pulseTimeEdge = $pulseTimeIncrement;
}
HourCounter_Log $hash, 4, "falling edge pulseTimeIncrement:$pulseTimeIncrement"; HourCounter_Log $hash, 4, "falling edge pulseTimeIncrement:$pulseTimeIncrement";
} }
}
# --------------- no change # ------------ no value change
elsif ( $valuePara == -1 && $isOffDefined ) # it is possible to receive an event without change of value (e.g. Max Shutter does it hourly)
elsif ($isOffDefined)
{ {
if ( $valueOld == 0 ) if ( $valueOld == 0 )
{ {