From 361a3948a1029dc3fab399aa32374575cf853217 Mon Sep 17 00:00:00 2001 From: markusbloch Date: Sun, 5 Jul 2015 18:54:17 +0000 Subject: [PATCH] FB_CALLLIST: new attribute "external-mapping", new column for external_connection reading (by Michael) git-svn-id: https://svn.fhem.de/fhem/trunk@8900 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 2 + fhem/FHEM/72_FB_CALLLIST.pm | 192 +++++++++++++++++++++++------------- 2 files changed, 123 insertions(+), 71 deletions(-) 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($)
  • do_not_notify
  • readingFnAttributes

  • disable 0,1
  • - Optional attribute to disable the call list update. When disabled, call events will be processed and the list wouldn't be updated accordingly. -

    - Possible values: 0 => FB_CALLLIST is activated, 1 => FB_CALLLIST is deactivated.
    + Optional attribute to disable the call list update. When disabled, call events will be processed and the list wouldn't be updated accordingly. +

    + Possible values: 0 => FB_CALLLIST is activated, 1 => FB_CALLLIST is deactivated.
    Default Value is 0 (activated)

  • disabledForIntervals HH:MM-HH:MM HH:MM-HH-MM...
  • - Optional attribute to disable the call list update during a specific time interval. The attribute contains a space separated list of HH:MM tupels. + Optional attribute to disable the call list update during a specific time interval. The attribute contains a space separated list of HH:MM tupels. If the current time is between the two time specifications, the callist will be disabled and no longer updated. Instead of HH:MM you can also specify HH or HH:MM:SS.

    To specify an interval spawning midnight, you have to specify two intervals, e.g.: @@ -1023,6 +1053,16 @@ sub FB_CALLLIST_returnTableHeader($)

    Default Value: empty (all internal numbers should be used, no exclusions and no mapping is performed)

    +
  • external-mapping <hash>
  • + Defines a custom mapping of external connection values (reading: external_connection) to custom values. The mapping is performed in a hash table.

    + e.g.
    +
    + The mapped name will be displayed in the table instead of the original value from FB_CALLMONITOR. +

    + Default Value: empty (no mapping is performed) +

  • connection-mapping <hash>
  • Defines a custom mapping of connection names to custom values. The mapping is performed in a hash table.

    e.g.
    @@ -1061,15 +1101,15 @@ sub FB_CALLLIST_returnTableHeader($) If you don't want to use icons you can deactivate them with this attribute.

    Possible values: 0 => no icons , 1 => use icons
    Default Value is 1 (use icons)

    -
  • visible-columns row,state,timestamp,name,number,internal,connection,duration
  • +
  • visible-columns row,state,timestamp,name,number,internal,external,connection,duration
  • Defines the visible columns, as well as the order in which these columns are displayed in the call list (from left to right). Not all columns must be displayed, you can select only a subset of columns which will be displayed.

    The possible values represents the corresponding column. The column "row" represents the row number within the current list.

    - Possible values: a combination of row,state,timestamp,name,number,internal,connection,duration
    - Default Value is "row,state,timestamp,name,number,internal,connection,duration" (show all columns)

    + Possible values: a combination of row,state,timestamp,name,number,internal,external,connection,duration
    + Default Value is "row,state,timestamp,name,number,internal,external,connection,duration" (show all columns)

  • no-heading 0,1
  • If activated the headline with a link to the detail page of the current definition will be hidden.

    Possible values: 0 => the heading line will be shown , 1 => the heading line will not be shown
    @@ -1079,7 +1119,7 @@ sub FB_CALLLIST_returnTableHeader($) Generated Events:

    =end html @@ -1144,8 +1184,8 @@ sub FB_CALLLIST_returnTableHeader($)
  • do_not_notify
  • readingFnAttributes

  • disable
  • - Optionales Attribut zur Deaktivierung der Anrufliste. Es werden dann keine Anruf-Events mehr verarbeitet und die Liste nicht weiter aktualisiert. -

    + Optionales Attribut zur Deaktivierung der Anrufliste. Es werden dann keine Anruf-Events mehr verarbeitet und die Liste nicht weiter aktualisiert. +

    Mögliche Werte: 0 => Anrufliste ist aktiv, 1 => Anrufliste ist deaktiviert.
    Standardwert ist 0 (aktiv)

  • disableForIntervals
  • @@ -1195,6 +1235,16 @@ sub FB_CALLLIST_returnTableHeader($) Standardwert ist nicht gesetzt (alle internen Rufnummern werden angezeigt)

    +
  • external-mapping <hash>
  • + Definiert eine eigene Zuordnung der externen Anschlussbezeichnung (Reading: external_connection) zu eigenen Bezeichnungen. Die Zuordnung erfolgt über eine Hash-Struktur.

    + z.B.
    +
    + Die jeweils zugeordnete Bezeichnung wird in der Anrufliste dann entsprechend angezeigt anstatt des originalen Werten von FB_CALLMONITOR. +

    + Standardwert ist nicht gesetzt (Keine Zuordnung, es werden die Originalwerte verwendet) +

  • connection-mapping <hash>
  • Definiert eine eigene Zuordnung der Endgeräte (Reading: internal_connection) zu eigenen Bezeichnungen. Die Zuordnung erfolgt über eine Hash-Struktur.

    z.B.
    @@ -1228,7 +1278,7 @@ sub FB_CALLLIST_returnTableHeader($) Im Normalfall wird der Status eines jeden Anrufs mit einem Icon angezeigt. Dazu muss das fhemSVG Icon-Set im iconpath-Attribut der entsprechenden FHEMWEB Instanz konfiguriert sein. Sollte man keine Icons wünschen, so kann man diese hiermit abschalten. Der Status wird dann mittels Textzeichen dargestellt.

    Mögliche Werte: 0 => keine Icons , 1 => benutze Icons
    Standardwert ist 1 (benutze Icons)

    -
  • visible-columns row,state,timestamp,name,number,internal,connection,duration
  • +
  • visible-columns row,state,timestamp,name,number,internal,external,connection,duration
  • Legt fest, welche Spalten in welcher Reihenfolge (von links nach rechts) in der Anrufliste angezeigt werden sollen. Es müssen nicht alle verfügbaren Spalten angezeigt werden. Es kann auch eine Auswahl von einzelnen Spalten angezeigt werden. @@ -1236,8 +1286,8 @@ sub FB_CALLLIST_returnTableHeader($) Die möglichen Werte repräsentieren die jeweilige Spalte. Der Wert "row" steht für die Zeilennummer innerhalb der Liste.

    - Mögliche Werte: Eine Kombination der folgenden Werte in der gewünschten Reihenfolge: row,state,timestamp,name,number,internal,connection,duration
    - Standardwert ist "row,state,timestamp,name,number,internal,connection,duration" (Anzeige aller Spalten)

    + Mögliche Werte: Eine Kombination der folgenden Werte in der gewünschten Reihenfolge: row,state,timestamp,name,number,internal,external,connection,duration
    + Standardwert ist "row,state,timestamp,name,number,internal,external,connection,duration" (Anzeige aller Spalten)

  • no-heading 0,1
  • Sofern aktiviert, wird die Überschriftenzeile ausserhalb der Liste inkl. Link auf die Detail-Seite der aktuellen Definition ausgeblendet.

    Mögliche Werte: 0 => Überschriftenzeile wird angezeigt , 1 => Überschriftenzeile wird ausgeblendet
    @@ -1247,7 +1297,7 @@ sub FB_CALLLIST_returnTableHeader($) Generierte Events:

    =end html_DE