code cleaning

This commit is contained in:
Marko Oldenburg
2017-09-12 15:54:57 +02:00
parent 1aa6180eaa
commit 5e56b30e58
2 changed files with 21 additions and 64 deletions

View File

@ -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:
# '<html>
# <head>
# <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
# <title>Error 400 Bad Request</title>
# </head>
# <body><h2>HTTP ERROR 400</h2>
# <p>Problem accessing /sg-1/devices/2ad0d816-8bc3-4f0a-8c52-8b0dc8d7b2ec/abilities/watering_computer/command. Reason:
# <pre> Bad Request</pre></p><hr><i><small>Powered by Jetty://</small></i><hr/>
#
# </body>
# </html>
# ';
# '<html>
# <head>
# <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
# <title>Error 503 Service Unavailable</title>
# </head>
# <body><h2>HTTP ERROR 503</h2>
# <p>Problem accessing /sg-1/devices/2ad0d816-8bc3-4f0a-8c52-8b0dc8d7b2ec/abilities/outlet/command. Reason:
# <pre> Service Unavailable</pre></p><hr><i><small>Powered by Jetty://</small></i><hr/>
#
# </body>
# </html>
# ';
# 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($$) {

View File

@ -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 <NAME> GardenaSmartDevice <device_Id> <model>" 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";
}
}