FB_CALLLIST: minor code optimization

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@15886 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
markusbloch 2018-01-14 14:25:28 +00:00
parent 58e73d22ca
commit cc14812b6c

View File

@ -346,11 +346,14 @@ sub FB_CALLLIST_Notify($$)
} }
} }
if(grep(m/^(?:INITIALIZED|REREADCFG)$/, @{$events}))
{
Log3 $name, 2, "FB_CALLLIST ($name) - WARNING - the selected device $callmonitor does not exist" unless(IsDevice($callmonitor));
Log3 $name, 2, "FB_CALLLIST ($name) - WARNING - selected device $callmonitor ist not of type FB_CALLMONITOR" if(IsDevice($callmonitor) and !IsDevice($callmonitor,"FB_CALLMONITOR"));
}
if(grep(m/^(?:ATTR $name .*|DELETEATTR $name.*|INITIALIZED|REREADCFG)$/, @{$events})) if(grep(m/^(?:ATTR $name .*|DELETEATTR $name.*|INITIALIZED|REREADCFG)$/, @{$events}))
{ {
Log3 $name, 3, "FB_CALLLIST ($name) - WARNING - the selected device $callmonitor does not exist" unless(IsDevice($callmonitor));
Log3 $name, 3, "FB_CALLLIST ($name) - WARNING - selected device $callmonitor ist not of type FB_CALLMONITOR" if(IsDevice($callmonitor) and !IsDevice($callmonitor,"FB_CALLMONITOR"));
# delete all outdated calls according to attribute list-type, internal-number-filter and number-of-calls # delete all outdated calls according to attribute list-type, internal-number-filter and number-of-calls
FB_CALLLIST_cleanupList($hash); FB_CALLLIST_cleanupList($hash);
@ -358,7 +361,7 @@ sub FB_CALLLIST_Notify($$)
{ {
# Inform all FHEMWEB clients # Inform all FHEMWEB clients
FB_CALLLIST_updateFhemWebClients($hash); FB_CALLLIST_updateFhemWebClients($hash);
# Update readings # Update readings
FB_CALLLIST_createReadings($hash); FB_CALLLIST_createReadings($hash);
} }
@ -738,8 +741,7 @@ sub FB_CALLLIST_returnCallState($$;$)
if($data->{direction} eq "incoming" and ((not exists($data->{internal_connection}) ) or (exists($data->{internal_connection}) and not $data->{internal_connection} =~ /Answering_Machine/))) if($data->{direction} eq "incoming" and ((not exists($data->{internal_connection}) ) or (exists($data->{internal_connection}) and not $data->{internal_connection} =~ /Answering_Machine/)))
{ {
$state = "=>".($data->{missed_call} ? " X" : ""); $state = "=>".($data->{missed_call} ? " X" : "");
$state = FB_CALLLIST_returnIcon($hash, "incoming.done", $state) if($icons and not $data->{missed_call}); $state = FB_CALLLIST_returnIcon($hash, "incoming.".($data->{missed_call} ? "missed" : "done"), $state) if($icons);
$state = FB_CALLLIST_returnIcon($hash, "incoming.missed", $state) if($icons and $data->{missed_call});
} }
elsif($data->{direction} eq "incoming" and exists($data->{internal_connection}) and $data->{internal_connection} =~ /^Answering_Machine/) elsif($data->{direction} eq "incoming" and exists($data->{internal_connection}) and $data->{internal_connection} =~ /^Answering_Machine/)
{ {
@ -749,8 +751,7 @@ sub FB_CALLLIST_returnCallState($$;$)
elsif($data->{direction} eq "outgoing") elsif($data->{direction} eq "outgoing")
{ {
$state = "<=".($data->{missed_call} ? " X" : ""); $state = "<=".($data->{missed_call} ? " X" : "");
$state = FB_CALLLIST_returnIcon($hash, "outgoing.done", $state) if($icons and not $data->{missed_call}); $state = FB_CALLLIST_returnIcon($hash, "outgoing.".($data->{missed_call} ? "missed" : "done"), $state) if($icons);
$state = FB_CALLLIST_returnIcon($hash, "outgoing.missed", $state) if($icons and $data->{missed_call});
} }
} }
@ -801,9 +802,9 @@ sub FB_CALLLIST_index2line($$)
{ {
my $data = \%{$hash->{helper}{DATA}{$index}}; my $data = \%{$hash->{helper}{DATA}{$index}};
my $count = FB_CALLLIST_getItemLineNumberFromIndex($hash,$index); my $count = FB_CALLLIST_getItemLineNumberFromIndex($hash,$index);
return undef unless(defined($count)); # call should not be displayed return undef unless(defined($count)); # call should not be displayed
my $old_locale = setlocale(LC_ALL); my $old_locale = setlocale(LC_ALL);
if(AttrVal($name, "language", "en") eq "de") if(AttrVal($name, "language", "en") eq "de")
@ -827,9 +828,9 @@ sub FB_CALLLIST_index2line($$)
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} ) : "-"), 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} ) : "-"),
duration => FB_CALLLIST_formatDuration($hash, $index) duration => FB_CALLLIST_formatDuration($hash, $index)
}; };
setlocale(LC_ALL, $old_locale); setlocale(LC_ALL, $old_locale);
return $line; return $line;
} }
@ -903,7 +904,7 @@ sub FB_CALLLIST_list2html($)
my $td_style = 'style="padding-left:6px;padding-right:6px;"'; my $td_style = 'style="padding-left:6px;padding-right:6px;"';
my $line; my $line;
my $ret .= "<table>"; my $ret .= "<table>";
@ -956,7 +957,7 @@ sub FB_CALLLIST_list2html($)
##################################### #####################################
# creating the call list as json array # generate all readings for the call list
sub FB_CALLLIST_createReadings($) sub FB_CALLLIST_createReadings($)
{ {
my ($hash) = @_; my ($hash) = @_;
@ -967,7 +968,7 @@ sub FB_CALLLIST_createReadings($)
my $create_readings = AttrVal($hash->{NAME}, "create-readings","0"); my $create_readings = AttrVal($hash->{NAME}, "create-readings","0");
return undef unless($create_readings); return undef unless($create_readings);
my @item_list = FB_CALLLIST_getAllItemLines($hash); my @item_list = FB_CALLLIST_getAllItemLines($hash);
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
@ -994,7 +995,7 @@ sub FB_CALLLIST_createReadings($)
readingsEndUpdate($hash, 1); readingsEndUpdate($hash, 1);
map { CommandDeleteReading(undef, "$name $_") } @delete_readings; map { CommandDeleteReading(undef, "$name $_") } @delete_readings;
return undef; return undef;
} }
@ -1244,11 +1245,11 @@ sub FB_CALLLIST_checkForInternalNumberFilter($$)
sub FB_CALLLIST_deleteItem($;$) sub FB_CALLLIST_deleteItem($;$)
{ {
my ($hash, $index) = @_; my ($hash, $index) = @_;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
delete($hash->{helper}{DATA}{$index}) if($index); delete($hash->{helper}{DATA}{$index}) if($index);
if(FB_CALLLIST_createOrderedIndexList($hash)) if(FB_CALLLIST_createOrderedIndexList($hash))
{ {
FW_directNotify($name, "{\"action\":\"delete\",\"index\":\"$index\"}", 1) if(defined($FW_ME) and $index); FW_directNotify($name, "{\"action\":\"delete\",\"index\":\"$index\"}", 1) if(defined($FW_ME) and $index);
@ -1310,9 +1311,9 @@ sub FB_CALLLIST_updateOneItemInFHEMWEB($$)
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $line = FB_CALLLIST_index2line($hash,$index); my $line = FB_CALLLIST_index2line($hash,$index);
return undef unless($line); # abort if call should not be displayed (e.g. attr list-type = "completed") return undef unless($line); # abort if call should not be displayed (e.g. attr list-type = "completed")
my $json = FB_CALLLIST_returnOrderedJSONOutput($hash, $line); my $json = FB_CALLLIST_returnOrderedJSONOutput($hash, $line);
FW_directNotify($name, "{\"action\":\"update\",\"index\":\"$index\",\"order\":\"".AttrVal($name, "list-order","descending")."\",\"item\":$json}", 1); FW_directNotify($name, "{\"action\":\"update\",\"index\":\"$index\",\"order\":\"".AttrVal($name, "list-order","descending")."\",\"item\":$json}", 1);