From e171b6fa42dbda82fab2274ed9d2951a946ae68d Mon Sep 17 00:00:00 2001 From: pahenning Date: Sun, 1 May 2016 19:07:59 +0000 Subject: [PATCH] DoorPi.pm: Bugfix git-svn-id: https://svn.fhem.de/fhem/trunk@11364 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/contrib/DoorPi/70_DoorPi.pm | 109 ++++++++++++++++++++----------- 1 file changed, 72 insertions(+), 37 deletions(-) diff --git a/fhem/contrib/DoorPi/70_DoorPi.pm b/fhem/contrib/DoorPi/70_DoorPi.pm index 855849ac9..d2a599c8b 100644 --- a/fhem/contrib/DoorPi/70_DoorPi.pm +++ b/fhem/contrib/DoorPi/70_DoorPi.pm @@ -6,7 +6,7 @@ # # Prof. Dr. Peter A. Henning, 2016 # -# Version 0.4 - April 2016 +# $Id: 70_DoorPi.pm 2016-05 - pahenning $ # ######################################################################################## # @@ -37,8 +37,10 @@ use JSON; # imports encode_json, decode_json, to_json and from_json. use vars qw{%attr %defs}; sub Log($$); +#sub DoorPi_GetConfig($); #-- globals on start +my $version = 1.0beta1"; #-- these we may get on request my %gets = ( @@ -73,7 +75,7 @@ sub DoorPi_Initialize ($) { $readingFnAttributes; $hash->{FW_detailFn} = "DoorPi_makeTable"; - $hash->{FW_summaryFn} = "DoorPi_makeTable"; + $hash->{FW_summaryFn} = "DoorPi_makeShort"; $hash->{FW_atPageEnd} = 1; } @@ -306,7 +308,7 @@ sub DoorPi_Set ($@) { # ####################################################################################### -sub DoorPi_GetConfig () { +sub DoorPi_GetConfig { my ($hash,$err,$status) = @_; my $name = $hash->{NAME}; my $url; @@ -378,7 +380,7 @@ sub DoorPi_GetConfig () { # ####################################################################################### -sub DoorPi_GetHistory () { +sub DoorPi_GetHistory { my ($hash,$err1,$status1,$err2,$status2) = @_; my $name = $hash->{NAME}; my $url; @@ -512,11 +514,11 @@ sub DoorPi_GetHistory () { my $record = $callrecord; $record =~ s/^.*records\///; #-- workaround for buggy DoorPi - $record = sprintf("%d-%02d-%2d_%02d-%02d-%02d.wav", $year,($month+1),$day,$hour, $min, $sec) + $record = sprintf("%d-%02d-%02d_%02d-%02d-%02d.wav", $year,($month+1),$day,$hour, $min, $sec) if( $callend eq "ok"); #-- this is the snapshot file if taken at the same time - my $snapshot = sprintf("%d-%02d-%2d_%02d-%02d-%02d.jpg", $year,($month+1),$day,$hour, $min, $sec); + my $snapshot = sprintf("%d-%02d-%02d_%02d-%02d-%02d.jpg", $year,($month+1),$day,$hour, $min, $sec); #-- check if it is present in the list of snapshots my $found = 0; for( my $i=0; $i<@history_snapshot; $i++){ @@ -533,7 +535,7 @@ sub DoorPi_GetHistory () { $wday = ("So", "Mo", "Di", "Mi", "Do", "Fr", "Sa")[$wday]; #-- this is the snapshot file if taken at the same time - $snapshot = sprintf("%d-%02d-%2d_%02d-%02d-%02d.jpg", $year,($month+1),$day,$hour, $min, $sec); + $snapshot = sprintf("%d-%02d-%02d_%02d-%02d-%02d.jpg", $year,($month+1),$day,$hour, $min, $sec); #-- check if it is present in the list of snapshots $found = 0; for( my $i=0; $i<@history_snapshot; $i++){ @@ -594,13 +596,13 @@ sub DoorPi_GetHistory () { # # DoorPi_Cmd - Write command to DoorPi. # acts as callable program DoorPi_Cmd($hash,$cmd) -# and as callback program DoorPi_GetHistory($hash,$cmd,$err,$data) +# and as callback program DoorPi_GetHistory($hash,$cmd,$err,$data) # # Parameter hash, cmd = command # ######################################################################################## - sub DoorPi_Cmd () { + sub DoorPi_Cmd { my ($hash, $cmd, $err, $data) = @_; my $name = $hash->{NAME}; @@ -645,41 +647,23 @@ sub DoorPi_GetHistory () { return undef; } - - ####################################################################################### # -# DoorPi_maketable +# DoorPi_makeShort # -# FW_detailFn & FW_summaryFn handler for creating the html output in FHEMWEB +# FW_summaryFn handler for creating the html output in FHEMWEB # ####################################################################################### -sub DoorPi_makeTable($$$$){ +sub DoorPi_makeShort($$$$){ my ($FW_wname, $devname, $room, $extPage) = @_; my $hash = $defs{$devname}; - return DoorPi_list2html($hash) -} - -####################################################################################### -# -# DoorPi_list2html creating the call list as html string or json array -# -####################################################################################### - -sub DoorPi_list2html($;$){ - my ($hash, $to_json) = @_; - return undef if( !$hash ); my $name = $hash->{NAME}; my $wwwpath = $hash->{HELPER}->{wwwpath}; my $alias = AttrVal($hash->{NAME}, "alias", $hash->{NAME}); my ($state,$timestamp,$number,$result,$duration,$snapshot,$record,$nrecord); - my $td_style = 'style="padding-left:6px;padding-right:6px;"'; - my @json_output = (); - my $line; - my $old_locale = setlocale(LC_ALL); if(AttrVal($name, "language", "en") eq "de"){ @@ -688,7 +672,58 @@ sub DoorPi_list2html($;$){ setlocale(LC_ALL, "en_US.utf8"); } - my $ret .= ""; + my $ret = ""; + + if(AttrVal($name, "no-heading", "0") eq "0" and defined($FW_ME) and defined($FW_subdir)) + { + #$ret .= '
'; + $ret .= '
'.$alias.''.(IsDisabled($name) ? ' (disabled)' : '').'
'; + } + + + if(AttrVal($name, "language", "en") eq "de"){ + $ret .= "
".int(@{ $hash->{DATA}})." Einträge"; + }else{ + $ret .= "".int(@{ $hash->{DATA}})." calls"; + } + + $ret .= "open"; + + setlocale(LC_ALL, $old_locale); + + return ($ret); +} + +####################################################################################### +# +# DoorPi_makeTable +# +# FW_detailFn handler for creating the html output in FHEMWEB +# +####################################################################################### + +sub DoorPi_makeTable($$$$){ + my ($FW_wname, $devname, $room, $extPage) = @_; + my $hash = $defs{$devname}; + + my $name = $hash->{NAME}; + my $wwwpath = $hash->{HELPER}->{wwwpath}; + my $alias = AttrVal($hash->{NAME}, "alias", $hash->{NAME}); + my ($state,$timestamp,$number,$result,$duration,$snapshot,$record,$nrecord); + + my $td_style = 'style="padding-left:6px;padding-right:6px;"'; + #my @json_output = (); + #my $line; + + my $old_locale = setlocale(LC_ALL); + + if(AttrVal($name, "language", "en") eq "de"){ + setlocale(LC_ALL, "de_DE.utf8"); + }else{ + setlocale(LC_ALL, "en_US.utf8"); + } + + my $ret = ""; if(AttrVal($name, "no-heading", "0") eq "0" and defined($FW_ME) and defined($FW_subdir)) { @@ -698,11 +733,11 @@ sub DoorPi_list2html($;$){ $ret .= ''; } - $ret .= "
"; + $ret .= "
"; #-- div tag to support inform updates $ret .= '
'; if( exists($hash->{DATA}) && (int(@{$hash->{DATA}}) > 0) ){ - $ret .= ''; + $ret .= '
'; if(AttrVal($name, "language", "en") eq "de"){ $state = "Wer"; @@ -719,7 +754,7 @@ sub DoorPi_list2html($;$){ $duration = "Duration"; $record = "Recording"; } - $ret .= ''; + $ret .= ''; $ret .= ''; $ret .= ''; $ret .= ''; @@ -754,7 +789,7 @@ sub DoorPi_list2html($;$){ $state = ''; } - $ret .= ''; + $ret .= ''; $ret .= ''; $ret .= ''; $ret .= ''; @@ -766,9 +801,9 @@ sub DoorPi_list2html($;$){ $ret .= "
'.$state.''.$timestamp.''.$number.'
'.$state.''.$timestamp.''.$number.'
"; }else{ if(AttrVal($name, "language", "en") eq "de"){ - $ret .= "leer"; + $ret .= "
Rufliste leer"; }else{ - $ret .= "empty"; + $ret .= "Calllist empty"; } }