reverted to normal token load

This commit is contained in:
Philipp Wo 2019-12-10 13:21:10 +01:00
parent 2d32913bef
commit df555d473b
1 changed files with 5 additions and 34 deletions

View File

@ -210,7 +210,7 @@ sub TadoAPI_Set(@) {
} elsif( $cmd eq 'update' ) { } elsif( $cmd eq 'update' ) {
Log3 $name, 3, "TadoAPI: set $name: processing ($cmd)"; Log3 $name, 3, "TadoAPI: set $name: processing ($cmd)";
TadoAPI_UpdateFnNb($hash); TadoAPI_UpdateFn($hash);
Log3 $name, 3, "TadoAPI $name" . ": " . "$cmd finished\n"; Log3 $name, 3, "TadoAPI $name" . ": " . "$cmd finished\n";
} elsif( $cmd eq 'zoneUpdate' ) { } elsif( $cmd eq 'zoneUpdate' ) {
@ -534,7 +534,7 @@ sub TadoAPI_Update(@){
InternalTimer( $nextTimer, "TadoAPI_Update", $hash, 0 ); InternalTimer( $nextTimer, "TadoAPI_Update", $hash, 0 );
# update subs # update subs
TadoAPI_UpdateFnNb($hash); TadoAPI_UpdateFn($hash);
return undef; return undef;
} }
@ -674,14 +674,8 @@ sub TadoAPI_SetAllOverlays(@){
} }
} }
} }
###### main update function
sub TadoAPI_UpdateFnNb(@){
my ($hash) = @_;
delete($hash->{helper}{RUNNING_PID});
$hash->{helper}{RUNNING_PID} = BlockingCall("TadoAPI_DoUpdate", $hash,"TadoAPI_UpdateFnNbDone", 120, "TadoAPI_UpdateFnNbAborted", $hash) unless(exists($hash->{helper}{RUNNING_PID}));
}
sub TadoAPI_DoUpdate($){ sub TadoAPI_UpdateFn(@){
my ($hash) = @_; my ($hash) = @_;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $TokenData = TadoAPI_LoadToken($hash); my $TokenData = TadoAPI_LoadToken($hash);
@ -708,33 +702,14 @@ sub TadoAPI_DoUpdate($){
url => $URL, url => $URL,
header => { "Content-Type"=>"application/json;charset=UTF-8","Authorization" => "$TokenData->{'token_type'} $TokenData->{'access_token'}" }, header => { "Content-Type"=>"application/json;charset=UTF-8","Authorization" => "$TokenData->{'token_type'} $TokenData->{'access_token'}" },
method => 'GET', method => 'GET',
timeout => 15, timeout => 10,
incrementalTimout => 1, incrementalTimout => 1,
callback => \&TadoAPI_UpdateMobileReadingsCallback, callback => \&TadoAPI_UpdateMobileReadingsCallback,
hash => $hash hash => $hash
}; };
HttpUtils_NonblockingGet($request); HttpUtils_NonblockingGet($request);
} }
return $name;
}
sub TadoAPI_UpdateFnNbDone($){
my ($string) = @_;
return unless(defined($string));
my @a = split("\\|",$string);
my $hash = $defs{$a[0]};
delete($hash->{helper}{RUNNING_PID});
Log3 $hash->{NAME}, 3, "BlockingCall for ".$hash->{NAME}." was DONE";
}
sub TadoAPI_UpdateFnNbAborted($){
my ($hash) = @_;
delete($hash->{helper}{RUNNING_PID});
Log3 $hash->{NAME}, 3, "BlockingCall for ".$hash->{NAME}." was aborted";
} }
######################################################################################################################################################################## ########################################################################################################################################################################
@ -746,9 +721,6 @@ sub TadoAPI_callback($){
my $name = $hash->{NAME}; my $name = $hash->{NAME};
$param->{code} = 0 unless defined $param->{code}; $param->{code} = 0 unless defined $param->{code};
# todo remove this
Log3 $name, 3, "TadoAPI $name" . ": " . "API Callback running..... Callback Status: " . $param->{code};
if($param->{code} == 401 || $param->{code} == 400){ if($param->{code} == 401 || $param->{code} == 400){
$apiStatus = 1; $apiStatus = 1;
$hash->{STATE}="reachable"; $hash->{STATE}="reachable";
@ -758,7 +730,6 @@ sub TadoAPI_callback($){
$apiStatus = 0; $apiStatus = 0;
$hash->{STATE}="error"; $hash->{STATE}="error";
Log3 $name, 5, "TadoAPI $name" . ": " . "API error: apiStatus $apiStatus ($err)"; Log3 $name, 5, "TadoAPI $name" . ": " . "API error: apiStatus $apiStatus ($err)";
} }
return undef; return undef;
} }