From bec4b536b650002d55e37b0e64077a95267f7a02 Mon Sep 17 00:00:00 2001 From: markusbloch <> Date: Mon, 9 Apr 2018 21:09:25 +0000 Subject: [PATCH] FB_CALLMONITOR: fix not working get command showPhonebookEntries (Forum: #86706) git-svn-id: https://svn.fhem.de/fhem/trunk@16579 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 2 + fhem/FHEM/72_FB_CALLMONITOR.pm | 84 +++++++++++++++++++++++++--------- 2 files changed, 65 insertions(+), 21 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 1bf5b41f5..723d0ce3b 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. + - bugfix: 72_FB_CALLMONITOR: fix not working get command + showPhonebookEntries for remote phonebooks - bugfix: 73_GardenaSmartBridge: add commandref parts - change: 93_DbLog: V3.10.2, event parsing of Weather changed, add option CN= to addlog-function diff --git a/fhem/FHEM/72_FB_CALLMONITOR.pm b/fhem/FHEM/72_FB_CALLMONITOR.pm index dde06f5c5..0bc0adf06 100755 --- a/fhem/FHEM/72_FB_CALLMONITOR.pm +++ b/fhem/FHEM/72_FB_CALLMONITOR.pm @@ -186,28 +186,67 @@ FB_CALLMONITOR_Get($@) return $head."\n".("-" x $width)."\n".$table; } - elsif($arguments[1] eq "showPhonebookEntries" and exists($hash->{helper}{PHONEBOOK})) + elsif($arguments[1] eq "showPhonebookEntries" and (exists($hash->{helper}{PHONEBOOK}) or exists($hash->{helper}{PHONEBOOKS})) and int(@arguments) <= 3) { - my $table = ""; + return "given argument is not a valid phonebook id: ".$arguments[2] if(int(@arguments) == 3 and ($arguments[2] !~ /^\d+$/ or !exists($hash->{helper}{PHONEBOOKS}{$arguments[2]}) ) ); + + my $return = ""; + + if(exists($hash->{helper}{PHONEBOOKS})) + { + foreach my $pb_id (sort keys %{$hash->{helper}{PHONEBOOKS}}) + { + next if(int(@arguments) == 3 and int($arguments[2]) != $pb_id); + + my $number_width = 0; + my $name_width = 0; + my $table = ""; + + if(defined($hash->{helper}{PHONEBOOKS}{$pb_id}) and scalar(keys(%{$hash->{helper}{PHONEBOOKS}{$pb_id}})) > 0) + { + foreach my $number (keys %{$hash->{helper}{PHONEBOOKS}{$pb_id}}) + { + $number_width = length($number) if($number_width < length($number)); + $name_width = length($hash->{helper}{PHONEBOOKS}{$pb_id}{$number}) if($name_width < length($hash->{helper}{PHONEBOOKS}{$pb_id}{$number})); + } + + my $head = "Phonebook: ".$hash->{helper}{PHONEBOOK_NAMES}{$pb_id}." / Id: $pb_id\n\n ".sprintf("%-".$number_width."s %s" ,"Number", "Name"); + + foreach my $number (sort { lc($hash->{helper}{PHONEBOOKS}{$pb_id}{$a}) cmp lc($hash->{helper}{PHONEBOOKS}{$pb_id}{$b}) } keys %{$hash->{helper}{PHONEBOOKS}{$pb_id}}) + { + my $string = sprintf(" %-".$number_width."s - %s" , $number,$hash->{helper}{PHONEBOOKS}{$pb_id}{$number}); + $table .= $string."\n"; + } + + $return .= $head."\n ".("-" x ($number_width + $name_width + 3))."\n".$table."\n"; + } + } + } - my $number_width = 0; - my $name_width = 0; - - foreach my $number (keys %{$hash->{helper}{PHONEBOOK}}) - { - $number_width = length($number) if($number_width < length($number)); - $name_width = length($hash->{helper}{PHONEBOOK}{$number}) if($name_width < length($hash->{helper}{PHONEBOOK}{$number})); + if(exists($hash->{helper}{PHONEBOOK}) and int(@arguments) == 2) + { + my $number_width = 0; + my $name_width = 0; + my $table = ""; + + foreach my $number (keys %{$hash->{helper}{PHONEBOOK}}) + { + $number_width = length($number) if($number_width < length($number)); + $name_width = length($hash->{helper}{PHONEBOOK}{$number}) if($name_width < length($hash->{helper}{PHONEBOOK}{$number})); + } + + my $head = sprintf("Phonebook file\n\n %-".$number_width."s %s" ,"Number", "Name"); + + foreach my $number (sort { lc($hash->{helper}{PHONEBOOK}{$a}) cmp lc($hash->{helper}{PHONEBOOK}{$b}) } keys %{$hash->{helper}{PHONEBOOK}}) + { + my $string = sprintf(" %-".$number_width."s - %s" , $number,$hash->{helper}{PHONEBOOK}{$number}); + $table .= $string."\n"; + } + + $return .= $head."\n ".("-" x ($number_width + $name_width + 3))."\n".$table } - my $head = sprintf("%-".$number_width."s %s" ,"Number", "Name"); - - foreach my $number (sort { lc($hash->{helper}{PHONEBOOK}{$a}) cmp lc($hash->{helper}{PHONEBOOK}{$b}) } keys %{$hash->{helper}{PHONEBOOK}}) - { - my $string = sprintf("%-".$number_width."s - %s" , $number,$hash->{helper}{PHONEBOOK}{$number}); - $table .= $string."\n"; - } - - return $head."\n".("-" x ($number_width + $name_width + 3))."\n".$table; + return $return; } elsif($arguments[1] eq "showCacheEntries" and exists($hash->{helper}{CACHE})) { @@ -257,7 +296,10 @@ FB_CALLMONITOR_Get($@) } else { - return "unknown argument ".$arguments[1].", choose one of search".(exists($hash->{helper}{PHONEBOOK_NAMES}) ? " showPhonebookIds" : "").(exists($hash->{helper}{PHONEBOOK}) ? " showPhonebookEntries" : "").(exists($hash->{helper}{CACHE}) ? " showCacheEntries" : "").(exists($hash->{helper}{TEXTFILE}) ? " showTextfileEntries" : ""); + return "unknown argument ".$arguments[1].", choose one of search".(exists($hash->{helper}{PHONEBOOK_NAMES}) ? " showPhonebookIds" : ""). + ((exists($hash->{helper}{PHONEBOOK}) or exists($hash->{helper}{PHONEBOOKS})) ? " showPhonebookEntries" : ""). + (exists($hash->{helper}{CACHE}) ? " showCacheEntries" : ""). + (exists($hash->{helper}{TEXTFILE}) ? " showTextfileEntries" : ""); } } @@ -2094,7 +2136,7 @@ sub FB_CALLMONITOR_checkNumberForDeflection($$) @@ -2249,7 +2291,7 @@ sub FB_CALLMONITOR_checkNumberForDeflection($$)