From fbbc44c6c21e164942d8c958a9e45a22245f9b79 Mon Sep 17 00:00:00 2001 From: markusbloch <> Date: Thu, 13 Dec 2018 12:23:17 +0000 Subject: [PATCH] FB_CALLLIST: new readings/events implemented to count different call types (incoming, outgoing, missed, etc.) git-svn-id: https://svn.fhem.de/fhem/trunk@17968 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 2 + fhem/FHEM/72_FB_CALLLIST.pm | 77 +++++++++++++++++++++++++------------ 2 files changed, 54 insertions(+), 25 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 0c55510ff..f21a676b5 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: 72_FB_CALLLIST: new readings/events "count-..." implemented to + count different call types - change: 72_FB_CALLMONITOR: removed klicktel.de for reverse search, as the service is not available anymore - bugfix: 49_SSCam: fix in autocreateCams and take snapshot diff --git a/fhem/FHEM/72_FB_CALLLIST.pm b/fhem/FHEM/72_FB_CALLLIST.pm index 03a27d91d..8f6599404 100755 --- a/fhem/FHEM/72_FB_CALLLIST.pm +++ b/fhem/FHEM/72_FB_CALLLIST.pm @@ -231,21 +231,9 @@ sub FB_CALLLIST_Set($@) { delete($hash->{helper}{DATA}); - if(AttrVal($name, "create-readings", "0") eq "1") - { - readingsBeginUpdate($hash); - - readingsBulkUpdate($hash, "numberOfCalls", 0, 1); - - for my $reading (grep { /^\d+-/ } keys %{$hash->{READINGS}}) - { - readingsBulkUpdate($hash, $reading, ""); - readingsDelete($hash, $reading); - } - - readingsEndUpdate($hash, 1); - } - + # update readings if neccessary + FB_CALLLIST_createReadings($hash); + # Inform all FHEMWEB clients FB_CALLLIST_updateFhemWebClients($hash); @@ -480,14 +468,14 @@ sub FB_CALLLIST_Notify($$) Log3 $name, 5, "FB_CALLLIST ($name) - processed connect event for call id $call_id"; } - if($event eq "disconnect" ) + if($event eq "disconnect") { $data->{call_duration} = ReadingsVal($fb, "call_duration", undef); $data->{finished} = gettimeofday(); if($data->{last_event} =~ /^call|ring$/) { - $data->{missed_call} = 1; + $data->{missed_call} = 1; } delete($data->{running_call}); @@ -510,8 +498,6 @@ sub FB_CALLLIST_Notify($$) # Update readings FB_CALLLIST_createReadings($hash); - - } ############################################################################################################ @@ -919,7 +905,6 @@ sub FB_CALLLIST_list2html($) $ret .= ""; } - $ret .= ""; $ret .= '
'; # div tag to support inform updates $ret .= ''; @@ -990,8 +975,27 @@ sub FB_CALLLIST_createReadings($) FB_CALLLIST_createReadingsForItem($hash, $line); } } - + readingsBulkUpdate($hash, "numberOfCalls", scalar @item_list, 1); + + my %counters = ("all" => 0, "incoming" => 0, "outgoing" => 0, "missed-calls" => 0, "active" => 0, "completed" => 0 ); + + foreach my $line (@item_list) + { + my $item = $hash->{helper}{DATA}{$line->{"index"}}; + + $counters{"all"}++; + $counters{"incoming"}++ if($item->{direction} eq "incoming"); + $counters{"outgoing"}++ if($item->{direction} eq "outgoing"); + $counters{"missed-calls"}++ if($item->{"missed_call"}); + $counters{"active"}++ if($item->{running_call}); + $counters{"completed"}++ unless($item->{running_call}); + } + + foreach my $counter (keys(%counters)) + { + readingsBulkUpdate($hash, "count-$counter", $counters{$counter}); + } # delete old readings my @delete_readings; @@ -999,7 +1003,7 @@ sub FB_CALLLIST_createReadings($) for my $reading (grep { /^(\d+)-/ and ($1 > @item_list) } keys %{$hash->{READINGS}}) { readingsBulkUpdate($hash, $reading, ""); - readingsDelete($hash, $_) ; + readingsDelete($hash, $reading) ; } readingsEndUpdate($hash, 1); @@ -1216,7 +1220,6 @@ sub FB_CALLLIST_createReadingsForItem($$) $line_tmp{state} = FB_CALLLIST_returnCallState($hash, $line->{index}, 0); - foreach my $col (@order) { readingsBulkUpdate($hash, $line_tmp{line}."-$col", $line_tmp{$col}) if($line->{$col}); @@ -1678,7 +1681,19 @@ sub FB_CALLLIST_strftime(@) Generated Events:

=end html @@ -1950,7 +1965,19 @@ sub FB_CALLLIST_strftime(@) Generierte Events:

=end html_DE