2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 06:39:11 +00:00

74_AutomowerConnect: Common.pm pervent JSON decoding error if more than one complete JSON string is in DevIo buffer, addPositionPolling is only settable if addPollingMinInterval > 0

git-svn-id: https://svn.fhem.de/fhem/trunk@27820 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
Ellert 2023-08-05 17:00:54 +00:00
parent 0b43dafafc
commit d354654e85
2 changed files with 91 additions and 72 deletions

View File

@ -1,5 +1,8 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it.
- change: 74_AutomowerConnect: Common.pm pervent JSON decoding error if more
than one complete JSON string is in DevIo buffer,
addPositionPolling is only settable if addPollingMinInterval > 0
- feature: 72_FB_CALLMONITOR: das Oertliche repariert.
- feature: 72_FRITZBOX: reconnect nach Netzwerk/FB Ausfall.
Neues Attribut: reConnect_Interval

View File

@ -1384,11 +1384,21 @@ sub Attr {
$hash->{helper}{additional_polling} = $attrVal;
Log3 $name, 4, "$iam $cmd $attrName $attrVal";
if ( $attrVal == 0 ) {
delete $attr{$name}{addPositionPolling} if ( defined( $attr{$name}{addPositionPolling} ) );
$hash->{helper}{use_position_polling} = 0;
}
} elsif( $cmd eq "del" ) {
$hash->{helper}{additional_polling} = 0;
readingsDelete( $hash, 'api_callsThisMonth' );
Log3 $name, 3, "$iam $cmd $attrName and set default value 0.";
delete $attr{$name}{addPositionPolling} if ( defined( $attr{$name}{addPositionPolling} ) );
$hash->{helper}{use_position_polling} = 0;
}
##########
@ -1397,6 +1407,7 @@ sub Attr {
if( $cmd eq "set" ) {
return "$iam $attrVal is invalid, allowed value 0 or 1." unless( $attrVal == 0 || $attrVal == 1 );
return "$iam $attrVal set attribute addPollingMinInterval > 0 first." unless( defined( $attr{$name}{addPollingMinInterval} ) && $attr{$name}{addPollingMinInterval} > 0 );
$hash->{helper}{use_position_polling} = $attrVal;
Log3 $name, 4, "$iam $cmd $attrName $attrVal";
@ -2561,12 +2572,15 @@ sub wsRead {
my $additional_polling = $hash->{helper}{additional_polling} * 1000;
my $use_position_polling = $hash->{helper}{use_position_polling};
my $buf = DevIo_SimpleRead( $hash );
return "" if ( !defined( $buf ) );
return undef if ( !defined( $buf ) );
Log3 $name, 4, "$iam received websocket data: >$buf<";
if ( $buf ) {
my $result = eval { decode_json( $buf ) };
$buf =~ s/}\{/},{/g;
$buf = "[${buf}]";
my $bufres = eval { decode_json( $buf ) };
if ( $@ ) {
@ -2574,11 +2588,13 @@ sub wsRead {
} else {
for my $result (@$bufres) {
if ( !defined( $result->{type} ) ) {
$hash->{helper}{wsResult}{other} = dclone( $result );
if ( $result =~ /^{"ready":false/ ) {
if ( defined( $result->{ready} ) && !$result->{ready} ) {
readingsSingleUpdate( $hash, 'mower_wsEvent', 'not ready', 1);
$hash->{helper}{retry_interval_wsreopen} = 420;
@ -2621,11 +2637,10 @@ sub wsRead {
) ) && !$hash->{helper}{midnightCycle} ) {
$hash->{helper}{storesum} = 0;
# RemoveInternalTimer( $hash, \&getMowerWs );
# InternalTimer(gettimeofday() + 2, \&getMowerWs, $hash, 0 );
getMowerWs( $hash );
$hash->{First_Read} = 0;
return;
RemoveInternalTimer( $hash, \&getMowerWs );
InternalTimer(gettimeofday() + 1, \&getMowerWs, $hash, 0 );
# getMowerWs( $hash );
next;
}
@ -2633,7 +2648,7 @@ sub wsRead {
if ( $result->{type} eq "positions-event" ) {
if ( !$use_position_polling || $use_position_polling && !$additional_polling ) {
if ( !$use_position_polling ) {
$hash->{helper}{positionsTime} = gettimeofday();
$hash->{helper}{mower}{attributes}{positions} = dclone( $result->{attributes}{positions} );
@ -2641,10 +2656,9 @@ sub wsRead {
AlignArray( $hash );
FW_detailFn_Update ($hash);
} elsif ( $use_position_polling && $additional_polling ) {
} elsif ( $use_position_polling ) {
$hash->{First_Read} = 0;
return;
next;
}
@ -2672,6 +2686,8 @@ sub wsRead {
}
}
$hash->{First_Read} = 0;
return;