2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-08 19:32:42 +00:00

FB_CALLLIST: fixing no reading update when list becomes empty (Forum: #52158)

git-svn-id: https://svn.fhem.de/fhem/trunk@11421 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
markusbloch 2016-05-09 20:17:15 +00:00
parent 4729bcf4ce
commit ca41d8b03a
2 changed files with 26 additions and 26 deletions

View File

@ -1,5 +1,6 @@
# 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_CALLLIST: no reading update when list becomes empty
- feature: added new module 37_plex.pm
- feature: FBAHAHTTP module as replacement for the deprecated FBAHA
- feature: 50_TelegramBot reply set command / allowedCommands as restriction

View File

@ -712,7 +712,7 @@ sub FB_CALLLIST_list2html($;$)
my $alias = AttrVal($hash->{NAME}, "alias", $hash->{NAME});
my $create_readings = AttrVal($hash->{NAME}, "create-readings","0");
my $count = 0;
my $td_style = 'style="padding-left:6px;padding-right:6px;"';
my @json_output = ();
my $line;
@ -743,10 +743,10 @@ sub FB_CALLLIST_list2html($;$)
$ret .= FB_CALLLIST_returnOrderedHTMLOutput($hash, FB_CALLLIST_returnTableHeader($hash), 'class="fbcalllist header"','') if(AttrVal($name, "no-table-header", "0") eq "0");
readingsBeginUpdate($hash) if($to_json and $create_readings eq "1");
if(exists($hash->{helper}{DATA}) and (scalar keys %{$hash->{helper}{DATA}}) > 0)
{
my $count = 0;
my @json_list;
my @list = sort { (AttrVal($name, "list-order","descending") eq "descending") ? $b <=> $a : $a <=> $b } keys %{$hash->{helper}{DATA}};
@ -761,8 +761,6 @@ sub FB_CALLLIST_list2html($;$)
@list = grep { !$hash->{helper}{DATA}{$_}{running_call} } @list;
}
readingsBeginUpdate($hash) if($to_json and $create_readings eq "1");
foreach my $index (@list)
{
$count++;
@ -796,24 +794,7 @@ sub FB_CALLLIST_list2html($;$)
push @json_output, FB_CALLLIST_returnOrderedJSONOutput($hash, $line);
$ret .= FB_CALLLIST_returnOrderedHTMLOutput($hash, $line, 'number="'.$count.'" class="fbcalllist '.($count % 2 == 1 ? "odd" : "even").'"', 'class="fbcalllist" '.$td_style);
}
if($to_json and $create_readings eq "1")
{
readingsBulkUpdate($hash, "numberOfCalls", $count, 1);
my @delete_readings;
for my $reading (grep { /^(\d+)-/ and ($1 > $count) } keys %{$hash->{READINGS}})
{
readingsBulkUpdate($hash, $reading, "");
push @delete_readings, $reading;
}
readingsEndUpdate($hash, 1) if($to_json and $create_readings eq "1");
map { delete($hash->{READINGS}{$_}) } @delete_readings;
}
}
}
else
{
@ -838,7 +819,25 @@ sub FB_CALLLIST_list2html($;$)
$ret .= "</td></tr></table>";
setlocale(LC_ALL, $old_locale);
return ($to_json ? @json_output : $ret);
# delete old readings
if($to_json and $create_readings eq "1")
{
readingsBulkUpdate($hash, "numberOfCalls", $count, 1);
my @delete_readings;
for my $reading (grep { /^(\d+)-/ and ($1 > $count) } keys %{$hash->{READINGS}})
{
readingsBulkUpdate($hash, $reading, "");
push @delete_readings, $reading;
}
readingsEndUpdate($hash, 1) if($to_json and $create_readings eq "1");
map { delete($hash->{READINGS}{$_}) } @delete_readings;
}
return ($to_json ? @json_output : $ret);
}
#####################################
@ -1074,13 +1073,13 @@ sub FB_CALLLIST_updateFhemWebClients($)
return undef unless($init_done);
if(exists($hash->{helper}{DATA}) and (scalar keys %{$hash->{helper}{DATA}}) > 0)
if(my @list = FB_CALLLIST_list2html($hash, 1))
{
Log3 $name, 5, "FB_CALLLIST ($name) - inform all FHEMWEB clients";
# inform all FHEMWEB clients about changes
my $count = 0;
foreach my $line (FB_CALLLIST_list2html($hash, 1))
foreach my $line (@list)
{
FW_directNotify($name, $line, 1);
$count++;