mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-02-25 16:05:19 +00:00
AutomowerConnectDevice: improved error handling
git-svn-id: https://svn.fhem.de/fhem/trunk@27132 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
370aae32cc
commit
d88ee40b01
@ -93,6 +93,7 @@ sub Initialize() {
|
|||||||
$hash->{FW_detailFn}= \&FW_detailFn;
|
$hash->{FW_detailFn}= \&FW_detailFn;
|
||||||
$hash->{AttrFn} = \&Attr;
|
$hash->{AttrFn} = \&Attr;
|
||||||
$hash->{AttrList} = "disable:1,0 " .
|
$hash->{AttrList} = "disable:1,0 " .
|
||||||
|
"debug:1,0 " .
|
||||||
"disabledForIntervals " .
|
"disabledForIntervals " .
|
||||||
"mapImagePath " .
|
"mapImagePath " .
|
||||||
"mapImageWidthHeight " .
|
"mapImageWidthHeight " .
|
||||||
@ -242,10 +243,11 @@ sub Notify {
|
|||||||
|
|
||||||
if ( grep /^state:.connected$/, @{$events} ) {
|
if ( grep /^state:.connected$/, @{$events} ) {
|
||||||
|
|
||||||
my $maxMower = @{$hosthash->{helper}{mowers}};
|
my $maxMower = 0;
|
||||||
|
$maxMower = @{$hash->{helper}{mowers}} if ( ref ( $hash->{helper}{mowers} ) eq 'ARRAY' );
|
||||||
if ($maxMower <= $mowerNumber || $mowerNumber < 0 ) {
|
if ($maxMower <= $mowerNumber || $mowerNumber < 0 ) {
|
||||||
|
|
||||||
Log3 $name, 2, "$iam mower number $mowerNumber not available. Change definition of $name.";
|
Log3 $name, 2, "$iam wrong mower number $mowerNumber ($maxMower mower available). Change definition of $name.";
|
||||||
return undef;
|
return undef;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -442,46 +444,48 @@ sub CMDResponse {
|
|||||||
my $hash = $param->{hash};
|
my $hash = $param->{hash};
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
my $type = $hash->{TYPE};
|
my $type = $hash->{TYPE};
|
||||||
|
my $statuscode = $param->{code};
|
||||||
my $iam = "$type $name CMDResponse:";
|
my $iam = "$type $name CMDResponse:";
|
||||||
|
|
||||||
if($err ne "") {
|
Log3 $name, 1, "\ndebug $iam \n\$statuscode [$statuscode]\n\$err [$err],\n \$data [$data] \n\$param->url $param->{url}" if ( AttrVal($name, 'debug', '') );
|
||||||
readingsSingleUpdate( $hash, 'state', 'error', 1 );
|
|
||||||
Log3 $name, 2, "$iam error while requesting ".$param->{url}." - $err";
|
|
||||||
|
|
||||||
} elsif($data ne "") {
|
if( !$err && $statuscode == 202 && $data ) {
|
||||||
|
|
||||||
my $result = eval { decode_json($data) };
|
my $result = eval { decode_json($data) };
|
||||||
if ($@) {
|
if ($@) {
|
||||||
|
|
||||||
Log3( $name, 2, "$iam - JSON error while request: $@");
|
Log3( $name, 2, "$iam - JSON error while request: $@");
|
||||||
return;
|
|
||||||
}
|
} else {
|
||||||
|
|
||||||
$hash->{helper}{CMDResponse} = $result;
|
$hash->{helper}{CMDResponse} = $result;
|
||||||
if ($result->{message}) {
|
if ($result->{data}) {
|
||||||
readingsSingleUpdate( $hash, 'state', 'error', 1 );
|
|
||||||
Log3 $name, 2, "$iam" . $data;
|
|
||||||
$hash->{helper}->{mower_commandStatus} = $result->{message};
|
|
||||||
|
|
||||||
} elsif ($result->{errors}) {
|
|
||||||
Log3 $name, 2, "$iam" . $data;
|
|
||||||
readingsSingleUpdate( $hash, 'state', 'error', 1 );
|
|
||||||
$hash->{helper}->{mower_commandStatus} = 'ERROR - '. $result->{errors}[0]{title};
|
|
||||||
} elsif ($result->{data}) {
|
|
||||||
Log3 $name, 5, $data;
|
Log3 $name, 5, $data;
|
||||||
if ( ref ($result->{data}) eq 'ARRAY') {
|
if ( ref ($result->{data}) eq 'ARRAY') {
|
||||||
|
|
||||||
$hash->{helper}->{mower_commandStatus} = 'OK - '. $result->{data}[0]{type};
|
$hash->{helper}->{mower_commandStatus} = 'OK - '. $result->{data}[0]{type};
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$hash->{helper}->{mower_commandStatus} = 'OK - '. $result->{data}{type};
|
$hash->{helper}->{mower_commandStatus} = 'OK - '. $result->{data}{type};
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
readingsSingleUpdate($hash, 'mower_commandStatus', $hash->{helper}->{mower_commandStatus} ,1);
|
readingsSingleUpdate($hash, 'mower_commandStatus', $hash->{helper}->{mower_commandStatus} ,1);
|
||||||
|
return undef;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
readingsSingleUpdate($hash, 'mower_commandStatus', "ERROR statuscode $statuscode" ,1);
|
||||||
|
Log3 $name, 2, "\n$iam \n\$statuscode [$statuscode]\n\$err [$err],\n\$data [$data]\n\$param->url $param->{url}";
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
|
||||||
##############################################################
|
##############################################################
|
||||||
sub Get {
|
sub Get {
|
||||||
my ($hash,@val) = @_;
|
my ($hash,@val) = @_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user