fixing not correct working AttrFn

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@2911 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
markusbloch 2013-03-13 23:10:19 +00:00
parent f9c1e19b2d
commit df5f845abf

View File

@ -122,13 +122,6 @@ FB_CALLMONITOR_Define($$)
my $ret = DevIo_OpenDev($hash, 0, "FB_CALLMONITOR_DoInit"); my $ret = DevIo_OpenDev($hash, 0, "FB_CALLMONITOR_DoInit");
if(-r "/var/flash/phonebook")
{
$attr{$name}{"reverse-search"} = "internal" unless(defined($attr{$name}{"reverse-search"}));
FB_CALLMONITOR_loadInternalPhonebookFile($hash);
}
return $ret; return $ret;
} }
@ -326,17 +319,22 @@ FB_CALLMONITOR_Attr($@)
my (@a) = @_; my (@a) = @_;
my $hash = $defs{$a[1]}; my $hash = $defs{$a[1]};
my $name = $hash->{NAME};
if($a[0] eq "set") if($a[0] eq "set")
{ {
if($a[2] eq "reverse-search" or $a[2] eq "reverse-search-phonebook-file") if($a[2] eq "reverse-search" or $a[2] eq "reverse-search-phonebook-file")
{ {
$attr{$name}{"reverse-search-phonebook-file"} = $a[3] if($a[2] eq "reverse-search-phonebook-file");
FB_CALLMONITOR_loadInternalPhonebookFile($hash); FB_CALLMONITOR_loadInternalPhonebookFile($hash);
} }
if($a[2] eq "reverse-search-cache-file") if($a[2] eq "reverse-search-cache-file")
{ {
$attr{$name}{"reverse-search-cache-file"} = $a[3];
FB_CALLMONITOR_loadCacheFile($hash); FB_CALLMONITOR_loadCacheFile($hash);
} }
@ -538,10 +536,10 @@ sub FB_CALLMONITOR_writeToCache($$$)
} }
sub FB_CALLMONITOR_loadInternalPhonebookFile($) sub FB_CALLMONITOR_loadInternalPhonebookFile($@)
{ {
my ($hash) = @_; my ($hash, $overwrite) = @_;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $phonebook = undef; my $phonebook = undef;
my $contact; my $contact;
@ -552,10 +550,18 @@ sub FB_CALLMONITOR_loadInternalPhonebookFile($)
my $area_code = AttrVal($name, "local-area-code", ""); my $area_code = AttrVal($name, "local-area-code", "");
my $phonebook_file = AttrVal($name, "reverse-search-phonebook-file", "/var/flash/phonebook"); my $phonebook_file = AttrVal($name, "reverse-search-phonebook-file", "/var/flash/phonebook");
delete $hash->{helper}{PHONEBOOK} if(defined($hash->{helper}{PHONEBOOK})); $overwrite = 1 unless(defined($overwrite));
return if($overwrite == 0 and defined($hash->{helper}{PHONEBOOK}));
if(-r $phonebook_file) if(-r $phonebook_file)
{ {
delete $hash->{helper}{PHONEBOOK} if(defined($hash->{helper}{PHONEBOOK}));
if(open(PHONEBOOK, "<$phonebook_file")) if(open(PHONEBOOK, "<$phonebook_file"))
{ {
@ -622,9 +628,12 @@ sub FB_CALLMONITOR_loadInternalPhonebookFile($)
sub FB_CALLMONITOR_loadCacheFile($) sub FB_CALLMONITOR_loadCacheFile($)
{ {
my ($hash) = @_; my ($hash) = @_;
my $file = AttrVal($hash->{NAME}, "reverse-search-cache-file", ""); my $file = AttrVal($hash->{NAME}, "reverse-search-cache-file", "");
my @cachefile; my @cachefile;
my @tmpline; my @tmpline;
my $count_contacts;
my $name = $hash->{NAME};
$file =~ s/(^\s+|\s+$)//g; $file =~ s/(^\s+|\s+$)//g;
@ -653,6 +662,9 @@ sub FB_CALLMONITOR_loadCacheFile($)
} }
} }
} }
$count_contacts = scalar keys %{$hash->{helper}{CACHE}};
Log GetLogLevel($name, 2), "FB_CALLMONITOR: $name read ".($count_contacts > 0 ? $count_contacts : "no")." contact".($count_contacts == 1 ? "" : "s")." from Cache";
} }
else else
{ {