diff --git a/fhem/CHANGED b/fhem/CHANGED index 92f9cf527..f764d836b 100644 --- a/fhem/CHANGED +++ b/fhem/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: FB_CALLMONITOR: new attribute "external-mapping", new column for + external_connection reading (see commandref for details, by Michael) - feature: Dashboard: release version 3.0 - bugfix: SYSMON: 'disable' not working at FHEM-start - bugfix: Text2Speech: ogg/wav as direkt mp3files are now possible diff --git a/fhem/FHEM/72_FB_CALLLIST.pm b/fhem/FHEM/72_FB_CALLLIST.pm index c56809037..9247d74e4 100755 --- a/fhem/FHEM/72_FB_CALLLIST.pm +++ b/fhem/FHEM/72_FB_CALLLIST.pm @@ -45,8 +45,9 @@ FB_CALLLIST_Initialize($) $hash->{AttrList} = "number-of-calls:1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 ". "internal-number-filter ". "connection-mapping ". + "external-mapping ". "create-readings:0,1 ". - "visible-columns:sortable-strict,row,state,timestamp,name,number,internal,connection,duration ". + "visible-columns:sortable-strict,row,state,timestamp,name,number,internal,external,connection,duration ". "show-icons:1,0 ". "list-type:all,incoming,outgoing,missed-calls,completed,active " . "time-format-string ". @@ -68,16 +69,16 @@ FB_CALLLIST_Initialize($) # Define function sub FB_CALLLIST_Define($$) { - my ($hash, $def) = @_; - my @a = split("[ \t][ \t]*", $def); - my $retval = undef; - my $name = $a[0]; + my ($hash, $def) = @_; + my @a = split("[ \t][ \t]*", $def); + my $retval = undef; + my $name = $a[0]; if(!defined($a[2])) - { - $retval = "FB_CALLLIST_define: you must specify a FB_CALLMONITOR object for using FB_CALLLIST"; - return $retval; - } + { + $retval = "FB_CALLLIST_define: you must specify a FB_CALLMONITOR object for using FB_CALLLIST"; + return $retval; + } if(@a != 3) { @@ -85,19 +86,19 @@ sub FB_CALLLIST_Define($$) return $retval; } - unless(defined($defs{$a[2]}) and $defs{$a[2]}->{TYPE} eq "FB_CALLMONITOR") - { - $retval = "FB_CALLLIST_Define: $a[2] does not exists or ist not of type FB_CALLMONITOR"; - return $retval; - } + unless(defined($defs{$a[2]}) and $defs{$a[2]}->{TYPE} eq "FB_CALLMONITOR") + { + $retval = "FB_CALLLIST_Define: $a[2] does not exists or ist not of type FB_CALLMONITOR"; + return $retval; + } - $hash->{FB} = $a[2]; + $hash->{FB} = $a[2]; $hash->{NOTIFYDEV} = $a[2]; - $hash->{STATE} = 'Initialized'; - $hash->{helper}{DEFAULT_COLUMN_ORDER} = "row,state,timestamp,name,number,internal,connection,duration"; + $hash->{STATE} = 'Initialized'; + $hash->{helper}{DEFAULT_COLUMN_ORDER} = "row,state,timestamp,name,number,internal,external,connection,duration"; FB_CALLLIST_loadList($hash); - return undef; + return undef; } @@ -118,7 +119,7 @@ sub FB_CALLLIST_Attr($@) if($table and (ref($table) eq 'HASH')) { - $hash->{helper}{LINE_FILTER} = $table; + $hash->{helper}{INTERNAL_FILTER} = $table; Log3 $name, 4, "FB_CALLLIST ($name) - filter stored as hash: $value"; } else @@ -134,7 +135,7 @@ sub FB_CALLLIST_Attr($@) $lines{$item} = $item; } - $hash->{helper}{LINE_FILTER} = \%lines; + $hash->{helper}{INTERNAL_FILTER} = \%lines; Log3 $name, 4, "FB_CALLLIST ($name) - filter stored as list $value"; } @@ -171,6 +172,30 @@ sub FB_CALLLIST_Attr($@) return "invalid connection mapping table: $value"; } } + elsif($attrib eq "external-mapping") + { + if( $value =~ m/^{.*}$/ ) + { + my $table = eval $value; + + if( $table &&(ref($table) eq 'HASH')) + { + $hash->{helper}{EXTERNAL_MAP} = $table; + Log3 $name, 4, "FB_CALLLIST ($name) - external map stored as hash: $value"; + + # Inform all FHEMWEB clients + FB_CALLLIST_updateFhemWebClients($hash) if($init_done); + } + else + { + return "invalid external mapping table: $value"; + } + } + else + { + return "invalid external mapping table: $value"; + } + } elsif($attrib eq "list-type") { if($value =~ /^incoming|outgoing|missed-call|completed|active$/) @@ -192,7 +217,7 @@ sub FB_CALLLIST_Attr($@) { if($attrib eq "internal-number-filter") { - delete($hash->{helper}{LINE_FILTER}) if(exists($hash->{helper}{LINE_FILTER})); + delete($hash->{helper}{INTERNAL_FILTER}) if(exists($hash->{helper}{INTERNAL_FILTER})); return undef; } elsif($attrib eq "connection-mapping") @@ -200,6 +225,11 @@ sub FB_CALLLIST_Attr($@) delete($hash->{helper}{CONNECTION_MAP}) if(exists($hash->{helper}{CONNECTION_MAP})); return undef; } + elsif($attrib eq "external-mapping") + { + delete($hash->{helper}{EXTERNAL_MAP}) if(exists($hash->{helper}{EXTERNAL_MAP})); + return undef; + } } } @@ -207,9 +237,9 @@ sub FB_CALLLIST_Attr($@) # SetFn for clearing the list sub FB_CALLLIST_Set($@) { - my ($hash, $name, $cmd, $value) = @_; + my ($hash, $name, $cmd, $value) = @_; - my $usage = "Unknown argument $cmd, choose one of clear:noArg"; + my $usage = "Unknown argument $cmd, choose one of clear:noArg"; if($cmd eq "clear") { @@ -230,20 +260,20 @@ sub FB_CALLLIST_Set($@) # NotifyFn is trigger upon changes on FB_CALLMONITOR device. Imports the call data into call list sub FB_CALLLIST_Notify($$) { - my ($hash,$d) = @_; + my ($hash,$d) = @_; - return undef if(!defined($hash)); + return undef if(!defined($hash)); - my $name = $hash->{NAME}; + my $name = $hash->{NAME}; - return undef if(IsDisabled($name)); + return undef if(IsDisabled($name)); - my $fb = $d->{NAME}; + my $fb = $d->{NAME}; - if ($fb ne $hash->{FB}) + if ($fb ne $hash->{FB}) { - return undef; - } + return undef; + } my $event = ReadingsVal($fb, "event", undef); my $call_id = ReadingsVal($fb, "call_id", undef); @@ -257,23 +287,21 @@ sub FB_CALLLIST_Notify($$) return undef } - if(exists($hash->{helper}{LINE_FILTER})) - { + if(exists($hash->{helper}{INTERNAL_FILTER})) + { Log3 $name, 5, "FB_CALLLIST ($name) - internal-number-filter is defined, checking if internal number is allowed"; - my $line_number = ReadingsVal($fb, "internal_number", undef); + my $line_number = ReadingsVal($fb, "internal_number", undef); - if(defined($line_number) and not exists($hash->{helper}{LINE_FILTER}{$line_number})) - { - Log3 $name, 5, "FB_CALLLIST ($name) - internal number $line_number does not match the current internal-number-filter. skipping call."; - return undef; - } + if(defined($line_number) and not exists($hash->{helper}{INTERNAL_FILTER}{$line_number})) + { + Log3 $name, 5, "FB_CALLLIST ($name) - internal number $line_number does not match the current internal-number-filter. skipping call."; + return undef; + } Log3 $name, 5, "FB_CALLLIST ($name) - call passed the internal-number-filter. proceeding..."; - } - - - + } + my $data; if($event =~ /^call|ring$/) @@ -286,6 +314,7 @@ sub FB_CALLLIST_Notify($$) $data->{external_number} = ReadingsVal($fb, "external_number", undef); $data->{external_name} = ReadingsVal($fb, "external_name", undef); + $data->{external_connection} = ReadingsVal($fb, "external_connection", undef); $data->{internal_number} = ReadingsVal($fb, "internal_number", undef); $data->{direction} = ReadingsVal($fb, "direction", undef); $data->{running_call} = 1; @@ -396,7 +425,7 @@ sub FB_CALLLIST_cleanupList($) } # delete calls which do not match the configured internal-number-filter - if(exists($hash->{helper}{LINE_FILTER})) + if(exists($hash->{helper}{INTERNAL_FILTER})) { push @list, grep { not FB_CALLLIST_checkForInternalNumberFilter($hash, $hash->{helper}{DATA}{$_}{internal_number}) } keys %{$hash->{helper}{DATA}}; } @@ -406,9 +435,7 @@ sub FB_CALLLIST_cleanupList($) { Log3 $name, 5, "FB_CALLLIST ($name) - deleting old call $index"; delete($hash->{helper}{DATA}{$index}) if(exists($hash->{helper}{DATA}{$index})); - } - - + } } else { @@ -440,7 +467,6 @@ sub FB_CALLLIST_returnCallState($$;$) { $state = "=> ((o))"; $state = FW_makeImage("phone_ring\@blue",$state) if($icons); - } elsif($data->{direction} eq "outgoing" and $data->{last_event} eq "connect" ) { @@ -551,7 +577,8 @@ sub FB_CALLLIST_list2html($;$) my $time = strftime(AttrVal($name, "time-format-string", "%a, %d %b %Y %H:%M:%S"), localtime($index)); my $name = ($data->{external_name} eq "unknown" ? "-" : $data->{external_name}); my $number = $data->{external_number}; - my $internal = ((exists($hash->{helper}{LINE_FILTER}) and exists($hash->{helper}{LINE_FILTER}{$data->{internal_number}})) ? $hash->{helper}{LINE_FILTER}{$data->{internal_number}} : $data->{internal_number} ); + my $external = ($data->{external_connection} ? ((exists($hash->{helper}{EXTERNAL_MAP}) and exists($hash->{helper}{EXTERNAL_MAP}{$data->{external_connection}})) ? $hash->{helper}{EXTERNAL_MAP}{$data->{external_connection}} : $data->{external_connection} ) : "-"); + my $internal = ((exists($hash->{helper}{INTERNAL_FILTER}) and exists($hash->{helper}{INTERNAL_FILTER}{$data->{internal_number}})) ? $hash->{helper}{INTERNAL_FILTER}{$data->{internal_number}} : $data->{internal_number} ); my $connection = ($data->{internal_connection} ? ((exists($hash->{helper}{CONNECTION_MAP}) and exists($hash->{helper}{CONNECTION_MAP}{$data->{internal_connection}})) ? $hash->{helper}{CONNECTION_MAP}{$data->{internal_connection}} : $data->{internal_connection} ) : "-"); my $duration = FB_CALLLIST_formatDuration($hash, $index); @@ -563,6 +590,7 @@ sub FB_CALLLIST_list2html($;$) timestamp => $time, name => $name, number => $number, + external => $external, internal => $internal, connection => $connection, duration => $duration @@ -814,20 +842,20 @@ sub FB_CALLLIST_checkForInternalNumberFilter($$) my ($hash, $line_number) = @_; my $name = $hash->{NAME}; - if(exists($hash->{helper}{LINE_FILTER})) - { + if(exists($hash->{helper}{INTERNAL_FILTER})) + { Log3 $name, 5, "FB_CALLLIST ($name) - internal-number-filter is defined, checking if internal number $line_number is allowed"; - if(defined($line_number) and not exists($hash->{helper}{LINE_FILTER}{$line_number})) - { - Log3 $name, 5, "FB_CALLLIST ($name) - internal number $line_number does not match the current internal-number-filter: ".Dumper($hash->{helper}{LINE_FILTER}); - return undef; - } + if(defined($line_number) and not exists($hash->{helper}{INTERNAL_FILTER}{$line_number})) + { + Log3 $name, 5, "FB_CALLLIST ($name) - internal number $line_number does not match the current internal-number-filter: ".Dumper($hash->{helper}{INTERNAL_FILTER}); + return undef; + } else { Log3 $name, 5, "FB_CALLLIST ($name) - call passed the internal-number-filter. proceeding..."; } - } + } return 1; } @@ -894,6 +922,7 @@ sub FB_CALLLIST_returnTableHeader($) name => "Name", number => "Rufnummer", internal => "Intern", + external => "Extern", connection => "Via", duration => "Dauer" }; @@ -909,6 +938,7 @@ sub FB_CALLLIST_returnTableHeader($) name => "Name", number => "Number", internal => "Internal", + external => "External", connection => "Via", duration => "Duration" }; @@ -981,12 +1011,12 @@ sub FB_CALLLIST_returnTableHeader($)
attr <name> external-mapping {'ISDN' => 'Fixed Network', 'SIP0' => 'Operator A', 'SIP1' => 'Operator B'}
+ row,state,timestamp,name,number,internal,connection,durationrow,state,timestamp,name,number,internal,external,connection,durationattr <name> external-mapping {'ISDN' => 'Festnetz', 'SIP0' => 'Anbieter A', 'SIP1' => 'Anbieter B'}
+ row,state,timestamp,name,number,internal,connection,durationrow,state,timestamp,name,number,internal,external,connection,duration