From 221f0420a19c0497545e7389d3c8328c12d9e78d Mon Sep 17 00:00:00 2001 From: markusbloch <> Date: Sun, 3 Jan 2016 14:05:48 +0000 Subject: [PATCH] FB_CALLMONITOR: several changes: - correctly processing of empty phonebooks (Forum: #46544) - continue phonebook processing even on errors (Forum: #46544) - allow phonebook names in attr fritzbox-remote-phonebook-exclude (Forum: #46544) - don't import textfile entries which have no comma (Forum: #46563) - use ForceType => "file" for textfile FileRead/FileWrite git-svn-id: https://svn.fhem.de/fhem/trunk@10348 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 4 +++ fhem/FHEM/72_FB_CALLMONITOR.pm | 54 ++++++++++++++++------------------ 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 66133764e..cb75c0907 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,9 @@ # 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. + - bugfix: FB_CALLMONITOR: empty phonebooks will be recognized correctly, + phonebook processing continues, when error occurs + - change: FB_CALLMONITOR: attr fritzbox-remote-phonebook-exclude allows + phonebook names additional to ID's - bugfix: 95_Dashboard: fixed issue when using cmdIcon attribute for devices. - feature: 71_PHILIPS_AUDIO: select presets and favorites by name. diff --git a/fhem/FHEM/72_FB_CALLMONITOR.pm b/fhem/FHEM/72_FB_CALLMONITOR.pm index da0bc007d..e29bd79dc 100755 --- a/fhem/FHEM/72_FB_CALLMONITOR.pm +++ b/fhem/FHEM/72_FB_CALLMONITOR.pm @@ -836,7 +836,7 @@ sub FB_CALLMONITOR_readPhonebook($;$) foreach my $phonebookId (sort keys %{$hash->{helper}{PHONEBOOK_NAMES}}) { - if(exists($excludedIds{$phonebookId})) + if(exists($excludedIds{$phonebookId}) or exists($excludedIds{$hash->{helper}{PHONEBOOK_NAMES}{$phonebookId}})) { Log3 $name, 4, "FB_CALLMONITOR ($name) - skipping excluded phonebook id $phonebookId (".$hash->{helper}{PHONEBOOK_NAMES}{$phonebookId}.")"; next; @@ -849,8 +849,7 @@ sub FB_CALLMONITOR_readPhonebook($;$) if(defined($err)) { - Log3 $name, 2, 'FB_CALLMONITOR ($name) - unable to retrieve phonebook "'.$hash->{helper}{PHONEBOOK_NAMES}{$phonebookId}.'" from FritzBox - '.$err; - return 'unable to retrieve phonebook "'.$hash->{helper}{PHONEBOOK_NAMES}{$phonebookId}.'" from FritzBox - $err'; + Log3 $name, 2, 'FB_CALLMONITOR ($name) - unable to retrieve phonebook "'.$hash->{helper}{PHONEBOOK_NAMES}{$phonebookId}.'" from FritzBox - '.$err; } else { @@ -859,7 +858,6 @@ sub FB_CALLMONITOR_readPhonebook($;$) if(defined($err)) { Log3 $name, 2, "FB_CALLMONITOR ($name) - could not parse remote phonebook ".$hash->{helper}{PHONEBOOK_NAMES}{$phonebookId}." - $err"; - return "could not parse remote phonebook ".$hash->{helper}{PHONEBOOK_NAMES}{$phonebookId}." - $err"; } else { @@ -922,34 +920,34 @@ sub FB_CALLMONITOR_parsePhonebook($$) my $number; my $count_contacts = 0; - if($phonebook =~ // and $phonebook =~ /,) + if($phonebook =~ // and $phonebook =~ /]+>/ and $phonebook =~ m,, and $phonebook =~ m,,) { - - while($phonebook =~ m,]*>(.+?),gs) + if($phonebook =~ // and $phonebook =~ /(.+?),) + while($phonebook =~ m,]*>(.+?),gcs) { - $contact_name = $1; - - while($contact =~ m,]*?type="([^<>"]+?)"[^<>]*?>([^<>"]+?),gs) + $contact = $1; + + if($contact =~ m,(.+?),) { - if($1 ne "intern" and $1 ne "memo") + $contact_name = $1; + + while($contact =~ m,]*?type="([^<>"]+?)"[^<>]*?>([^<>"]+?),gs) { - $number = FB_CALLMONITOR_normalizePhoneNumber($hash, $2); - - $count_contacts++; - Log3 $name, 4, "FB_CALLMONITOR ($name) - found $contact_name with number $number"; - $hash->{helper}{PHONEBOOK}{$number} = FB_CALLMONITOR_html2txt($contact_name) if(not defined($hash->{helper}{PHONEBOOK}{$number})); - undef $number; + if($1 ne "intern" and $1 ne "memo") + { + $number = FB_CALLMONITOR_normalizePhoneNumber($hash, $2); + + $count_contacts++; + Log3 $name, 4, "FB_CALLMONITOR ($name) - found $contact_name with number $number"; + $hash->{helper}{PHONEBOOK}{$number} = FB_CALLMONITOR_html2txt($contact_name) if(not defined($hash->{helper}{PHONEBOOK}{$number})); + undef $number; + } } + undef $contact_name; } - undef $contact_name; } } - - undef $phonebook; return (undef, $count_contacts); } @@ -1029,7 +1027,7 @@ sub FB_CALLMONITOR_loadTextFile($;$) Log3 $hash->{NAME}, 3, "FB_CALLMONITOR ($name) - loading textfile $file"; - ($err, @file) = FileRead($file); + ($err, @file) = FileRead({FileName => $file, ForceType => "file"}); unless(defined($err) and $err) { @@ -1038,7 +1036,7 @@ sub FB_CALLMONITOR_loadTextFile($;$) $line =~ s/#.*$//g; $line =~ s,//.*$,,g; - if(not $line =~ /^\s*$/) + if((not $line =~ /^\s*$/) and $line =~ /,/) { chomp $line; @tmpline = split(/,/, $line,2); @@ -1073,7 +1071,7 @@ sub FB_CALLMONITOR_loadTextFile($;$) "# 45678,Boss", "####" ); - $err = FileWrite($file,@tmpline); + $err = FileWrite({FileName => $file, ForceType => "file"},@tmpline); Log3 $name, 3, "FB_CALLMONITOR ($name) - unable to create textfile $file: $err" if(defined($err) and $err ne ""); } @@ -1841,7 +1839,7 @@ sub FB_CALLMONITOR_normalizePhoneNumber($$) Possible values: web,telnet,tr064
Default Value is tr064 (retrieve phonebooks via TR-064 interface)

  • fritzbox-remote-phonebook-exclude
  • - A comma separated list of phonebook id's which should be excluded when retrieving all possible phonebooks via web or tr064 method (see attribute fritzbox-remote-phonebook-via). All list possible values is provided by get command showPhonebookIds. This attribute is not applicable when using telnet method to obtain remote phonebook.

    + A comma separated list of phonebook id's or names which should be excluded when retrieving all possible phonebooks via web or tr064 method (see attribute fritzbox-remote-phonebook-via). All list possible values is provided by get command showPhonebookIds. This attribute is not applicable when using telnet method to obtain remote phonebook.

    Default Value: empty (all phonebooks should be used, no exclusions)

  • fritzbox-user
  • Use the given user for remote connect to obtain the phonebook. This attribute is only needed, if you use multiple users on your FritzBox.

    @@ -1999,7 +1997,7 @@ sub FB_CALLMONITOR_normalizePhoneNumber($$) Mögliche Werte: web,telnet,tr064
    Standardwert ist "tr064" (Abfrage aller verfügbaren Telefonbücher über die TR-064-Schnittstelle)

  • fritzbox-remote-phonebook-exclude
  • - Eine komma-separierte Liste von Telefonbuch-ID's welche beim einlesen übersprungen werden sollen. Dieses Attribut greift nur beim einlesen der Telefonbücher via "web"- oder "tr064"-Methode (siehe Attribut fritzbox-remote-phonebook-via). Eine Liste aller möglichen Werte kann über das Get-Kommando showPhonebookIds angezeigt werden.

    + Eine komma-separierte Liste von Telefonbuch-ID's oder Namen welche beim einlesen übersprungen werden sollen. Dieses Attribut greift nur beim einlesen der Telefonbücher via "web"- oder "tr064"-Methode (siehe Attribut fritzbox-remote-phonebook-via). Eine Liste aller möglichen Werte kann über das Get-Kommando showPhonebookIds angezeigt werden.

    Standardmäßig ist diese Funktion deaktiviert (alle Telefonbücher werden eingelesen)

  • fritzbox-user
  • Der Username für das Telnet-Interface, sofern das Telefonbuch direkt von der FritzBox geladen werden soll (Attribut: fritzbox-remote-phonebook). Dieses Attribut ist nur notwendig, wenn mehrere Benutzer auf der FritzBox konfiguriert sind.