diff --git a/CHANGED b/CHANGED
index 079184933..201368f66 100644
--- a/CHANGED
+++ b/CHANGED
@@ -1,5 +1,7 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it.
+ - feature: 72_FB_CALLMONITOR: new attribute "internal-number-filter" to
+ process only calls for specific internal numbers
- change: 93_Log2Syslog: switch to packages, improve IETF octet count
- bugfix: 49_SSCam: fix autocreate bug with https
- change: 37_echodevice.pm more loginformations set "NPM_login new"
diff --git a/FHEM/72_FB_CALLMONITOR.pm b/FHEM/72_FB_CALLMONITOR.pm
index 2adf5ca69..c74bb8a24 100755
--- a/FHEM/72_FB_CALLMONITOR.pm
+++ b/FHEM/72_FB_CALLMONITOR.pm
@@ -62,6 +62,7 @@ FB_CALLMONITOR_Initialize($)
"local-area-code ".
"country-code ".
"remove-leading-zero:0,1 ".
+ "internal-number-filter ".
"answMachine-is-missed-call:0,1 ".
"check-deflections:0,1 ".
"reverse-search-cache-file ".
@@ -427,7 +428,6 @@ FB_CALLMONITOR_Read($)
my $external_number = undef;
my $reverse_search = undef;
- my $is_deflected = undef;
Log3 $name, 5, "FB_CALLMONITOR ($name) - received data: $data";
@@ -436,7 +436,7 @@ FB_CALLMONITOR_Read($)
$external_number = $array[3] if(not $array[3] eq "0" and $array[1] eq "RING" and $array[3] ne "");
$external_number = $array[5] if($array[1] eq "CALL" and $array[3] ne "");
- $is_deflected = FB_CALLMONITOR_checkNumberForDeflection($hash, $external_number) if($array[1] eq "RING");
+ Log3 $name, 4, "FB_CALLMONITOR ($name) - received event ".$array[1]." for call id ".$array[2].(defined($external_number) ? " (external number: $external_number)" : "");
if(defined($external_number))
{
@@ -494,7 +494,12 @@ FB_CALLMONITOR_Read($)
if(my $contact_image = FB_CALLMONITOR_getContactImage($hash, $hash->{helper}{TEMP}{$array[2]}{external_number}))
{
$hash->{helper}{TEMP}{$array[2]}{contact_image} = $contact_image;
- }
+ }
+
+ if(FB_CALLMONITOR_checkNumberIsFiltered($hash, $hash->{helper}{TEMP}{$array[2]}{internal_number}))
+ {
+ $hash->{helper}{TEMP}{$array[2]}{".filtered"} = 1
+ }
}
if($array[1] eq "CALL")
@@ -508,7 +513,7 @@ FB_CALLMONITOR_Read($)
{
$hash->{helper}{TEMP}{$array[2]}{external_connection} = $array[5];
$hash->{helper}{TEMP}{$array[2]}{direction} = "incoming";
- $hash->{helper}{TEMP}{$array[2]}{".deflected"} = $is_deflected;
+ $hash->{helper}{TEMP}{$array[2]}{".deflected"} = FB_CALLMONITOR_checkNumberForDeflection($hash, $external_number);
}
if($array[1] eq "CONNECT" and not exists($hash->{helper}{TEMP}{$array[2]}{internal_connection}))
@@ -532,27 +537,47 @@ FB_CALLMONITOR_Read($)
$hash->{helper}{TEMP}{$array[2]}{".last-event"} = $array[1];
- readingsBeginUpdate($hash);
- unless($hash->{helper}{TEMP}{$array[2]}{".deflected"})
+ # skip readings/event generation if call does not matched a configured internal number filter
+ if($hash->{helper}{TEMP}{$array[2]}{".filtered"})
{
- readingsBulkUpdate($hash, "event", lc($array[1]));
+ Log3 $name, 4, "FB_CALLMONITOR ($name) - skipped creating readings/events because number does not match configured attribute internal-number-filter";
- foreach my $key (keys %{$hash->{helper}{TEMP}{$array[2]}})
+ if($array[1] eq "DISCONNECT")
{
- readingsBulkUpdate($hash, $key, $hash->{helper}{TEMP}{$array[2]}{$key}) unless($key =~ /^\./);
- }
- }
- else
- {
- Log3 $name, 4, "FB_CALLMONITOR ($name) - skipped creating readings/events due to deflection match";
+ delete($hash->{helper}{TEMP}{$array[2]});
+ }
+
+ next;
}
+ # skip readings/event generation if call is deflected
+ if($hash->{helper}{TEMP}{$array[2]}{".deflected"})
+ {
+ Log3 $name, 4, "FB_CALLMONITOR ($name) - skipped creating readings/events due to deflection match";
+
+ if($array[1] eq "DISCONNECT")
+ {
+ delete($hash->{helper}{TEMP}{$array[2]});
+ }
+
+ next;
+ }
+
+ # create readings/events
+ readingsBeginUpdate($hash);
+ readingsBulkUpdate($hash, "event", lc($array[1]));
+
+ foreach my $key (keys %{$hash->{helper}{TEMP}{$array[2]}})
+ {
+ readingsBulkUpdate($hash, $key, $hash->{helper}{TEMP}{$array[2]}{$key}) unless($key =~ /^\./);
+ }
+
if($array[1] eq "DISCONNECT")
{
delete($hash->{helper}{TEMP}{$array[2]});
}
- readingsBulkUpdate($hash, "calls_count", scalar keys %{$hash->{helper}{TEMP}});
+ readingsBulkUpdate($hash, "calls_count", scalar grep { not $hash->{helper}{TEMP}{$_}{".filtered"} } keys %{$hash->{helper}{TEMP}});
readingsEndUpdate($hash, 1);
}
@@ -625,6 +650,21 @@ FB_CALLMONITOR_Attr($@)
{
return "invalid value $value for $attrib. Allowed values are: none,5m,10m,15m,30m,1h";
}
+
+ if($attrib eq "internal-number-filter")
+ {
+ if($value !~ /^\d+(?:,\d+)*$/)
+ {
+ return 'invalid value $value for $attrib. It should contain a single internal number or a comma separated list of multiple internal numbers. (e.g. "12345" or "12345,56789")';
+ }
+
+ delete($hash->{helper}{INTERNAL_FILTER});
+
+ foreach my $item (split("[ \t,][ \t,]*",$value))
+ {
+ $hash->{helper}{INTERNAL_FILTER}{$item} = 1;
+ }
+ }
}
elsif($cmd eq "del")
{
@@ -643,6 +683,11 @@ FB_CALLMONITOR_Attr($@)
delete($hash->{helper}{TEXTFILE});
}
+ if($attrib eq "internal-number-filter")
+ {
+ delete($hash->{helper}{INTERNAL_FILTER});
+ }
+
if($attrib eq "disable")
{
DevIo_OpenDev($hash, 0, undef, \&FB_CALLMONITOR_DevIoCallback);
@@ -2277,6 +2322,19 @@ sub FB_CALLMONITOR_checkNumberForDeflection($$)
return $ret;
}
+sub FB_CALLMONITOR_checkNumberIsFiltered($$)
+{
+ my ($hash, $number) = @_;
+ my $name = $hash->{NAME};
+
+ if(exists($hash->{helper}{INTERNAL_FILTER}) and not exists($hash->{helper}{INTERNAL_FILTER}{$number}))
+ {
+ return 1;
+ }
+
+ return 0;
+}
+
sub FB_CALLMONITOR_sendKeepAlive($)
{
my ($hash) = @_;
@@ -2395,6 +2453,12 @@ sub FB_CALLMONITOR_sendKeepAlive($)
Possible values: 0 => disabled, 1 => enabled (answering machine calls will be treated as "missed call").
Default Value is 0 (disabled)
+