From 5e56b30e58b08ddd93f7fbeec0a29ad1a947e611 Mon Sep 17 00:00:00 2001
From: Marko Oldenburg
Date: Tue, 12 Sep 2017 15:54:57 +0200
Subject: [PATCH] code cleaning
---
73_GardenaSmartBridge.pm | 73 ++++++++++------------------------------
74_GardenaSmartDevice.pm | 12 +++----
2 files changed, 21 insertions(+), 64 deletions(-)
diff --git a/73_GardenaSmartBridge.pm b/73_GardenaSmartBridge.pm
index a76c731..f4f15af 100644
--- a/73_GardenaSmartBridge.pm
+++ b/73_GardenaSmartBridge.pm
@@ -62,15 +62,13 @@ use strict;
use warnings;
use HttpUtils;
-use Data::Dumper; #debugging
eval "use Encode qw(encode encode_utf8 decode_utf8);1" or $missingModul .= "Encode ";
eval "use JSON;1" or $missingModul .= "JSON ";
eval "use IO::Socket::SSL;1" or $missingModul .= "IO::Socket::SSL ";
-###todo Hier fehlt noch Modulabfrage für ssl
-my $version = "0.2.2";
+my $version = "0.2.4";
@@ -314,63 +312,26 @@ sub GardenaSmartBridge_Write($@) {
sub GardenaSmartBridge_ErrorHandling($$$) {
- my ($param,$err,$data) = @_;
+ my ($param,$err,$data) = @_;
- my $hash = $param->{hash};
- my $name = $hash->{NAME};
+ my $hash = $param->{hash};
+ my $name = $hash->{NAME};
+ my $dhash = $hash;
+
+ $dhash = $modules{GardenaSmartDevice}{defptr}{$param->{'device_id'}}
+ unless( not defined( $param->{'device_id'}) );
- my $dhash;
- if( defined( $param->{'device_id'}) ) {
- $dhash = $modules{GardenaSmartDevice}{defptr}{$param->{'device_id'}};
- } else {
- $dhash = $hash;
- }
my $dname = $dhash->{NAME};
+
+
+ #if( defined( $param->{'device_id'}) ) {
+ # $dhash = $modules{GardenaSmartDevice}{defptr}{$param->{'device_id'}};
+ #} else {
+ # $dhash = $hash;
+ #}
+ #my $dname = $dhash->{NAME};
- ###todo Das gesamte Errorhandling muss hier noch rein
-
- #Log3 $name, 1, "GardenaSmartBridge ($name) - Header:\n".Dumper($param->{header});
- #Log3 $name, 1, "GardenaSmartBridge ($name) - CODE:\n".Dumper($param->{code});
- #Log3 $name, 1, "GardenaSmartBridge ($name) - Error:\n".Dumper($err);
- #Log3 $name, 1, "GardenaSmartBridge ($name) - Data:\n".Dumper($data);
-
-
-
-
- #### Ein Fehler der Behandelt werden muss
- # Data:
- # '
- #
- #
- # Error 400 Bad Request
- #
- # HTTP ERROR 400
- # Problem accessing /sg-1/devices/2ad0d816-8bc3-4f0a-8c52-8b0dc8d7b2ec/abilities/watering_computer/command. Reason:
- #
Bad Request
Powered by Jetty://
- #
- #
- #
- # ';
-
- # '
- #
- #
- # Error 503 Service Unavailable
- #
- # HTTP ERROR 503
- # Problem accessing /sg-1/devices/2ad0d816-8bc3-4f0a-8c52-8b0dc8d7b2ec/abilities/outlet/command. Reason:
- #
Service Unavailable
Powered by Jetty://
- #
- #
- #
- # ';
-
-
- # 2017.08.10 11:17:20 1: GardenaSmartBridge (myGardena) - Data:
- # $VAR1 = '{"errors":[{"attribute":"password","error":"invalid"}]}';
-
-
if( defined( $err ) ) {
@@ -577,7 +538,7 @@ sub GardenaSmartBridge_ResponseProcessing($$) {
return;
}
- Log3 $name, 3, "GardenaSmartBridge ($name) - no Match for processing data"
+ Log3 $name, 3, "GardenaSmartBridge ($name) - no Match for processing data"
}
sub GardenaSmartBridge_WriteReadings($$) {
diff --git a/74_GardenaSmartDevice.pm b/74_GardenaSmartDevice.pm
index 180b2b1..571e444 100644
--- a/74_GardenaSmartDevice.pm
+++ b/74_GardenaSmartDevice.pm
@@ -62,13 +62,10 @@ use strict;
use warnings;
use Time::Local;
-use Data::Dumper; #debugging
-
-# eval "use Encode qw(encode encode_utf8 decode_utf8);1" or $missingModul .= "Encode "; wird nicht benötigt
eval "use JSON;1" or $missingModul .= "JSON ";
-my $version = "0.2.3";
+my $version = "0.2.4";
@@ -135,10 +132,10 @@ sub GardenaSmartDevice_Define($$) {
return "too few parameters: define GardenaSmartDevice " if( @a != 3 ) ;
return "Cannot define Gardena Bridge device. Perl modul $missingModul is missing." if ( $missingModul );
- my ($name,$deviceId,$category) = @a;
+ my ($name,$deviceId,$category) = @a;
- $hash->{DEVICEID} = $deviceId;
- $hash->{VERSION} = $version;
+ $hash->{DEVICEID} = $deviceId;
+ $hash->{VERSION} = $version;
AssignIoPort($hash,$iodev) if( !$hash->{IODev} );
@@ -314,7 +311,6 @@ sub GardenaSmartDevice_Parse($$) {
} else {
Log3 $name, 3, "GardenaSmartDevice ($name) - autocreate new device " . makeDeviceName($decode_json->{name}) . " with deviceId $decode_json->{id}, model $decode_json->{category} and IODev IODev=$name";
- #return "UNDEFINED " . join('',split("[ \t]+",$decode_json->{name})) . " GardenaSmartDevice $decode_json->{id} $decode_json->{category} IODev=$name";
return "UNDEFINED " . makeDeviceName($decode_json->{name}) . " GardenaSmartDevice $decode_json->{id} $decode_json->{category} IODev=$name";
}
}