From 107940bf1a45c1434f1a53718cb8f78eb6242294 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Thu, 10 Aug 2017 15:00:29 +0200 Subject: [PATCH] better error handling supported --- 73_GardenaSmartBridge.pm | 27 +++++++++++++++++++++++---- 74_GardenaSmartDevice.pm | 1 + 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/73_GardenaSmartBridge.pm b/73_GardenaSmartBridge.pm index 5f46cc1..b9e850f 100644 --- a/73_GardenaSmartBridge.pm +++ b/73_GardenaSmartBridge.pm @@ -398,7 +398,7 @@ sub GardenaSmartBridge_ErrorHandling($$$) { Log3 $dname, 5, "GardenaSmartBridge ($dname) - RequestERROR: connect to gardena cloud is timed out. check network"; } - elsif( $err =~ /Keine Route zum Zielrechner/ ) { + elsif( $err =~ /Keine Route zum Zielrechner/ or $err =~ /no route to target/ ) { Log3 $dname, 5, "GardenaSmartBridge ($dname) - RequestERROR: no route to target. bad network configuration or network is down"; @@ -411,6 +411,8 @@ sub GardenaSmartBridge_ErrorHandling($$$) { Log3 $dname, 5, "GardenaSmartBridge ($dname) - RequestERROR: GardenaSmartBridge RequestErrorHandling: error while requesting gardena cloud: $err"; + delete $dhash->{helper}{deviceAction} if( defined($dhash->{helper}{deviceAction}) ); + return; } } @@ -422,7 +424,7 @@ sub GardenaSmartBridge_ErrorHandling($$$) { readingsBulkUpdateIfChanged( $dhash, "lastRequestState", "request_error", 1 ); - if( $param->{code} == 401 ) { + if( $param->{code} == 401 and $hash eq $dhash ) { if( ReadingsVal($dname,'token','none') eq 'none' ) { readingsBulkUpdate( $dhash, "state", "no token available", 1); @@ -431,6 +433,11 @@ sub GardenaSmartBridge_ErrorHandling($$$) { Log3 $dname, 5, "GardenaSmartBridge ($dname) - RequestERROR: ".$param->{code}; + } elsif( $param->{code} == 204 and $dhash ne $hash and defined($dhash->{helper}{deviceAction}) ) { + + readingsBulkUpdate( $dhash, "state", "the set command is processed", 1); + GardenaSmartBridge_getDevices($hash); + } elsif( $param->{code} != 200 ) { Log3 $dname, 5, "GardenaSmartBridge ($dname) - RequestERROR: ".$param->{code}; @@ -439,6 +446,8 @@ sub GardenaSmartBridge_ErrorHandling($$$) { readingsEndUpdate( $dhash, 1 ); Log3 $dname, 5, "GardenaSmartBridge ($dname) - RequestERROR: received http code ".$param->{code}." without any data after requesting gardena cloud"; + + delete $dhash->{helper}{deviceAction} if( defined($dhash->{helper}{deviceAction}) ); return; } @@ -452,8 +461,8 @@ sub GardenaSmartBridge_ErrorHandling($$$) { if( $param->{code} == 400 ) { if( defined(eval{decode_json($data)}->{errors}) and ref(eval{decode_json($data)}->{errors}) eq "ARRAY" ) { readingsBulkUpdate( $dhash, "state", eval{decode_json($data)}->{errors}[0]{error} . ' ' . eval{decode_json($data)}->{errors}[0]{attribute}, 1); - #readingsBulkUpdate( $dhash, "lastRequestState", eval{decode_json($data)}->{errors}{error} eval{decode_json($data)}->{errors}{attribute}, 1 ); - #Log3 $dname, 5, "GardenaSmartBridge ($dname) - RequestERROR: eval{decode_json($data)}->{errors}{error} eval{decode_json($data)}->{errors}{attribute}"; + readingsBulkUpdate( $dhash, "lastRequestState", eval{decode_json($data)}->{errors}[0]{error} . ' ' . eval{decode_json($data)}->{errors}[0]{attribute}, 1 ); + Log3 $dname, 5, "GardenaSmartBridge ($dname) - RequestERROR: " . eval{decode_json($data)}->{errors}[0]{error} . " " . eval{decode_json($data)}->{errors}[0]{attribute}; } else { readingsBulkUpdate( $dhash, "lastRequestState", "Error 400 Bad Request", 1 ); Log3 $dname, 5, "GardenaSmartBridge ($dname) - RequestERROR: Error 400 Bad Request"; @@ -462,6 +471,14 @@ sub GardenaSmartBridge_ErrorHandling($$$) { Log3 $dname, 5, "GardenaSmartBridge ($dname) - RequestERROR: Error 503 Service Unavailable"; readingsBulkUpdate( $dhash, "lastRequestState", "Error 503 Service Unavailable", 1 ); + + } elsif( $param->{code} == 404 ) { + if( defined($dhash->{helper}{deviceAction}) and $dhash ne $hash ) { + readingsBulkUpdate( $dhash, "lastRequestState", "device id not found", 1 ); + readingsBulkUpdate( $dhash, "state", "device Id not found", 1 ); + } + + Log3 $dname, 5, "GardenaSmartBridge ($dname) - RequestERROR: Error 404 Not Found"; } elsif( $param->{code} == 500 ) { @@ -475,6 +492,8 @@ sub GardenaSmartBridge_ErrorHandling($$$) { readingsEndUpdate( $dhash, 1 ); Log3 $dname, 5, "GardenaSmartBridge ($dname) - RequestERROR: received http code ".$param->{code}." receive Error after requesting gardena cloud"; + + delete $dhash->{helper}{deviceAction} if( defined($dhash->{helper}{deviceAction}) ); return; } diff --git a/74_GardenaSmartDevice.pm b/74_GardenaSmartDevice.pm index bcc8df8..1b4664c 100644 --- a/74_GardenaSmartDevice.pm +++ b/74_GardenaSmartDevice.pm @@ -263,6 +263,7 @@ sub GardenaSmartDevice_Set($@) { $abilities = 'mower' if( AttrVal($name,'model','unknown') eq 'mower' ); $abilities = 'outlet' if( AttrVal($name,'model','unknown') eq 'watering_computer' ); + $hash->{helper}{deviceAction} = $payload; IOWrite($hash,$payload,$hash->{DEVICEID},$abilities); Log3 $name, 4, "GardenaSmartBridge ($name) - IOWrite: $payload $hash->{DEVICEID} $abilities IODevHash=$hash->{IODev}";