fixed zone query (query id of zone)
This commit is contained in:
parent
afcd5246e7
commit
392a2e99af
170
98_TadoAPI.pm
170
98_TadoAPI.pm
|
@ -286,7 +286,7 @@ sub TadoAPI_Get(@) {
|
|||
$message = "Tado-Device(s):\n";
|
||||
for (my $i=0; $i < @devArr; $i++){
|
||||
my $tadodevices = $devArr[$i]->{'devices'};
|
||||
$message .= "ZoneID:" . ($i+1);
|
||||
$message .= "ZoneID: " . ($devArr[$i]->{'id'});
|
||||
my $spacer = 0;
|
||||
foreach my $item ( @$tadodevices ){
|
||||
$message .= "\t" if ($spacer > 0);
|
||||
|
@ -305,8 +305,10 @@ sub TadoAPI_Get(@) {
|
|||
TadoAPI_GetZoneInfo($hash);
|
||||
my $zonecount = TadoAPI_GetZoneCount($hash);
|
||||
$message = "You have $zonecount Zones in Home " . $attr{$name}{homeID} . ".\n";
|
||||
for (my $i=1; $i <= $zonecount; $i++) {
|
||||
$message .= "Zone ID:$i: " . TadoAPI_GetZoneNameById($hash, $i) . "\n";
|
||||
my @zoneArr = TadoAPI_RequestTadoDevices($hash);
|
||||
for (my $i=0; $i < @zoneArr; $i++){
|
||||
my $zoneid = $zoneArr[$i]->{'id'};
|
||||
$message .= "Zone ID $zoneid: " . TadoAPI_GetZoneNameById($hash, $zoneid) . "\n";
|
||||
}
|
||||
$message .= "See Logfile for more Info";
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "$cmd finished\n";
|
||||
|
@ -614,49 +616,6 @@ sub TadoAPI_SetAllOverlays(@){
|
|||
}
|
||||
}
|
||||
|
||||
sub TadoAPI_UpdateAllZonesCallback($){
|
||||
my ($param, $err, $data) = @_;
|
||||
my $hash = $param->{hash};
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
if($err ne "")
|
||||
{
|
||||
Log3 $name, 3, "Error in TadoAPI_UpdateZoneCallback while requesting ".$param->{url}." - $err";
|
||||
return undef;
|
||||
}
|
||||
|
||||
elsif($data ne "")
|
||||
{
|
||||
Log3 $name, 5, "url ".$param->{url}." returned: $data";
|
||||
my $zonecount = TadoAPI_GetZoneCount($hash);
|
||||
# fix for empty zonecount
|
||||
if($zonecount == 0){
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "Error, no zones found, retrying...";
|
||||
$TokenData = TadoAPI_LoadToken($hash);
|
||||
$zonecount = TadoAPI_GetZoneCount($hash);
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "Retry finished. Zonecount now: %zonecount ";
|
||||
}
|
||||
for (my $i=1; $i <= $zonecount; $i++) {
|
||||
Log3 $name, 5, "TadoAPI $name" . ": " . "Set Reading Update for Zone $i ";
|
||||
my ($temperature, $humidity, $desiredTemp, $currentHeatingPower, $overlay ) = TadoAPI_GetZoneReadingsById($hash, $i);
|
||||
my $zoneName = TadoAPI_GetZoneNameById($hash, $i);
|
||||
|
||||
if(defined($zoneName)){
|
||||
readingsBeginUpdate($hash);
|
||||
readingsBulkUpdate($hash, "Temperatur_" . $zoneName, $temperature);
|
||||
readingsBulkUpdate($hash, "Luftfeuchtigkeit_" . $zoneName, $humidity);
|
||||
readingsBulkUpdate($hash, "Heizleistung_" . $zoneName, $currentHeatingPower);
|
||||
readingsBulkUpdate($hash, "OverlayType_" . $zoneName, $overlay);
|
||||
readingsBulkUpdate($hash, "DesiredTemp_" . $zoneName, $desiredTemp);
|
||||
readingsEndUpdate( $hash, 1 );
|
||||
}
|
||||
}
|
||||
readingsBeginUpdate($hash);
|
||||
readingsBulkUpdate($hash, "ActiveZones", $zonecount);
|
||||
readingsEndUpdate( $hash, 1 );
|
||||
}
|
||||
}
|
||||
|
||||
sub TadoAPI_UpdateFn(@){
|
||||
my ($hash) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
@ -670,7 +629,7 @@ sub TadoAPI_UpdateFn(@){
|
|||
url => $URL,
|
||||
header => { "Content-Type"=>"application/json;charset=UTF-8","Authorization" => "$TokenData->{'token_type'} $TokenData->{'access_token'}" },
|
||||
method => 'GET',
|
||||
timeout => 10,
|
||||
timeout => 5,
|
||||
incrementalTimout => 1,
|
||||
hash => $hash,
|
||||
callback => \&TadoAPI_UpdateAllZonesCallback
|
||||
|
@ -684,7 +643,7 @@ sub TadoAPI_UpdateFn(@){
|
|||
url => $URL,
|
||||
header => { "Content-Type"=>"application/json;charset=UTF-8","Authorization" => "$TokenData->{'token_type'} $TokenData->{'access_token'}" },
|
||||
method => 'GET',
|
||||
timeout => 10,
|
||||
timeout => 4,
|
||||
incrementalTimout => 1,
|
||||
callback => \&TadoAPI_UpdateMobileReadingsCallback,
|
||||
hash => $hash
|
||||
|
@ -697,7 +656,7 @@ sub TadoAPI_UpdateFn(@){
|
|||
url => $URL,
|
||||
header => { "Content-Type"=>"application/json;charset=UTF-8","Authorization" => "$TokenData->{'token_type'} $TokenData->{'access_token'}" },
|
||||
method => 'GET',
|
||||
timeout => 8,
|
||||
timeout => 10,
|
||||
incrementalTimout => 1,
|
||||
callback => \&TadoAPI_UpdateTadoDeviceInformationCallback,
|
||||
hash => $hash
|
||||
|
@ -746,9 +705,9 @@ sub TadoAPI_GetGeoById(@){
|
|||
}
|
||||
return undef;
|
||||
}
|
||||
########################################################
|
||||
########################################################################################################################################################################
|
||||
# Callback Subs
|
||||
########################################################
|
||||
########################################################################################################################################################################
|
||||
sub TadoAPI_callback($){
|
||||
my ($param, $err, $data) = @_;
|
||||
my $hash = $param->{hash};
|
||||
|
@ -769,6 +728,54 @@ sub TadoAPI_callback($){
|
|||
return undef;
|
||||
}
|
||||
|
||||
sub TadoAPI_UpdateAllZonesCallback($){
|
||||
my ($param, $err, $data) = @_;
|
||||
my $hash = $param->{hash};
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
if($err ne "")
|
||||
{
|
||||
Log3 $name, 3, "Error in TadoAPI_UpdateZoneCallback while requesting ".$param->{url}." - $err";
|
||||
return undef;
|
||||
}
|
||||
|
||||
elsif($data ne "")
|
||||
{
|
||||
Log3 $name, 5, "url ".$param->{url}." returned: $data";
|
||||
my $decoded_data = eval { decode_json($data) };
|
||||
|
||||
# if api returns error
|
||||
eval { my $error = @$decoded_data; };
|
||||
|
||||
if ($@){
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "UpdateAllZonesCallback: decode_json failed, invalid json. error:$@\n" if $@;
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "UpdateAllZonesCallback: Error in decoded data, Code: " . $decoded_data->{'errors'}->[0]->{'code'} if (exists($decoded_data->{'errors'}->[0]->{'code'}));
|
||||
$hash->{LastRequest}="error";
|
||||
}else{
|
||||
foreach my $zone ( @$decoded_data ){
|
||||
my $zoneid = $zone->{'id'};
|
||||
Log3 $name, 5, "TadoAPI $name" . ": " . "Set Reading Update for Zone $zoneid ";
|
||||
my ($temperature, $humidity, $desiredTemp, $currentHeatingPower, $overlay ) = TadoAPI_GetZoneReadingsById($hash, $zoneid);
|
||||
my $zoneName = TadoAPI_GetZoneNameById($hash, $zoneid);
|
||||
|
||||
if(defined($zoneName)){
|
||||
readingsBeginUpdate($hash);
|
||||
readingsBulkUpdate($hash, "Temperatur_" . $zoneName, $temperature);
|
||||
readingsBulkUpdate($hash, "Luftfeuchtigkeit_" . $zoneName, $humidity);
|
||||
readingsBulkUpdate($hash, "Heizleistung_" . $zoneName, $currentHeatingPower);
|
||||
readingsBulkUpdate($hash, "OverlayType_" . $zoneName, $overlay);
|
||||
readingsBulkUpdate($hash, "DesiredTemp_" . $zoneName, $desiredTemp);
|
||||
readingsEndUpdate( $hash, 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
my $zonecount = TadoAPI_GetZoneCount($hash);
|
||||
readingsBeginUpdate($hash);
|
||||
readingsBulkUpdate($hash, "ActiveZones", $zonecount);
|
||||
readingsEndUpdate( $hash, 1 );
|
||||
}
|
||||
}
|
||||
|
||||
sub Tado_UpdateZoneOverlayCallback($)
|
||||
{
|
||||
my ($param, $err, $data) = @_;
|
||||
|
@ -847,6 +854,22 @@ sub TadoAPI_UpdateTadoDeviceInformationCallback($){
|
|||
}
|
||||
}
|
||||
|
||||
sub TadoAPI_SetGeoByIdCallback($){
|
||||
my ($param, $err, $data) = @_;
|
||||
my $hash = $param->{hash};
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
if($err ne "")
|
||||
{
|
||||
Log3 $name, 3, "Error in TadoAPI_SetGeoByIdCallback while requesting ".$param->{url}." - $err";
|
||||
}
|
||||
|
||||
elsif($data ne "")
|
||||
{
|
||||
Log3 $name, 3, "url ".$param->{url}." returned: $data";
|
||||
}
|
||||
}
|
||||
|
||||
sub TadoAPI_UpdateMobileReadingsCallback($){
|
||||
my ($param, $err, $data) = @_;
|
||||
my $hash = $param->{hash};
|
||||
|
@ -966,22 +989,7 @@ sub TadoAPI_GetZoneInfo(@) {
|
|||
return undef;
|
||||
}
|
||||
|
||||
sub TadoAPI_SetGeoByIdCallback($){
|
||||
my ($param, $err, $data) = @_;
|
||||
my $hash = $param->{hash};
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
if($err ne "")
|
||||
{
|
||||
Log3 $name, 3, "Error in TadoAPI_SetGeoByIdCallback while requesting ".$param->{url}." - $err";
|
||||
}
|
||||
|
||||
elsif($data ne "")
|
||||
{
|
||||
Log3 $name, 3, "url ".$param->{url}." returned: $data";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sub TadoAPI_SetGeoById(@){
|
||||
my ($hash, $mobID, $geo) = @_;
|
||||
|
@ -1030,7 +1038,7 @@ sub TadoAPI_RequestTadoDevices(@) {
|
|||
url => $URL,
|
||||
header => {"Content-Type"=>"application/json;charset=UTF-8","Authorization" => "$TokenData->{'token_type'} $TokenData->{'access_token'}"},
|
||||
method => 'GET',
|
||||
timeout => 2,
|
||||
timeout => 5,
|
||||
hash => $hash
|
||||
};
|
||||
|
||||
|
@ -1039,7 +1047,7 @@ sub TadoAPI_RequestTadoDevices(@) {
|
|||
|
||||
if($err ne "")
|
||||
{
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "TadoAPI_RequestTadoDevices: Error while requesting ".$param->{url}." - $err";
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "RequestTadoDevices: Error while requesting ".$param->{url}." - $err";
|
||||
}
|
||||
elsif($data ne "")
|
||||
{
|
||||
|
@ -1047,7 +1055,7 @@ sub TadoAPI_RequestTadoDevices(@) {
|
|||
my $decoded_data = eval { decode_json($data) };
|
||||
|
||||
if ($@){
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "TadoAPI_RequestTadoDevices: decode_json failed, invalid json. error:$@\n";
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "RequestTadoDevices: decode_json failed, invalid json. error:$@\n";
|
||||
}else{
|
||||
my @devices = ();
|
||||
foreach my $dev (@$decoded_data){
|
||||
|
@ -1076,7 +1084,7 @@ sub TadoAPI_ZoneRequest(@) {
|
|||
url => $URL,
|
||||
header => {"Content-Type"=>"application/json;charset=UTF-8","Authorization" => "$TokenData->{'token_type'} $TokenData->{'access_token'}"},
|
||||
method => 'GET',
|
||||
timeout => 2,
|
||||
timeout => 5,
|
||||
hash => $hash,
|
||||
zoneID => $i
|
||||
};
|
||||
|
@ -1223,7 +1231,7 @@ sub TadoAPI_GetZoneCount(@) {
|
|||
|
||||
if($err ne "")
|
||||
{
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "TadoAPI_GetZoneCount: Error while requesting ".$param->{url}." - $err";
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "GetZoneCount: Error while requesting ".$param->{url}." - $err";
|
||||
}
|
||||
elsif($data ne "")
|
||||
{
|
||||
|
@ -1232,18 +1240,20 @@ sub TadoAPI_GetZoneCount(@) {
|
|||
my $decoded_data = eval { decode_json($data) };
|
||||
|
||||
if ($@){
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "TadoAPI_GetZoneCount: decode_json failed, invalid json. error:$@\n";
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "GetZoneCount: decode_json failed, invalid json. error:$@\n";
|
||||
}else{
|
||||
return 0 unless (ref($decoded_data) ne 'HASH') ;
|
||||
foreach my $item( @$decoded_data ) {
|
||||
$zonecount++;
|
||||
if(ref($decoded_data) eq 'ARRAY'){
|
||||
foreach my $item( @$decoded_data ) {
|
||||
$zonecount++;
|
||||
}
|
||||
return $zonecount;
|
||||
}elsif(ref($decoded_data) eq 'HASH'){
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "GetZoneCount: " . $decoded_data->{'errors'}->[0]->{'code'} if (exists($decoded_data->{'errors'}));
|
||||
}
|
||||
|
||||
return $zonecount;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub TadoAPI_GetZoneNameById(@) {
|
||||
|
@ -1317,14 +1327,14 @@ sub TadoAPI_GetZoneReadingsById(@){
|
|||
|
||||
if($err ne "")
|
||||
{
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "TadoAPI_GetZoneReadingsById: Error while requesting ".$param->{url}." - $err";
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "GetZoneReadingsById: Error while requesting ".$param->{url}." - $err";
|
||||
}
|
||||
elsif($data ne "")
|
||||
{
|
||||
Log3 $name, 5, "url ".$param->{url}." returned: $data";
|
||||
my $decoded_data = eval { decode_json($data) };
|
||||
if ($@){
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "TadoAPI_GetZoneReadingsById: Zone $zoneID decode_json failed, invalid json. error:$@\n";
|
||||
Log3 $name, 3, "TadoAPI $name" . ": " . "GetZoneReadingsById: Zone $zoneID decode_json failed, invalid json. error:$@\n";
|
||||
}else{
|
||||
$temperature = $decoded_data->{'sensorDataPoints'}->{'insideTemperature'}->{'celsius'};
|
||||
$humidity = $decoded_data->{'sensorDataPoints'}->{'humidity'}->{'percentage'};
|
||||
|
|
Loading…
Reference in New Issue