DoorPi.pm: Bugfix

git-svn-id: https://svn.fhem.de/fhem/trunk@11851 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
pahenning 2016-07-25 13:41:58 +00:00
parent 2beee79832
commit bf6c20204a

View File

@ -41,7 +41,7 @@ use vars qw{%attr %defs};
sub Log($$); sub Log($$);
#-- globals on start #-- globals on start
my $version = "1.1"; my $version = "1.2";
#-- these we may get on request #-- these we may get on request
my %gets = ( my %gets = (
@ -989,7 +989,7 @@ sub DoorPi_GetHistory {
####################################################################################### #######################################################################################
sub DoorPi_PurgeDB { sub DoorPi_PurgeDB {
my ($hash,$err,$data) = @_; my ($hash,$err,$status) = @_;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $url; my $url;
@ -997,8 +997,9 @@ sub DoorPi_PurgeDB {
if ( !$hash ){ if ( !$hash ){
Log 1,"[DoorPi_PurgeDB] called without hash"; Log 1,"[DoorPi_PurgeDB] called without hash";
return undef; return undef;
}elsif ( $hash && !$err ){ }elsif ( $hash && !$err && !$status){
$url = "http://".$hash->{TCPIP}."/status?module=history_event&name=purge&value=1.0"; $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({ HttpUtils_NonblockingGet({
url => $url, url => $url,
callback => sub($$$){ DoorPi_PurgeDB($hash,$_[1],$_[2]) } callback => sub($$$){ DoorPi_PurgeDB($hash,$_[1],$_[2]) }
@ -1006,25 +1007,25 @@ sub DoorPi_PurgeDB {
return undef; return undef;
}elsif ( $hash && $err ){ }elsif ( $hash && $err ){
Log 1,"[DoorPi_PurgeDB] has error $err"; Log 1,"[DoorPi_PurgeDB] has error $err";
readingsSingleUpdate($hash,"config",$err,0);
readingsSingleUpdate($hash,"state","Error",1); readingsSingleUpdate($hash,"state","Error",1);
return; return;
} }
#Log 1,"[DoorPi_PurgeDB] has obtained data $status";
#-- test if this is valid JSON #-- test if this is valid JSON
if( !is_valid_json($data) ){ if( !is_valid_json($status) ){
Log 1,"[DoorPi_PurgeDB] invalid data"; Log 1,"[DoorPi_PurgeDB] invalid data";
readingsSingleUpdate($hash,"state","Error",1); readingsSingleUpdate($hash,"state","Error",1);
return; return;
} }
my $json = JSON->new->utf8; my $json = JSON->new->utf8;
my $jhash = $json->decode( $data ); my $jhash = $json->decode( $status );
my $msg = $jhash->{'message'}; my $suc = $jhash->{'history_event'};
my $suc = $jhash->{'success'}; if( $suc eq "0" ){
if( $suc ){ return "OK";
return $msg; }else{
}
return undef; return undef;
}
} }
####################################################################################### #######################################################################################