updateFn optimized

This commit is contained in:
Philipp Wo 2019-11-22 20:23:01 +01:00
parent c802b3f655
commit d7d6fc4000
1 changed files with 20 additions and 20 deletions

View File

@ -630,10 +630,10 @@ sub TadoAPI_UpdateFn(@){
url => $URL,
header => { "Content-Type"=>"application/json;charset=UTF-8","Authorization" => "$TokenData->{'token_type'} $TokenData->{'access_token'}" },
method => 'GET',
timeout => 5,
timeout => 25,
incrementalTimout => 1,
hash => $hash,
callback => \&TadoAPI_UpdateAllZonesCallback
callback => \&TadoAPI_UpdateAllZoneReadingsCallback
};
HttpUtils_NonblockingGet($request);
@ -644,25 +644,13 @@ sub TadoAPI_UpdateFn(@){
url => $URL,
header => { "Content-Type"=>"application/json;charset=UTF-8","Authorization" => "$TokenData->{'token_type'} $TokenData->{'access_token'}" },
method => 'GET',
timeout => 4,
timeout => 5,
incrementalTimout => 1,
callback => \&TadoAPI_UpdateMobileReadingsCallback,
hash => $hash
};
HttpUtils_NonblockingGet($request);
# tado devices
$URL=$QueryURL.qq{/$homeID/zones};
$request = {
url => $URL,
header => { "Content-Type"=>"application/json;charset=UTF-8","Authorization" => "$TokenData->{'token_type'} $TokenData->{'access_token'}" },
method => 'GET',
timeout => 10,
incrementalTimout => 1,
callback => \&TadoAPI_UpdateTadoDeviceInformationCallback,
hash => $hash
};
HttpUtils_NonblockingGet($request);
}
}
@ -729,7 +717,7 @@ sub TadoAPI_callback($){
return undef;
}
sub TadoAPI_UpdateAllZonesCallback($){
sub TadoAPI_UpdateAllZoneReadingsCallback($){
my ($param, $err, $data) = @_;
my $hash = $param->{hash};
my $name = $hash->{NAME};
@ -768,6 +756,16 @@ sub TadoAPI_UpdateAllZonesCallback($){
readingsBulkUpdate($hash, "DesiredTemp_" . $zoneName, $desiredTemp);
readingsEndUpdate( $hash, 1 );
}
# iterate through all devices in zone
my $devices = $zone->{'devices'};
foreach my $device ( @$devices ){
readingsBeginUpdate($hash);
readingsBulkUpdate($hash, "Battery_" . $device->{'serialNo'}, $device->{'batteryState'});
readingsEndUpdate( $hash, 1 );
$hash->{LastRequest}="OK";
print "fffffffffffffffffffffffffffffffffffffffffffffffffff";
}
}
}
my $zonecount = TadoAPI_GetZoneCount($hash);
@ -1060,11 +1058,13 @@ sub TadoAPI_RequestTadoDevices(@) {
if ($@){
Log3 $name, 3, "TadoAPI $name" . ": " . "RequestTadoDevices: decode_json failed, invalid json. error:$@\n";
}else{
my @devices = ();
foreach my $dev (@$decoded_data){
push @devices, $dev;
if(ref($decoded_data) eq 'ARRAY'){
my @devices = ();
foreach my $dev (@$decoded_data){
push @devices, $dev;
}
return @devices;
}
return @devices;
}
}
}