From bf6c20204a10b43a88da7ddda8f5162830f238b4 Mon Sep 17 00:00:00 2001 From: pahenning <> Date: Mon, 25 Jul 2016 13:41:58 +0000 Subject: [PATCH] DoorPi.pm: Bugfix git-svn-id: https://svn.fhem.de/fhem/trunk@11851 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/contrib/DoorPi/70_DoorPi.pm | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/fhem/contrib/DoorPi/70_DoorPi.pm b/fhem/contrib/DoorPi/70_DoorPi.pm index 7d2876ffa..bfe0a7aa8 100644 --- a/fhem/contrib/DoorPi/70_DoorPi.pm +++ b/fhem/contrib/DoorPi/70_DoorPi.pm @@ -41,7 +41,7 @@ use vars qw{%attr %defs}; sub Log($$); #-- globals on start -my $version = "1.1"; +my $version = "1.2"; #-- these we may get on request my %gets = ( @@ -628,7 +628,7 @@ sub DoorPi_GetConfig { ####################################################################################### # # DoorPi_LastSnapshot - acts as callable program DoorPi_GetLastSnapshot($hash) -# and as callback program DoorPi_GetLastSnapshot($hash,$err,$status) +# and as callback program DoorPi_GetLastSnapshot($hash,$err,$status) # # Parameter hash, err, status # @@ -982,14 +982,14 @@ sub DoorPi_GetHistory { ###################################################################################### # # DoorPi_PurgeDB - acts as callable program DoorPi_PurgeDB($hash) -# and as callback program DoorPi_PurgeDB($hash,$err,$status) +# and as callback program DoorPi_PurgeDB($hash,$err,$status) # # Parameter hash, err, status # ####################################################################################### sub DoorPi_PurgeDB { - my ($hash,$err,$data) = @_; + my ($hash,$err,$status) = @_; my $name = $hash->{NAME}; my $url; @@ -997,8 +997,9 @@ sub DoorPi_PurgeDB { if ( !$hash ){ Log 1,"[DoorPi_PurgeDB] called without hash"; return undef; - }elsif ( $hash && !$err ){ + }elsif ( $hash && !$err && !$status){ $url = "http://".$hash->{TCPIP}."/status?module=history_event&name=purge&value=1.0"; + # 1,"[DoorPi_PurgeDB] called with only hash => Issue a non-blocking call to $url"; HttpUtils_NonblockingGet({ url => $url, callback => sub($$$){ DoorPi_PurgeDB($hash,$_[1],$_[2]) } @@ -1006,25 +1007,25 @@ sub DoorPi_PurgeDB { return undef; }elsif ( $hash && $err ){ Log 1,"[DoorPi_PurgeDB] has error $err"; - readingsSingleUpdate($hash,"config",$err,0); readingsSingleUpdate($hash,"state","Error",1); return; } + #Log 1,"[DoorPi_PurgeDB] has obtained data $status"; #-- test if this is valid JSON - if( !is_valid_json($data) ){ + if( !is_valid_json($status) ){ Log 1,"[DoorPi_PurgeDB] invalid data"; readingsSingleUpdate($hash,"state","Error",1); return; } my $json = JSON->new->utf8; - my $jhash = $json->decode( $data ); - my $msg = $jhash->{'message'}; - my $suc = $jhash->{'success'}; - if( $suc ){ - return $msg; + my $jhash = $json->decode( $status ); + my $suc = $jhash->{'history_event'}; + if( $suc eq "0" ){ + return "OK"; + }else{ + return undef; } - return undef; } #######################################################################################