98_autocreate.pm: Fixing autocreateThreshold (Forum #37926)

git-svn-id: https://svn.fhem.de/fhem/trunk@9415 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig
2015-10-09 17:22:35 +00:00
parent f1d6f85d0a
commit 315d35670e

View File

@@ -136,7 +136,7 @@ autocreate_Notify($$)
my $at = AttrVal($me, "autocreateThreshold", undef); my $at = AttrVal($me, "autocreateThreshold", undef);
LoadModule($type) if( !$at ); LoadModule($type) if( !$at );
if($at) { if( $at || $modules{$type}{AutoCreate} ) {
my @at = split( '[, ]', $at?$at:"" ); my @at = split( '[, ]', $at?$at:"" );
my $hash = $defs{$me}; my $hash = $defs{$me};
@@ -182,30 +182,34 @@ autocreate_Notify($$)
#if there is an entry for this type #if there is an entry for this type
if( @v || $modules{$type}{AutoCreate} ) { if( @v || $modules{$type}{AutoCreate} ) {
my( undef, $min_count, $interval ) = split( ':', $v[0]?$v[0]:"" ); my( undef, $min_count, $interval ) = split( ':', $v[0]?$v[0]:"" );
my $found;
if( !@v ) { if( !@v ) {
if( my $fp = $modules{$type}{AutoCreate} ) { if( my $fp = $modules{$type}{AutoCreate} ) {
foreach my $k (keys %{$fp}) { foreach my $k (keys %{$fp}) {
next if($name !~ m/^$k$/ || !$fp->{$k}{autocreateThreshold}); next if($name !~ m/^$k$/ || !$fp->{$k}{autocreateThreshold});
($min_count, $interval) = ($min_count, $interval) =
split(':', $fp->{$k}{autocreateThreshold}); split(':', $fp->{$k}{autocreateThreshold});
$found = 1;
last; last;
} }
} }
} }
$min_count = 2 if( !$min_count ); if( @v || $found ) {
$interval = 60 if( !$interval ); $min_count = 2 if( !$min_count );
$interval = 60 if( !$interval );
#add this event #add this event
$hash->{received}{$type}{$arg}{$now} = 1; $hash->{received}{$type}{$arg}{$now} = 1;
my $count = keys %{$hash->{received}{$type}{$arg}}; my $count = keys %{$hash->{received}{$type}{$arg}};
Log3 $me, 4, "autocreate: received $count event(s) for ". Log3 $me, 4, "autocreate: received $count event(s) for ".
"'$type $arg' during the last $interval seconds"; "'$type $arg' during the last $interval seconds";
if( $count < $min_count ) { if( $count < $min_count ) {
Log3 $me, 4, "autocreate: ignoring event for ". Log3 $me, 4, "autocreate: ignoring event for ".
"'$type $arg': at least $min_count needed"; "'$type $arg': at least $min_count needed";
next; next;
}
} }
#forget entries for this type #forget entries for this type