2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 09:16:53 +00:00

70_BOTVAC.pm: transient map cache

git-svn-id: https://svn.fhem.de/fhem/trunk@24253 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
vuffiraa 2021-04-14 18:50:54 +00:00
parent b076360511
commit 0e083401cc
2 changed files with 40 additions and 37 deletions

View File

@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # 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. # Do not insert empty lines here, update check depends on it.
- bugfix: 70_BOTVAC: transient map cache
- bugfix: 73_DoorBird: Event Video Routine - bugfix: 73_DoorBird: Event Video Routine
- bugfix: 73_ElectricityCalculator: Bugfix - Midnight-Crash - bugfix: 73_ElectricityCalculator: Bugfix - Midnight-Crash
- bugfix: 73_WaterCalculator: Bugfix - Midnight-Crash - bugfix: 73_WaterCalculator: Bugfix - Midnight-Crash

View File

@ -251,8 +251,8 @@ sub Get {
} }
} }
elsif ( $what =~ /^(statistics)$/x ) { elsif ( $what =~ /^(statistics)$/x ) {
if ( defined( $hash->{helper}{MAPS} ) if ( defined( $hash->{Helper}{MAPS} )
and @{ $hash->{helper}{MAPS} } > 0 ) and @{ $hash->{Helper}{MAPS} } > 0 )
{ {
return GetStatistics($hash); return GetStatistics($hash);
} }
@ -368,7 +368,7 @@ sub Set {
} }
# manual cleaning # manual cleaning
if ( $hash->{HELPER}{WEBSOCKETS} ) { if ( $hash->{Helper}{WEBSOCKETS} ) {
$usage .= $usage .=
" wsCommand:brush-on,brush-off,eco-on,eco-off,turbo-on,turbo-off,vacuum-on,vacuum-off"; " wsCommand:brush-on,brush-off,eco-on,eco-off,turbo-on,turbo-off,vacuum-on,vacuum-off";
$usage .= $usage .=
@ -376,8 +376,8 @@ sub Set {
} }
my @robots; my @robots;
if ( defined( $hash->{helper}{ROBOTS} ) ) { if ( defined( $hash->{Helper}{ROBOTS} ) ) {
@robots = @{ $hash->{helper}{ROBOTS} }; @robots = @{ $hash->{Helper}{ROBOTS} };
if ( @robots > 1 ) { if ( @robots > 1 ) {
$usage .= " setRobot:"; $usage .= " setRobot:";
for ( my $i = 0 ; $i < @robots ; $i++ ) { for ( my $i = 0 ; $i < @robots ; $i++ ) {
@ -391,8 +391,8 @@ sub Set {
or GetServiceVersion( $hash, "maps" ) eq "basic-2" or GetServiceVersion( $hash, "maps" ) eq "basic-2"
or GetServiceVersion( $hash, "maps" ) eq "macro-1" ) or GetServiceVersion( $hash, "maps" ) eq "macro-1" )
{ {
if ( defined( $hash->{helper}{BoundariesList} ) ) { if ( defined( $hash->{Helper}{BoundariesList} ) ) {
my @Boundaries = @{ $hash->{helper}{BoundariesList} }; my @Boundaries = @{ $hash->{Helper}{BoundariesList} };
my @names; my @names;
for ( my $i = 0 ; $i < @Boundaries ; $i++ ) { for ( my $i = 0 ; $i < @Boundaries ; $i++ ) {
my $boundaryName = $Boundaries[$i]->{name}; my $boundaryName = $Boundaries[$i]->{name};
@ -456,7 +456,7 @@ sub Set {
elsif ( $a[1] eq "stop" ) { elsif ( $a[1] eq "stop" ) {
Log3( $name, 2, "BOTVAC set $name $arg" ); Log3( $name, 2, "BOTVAC set $name $arg" );
if ( $hash->{HELPER}{WEBSOCKETS} ) { if ( $hash->{Helper}{WEBSOCKETS} ) {
wsClose($hash); wsClose($hash);
} }
else { else {
@ -584,9 +584,9 @@ sub Set {
if ( $a[2] =~ /^\{.*\}/x ) { if ( $a[2] =~ /^\{.*\}/x ) {
$setBoundaries = $a[2]; $setBoundaries = $a[2];
} }
elsif ( defined( $hash->{helper}{BoundariesList} ) ) { elsif ( defined( $hash->{Helper}{BoundariesList} ) ) {
my @names = split ",", $a[2]; my @names = split ",", $a[2];
my @Boundaries = @{ $hash->{helper}{BoundariesList} }; my @Boundaries = @{ $hash->{Helper}{BoundariesList} };
for ( my $i = 0 ; $i < @Boundaries ; $i++ ) { for ( my $i = 0 ; $i < @Boundaries ; $i++ ) {
foreach my $name (@names) { foreach my $name (@names) {
if ( $Boundaries[$i]->{name} eq $name ) { if ( $Boundaries[$i]->{name} eq $name ) {
@ -768,12 +768,12 @@ sub Attr {
else { else {
push @areas, eval { decode_json $attr_value}; push @areas, eval { decode_json $attr_value};
} }
$hash->{helper}{BoundariesList} = \@areas; $hash->{Helper}{BoundariesList} = \@areas;
} }
} }
} }
else { else {
delete $hash->{helper}{BoundariesList} delete $hash->{Helper}{BoundariesList}
if ( $attr_name eq "boundaries" ); if ( $attr_name eq "boundaries" );
} }
return $err ? $err : undef; return $err ? $err : undef;
@ -1122,9 +1122,9 @@ sub SendCommand {
}; };
if ($keepalive) { if ($keepalive) {
map { $hash->{helper}{".HTTP_CONNECTION"}{$_} = $params->{$_} } map { $hash->{Helper}{".HTTP_CONNECTION"}{$_} = $params->{$_} }
keys %{$params}; keys %{$params};
::HttpUtils_NonblockingGet( $hash->{helper}{".HTTP_CONNECTION"} ); ::HttpUtils_NonblockingGet( $hash->{Helper}{".HTTP_CONNECTION"} );
} }
else { else {
::HttpUtils_NonblockingGet($params); ::HttpUtils_NonblockingGet($params);
@ -1658,7 +1658,7 @@ sub ReceiveCommand {
push( @robotList, $r ); push( @robotList, $r );
} }
$hash->{helper}{ROBOTS} = \@robotList; $hash->{Helper}{ROBOTS} = \@robotList;
if (@robotList) { if (@robotList) {
SetRobot( $hash, ReadingsNum( $name, "robot", 0 ) ); SetRobot( $hash, ReadingsNum( $name, "robot", 0 ) );
push( @successor, [ "robots", "maps" ] ); push( @successor, [ "robots", "maps" ] );
@ -1689,7 +1689,7 @@ sub ReceiveCommand {
}; };
push( @robotList, $r ); push( @robotList, $r );
} }
$hash->{helper}{ROBOTS} = \@robotList; $hash->{Helper}{ROBOTS} = \@robotList;
if (@robotList) { if (@robotList) {
# follow registration procedure first # follow registration procedure first
unshift( @successor, [ 'firmwares' ] ); unshift( @successor, [ 'firmwares' ] );
@ -1706,7 +1706,7 @@ sub ReceiveCommand {
#firmwares #firmwares
elsif ( $service eq 'firmwares' ) { elsif ( $service eq 'firmwares' ) {
if ( ref($return) eq 'HASH' ) { if ( ref($return) eq 'HASH' ) {
my @robotList = @{ $hash->{helper}{ROBOTS} }; my @robotList = @{ $hash->{Helper}{ROBOTS} };
foreach my $r ( @robotList ) { foreach my $r ( @robotList ) {
my $firmware = $return->{ $r->{model} }; my $firmware = $return->{ $r->{model} };
$r->{recentFirmware} = $firmware->{version} if defined($firmware); $r->{recentFirmware} = $firmware->{version} if defined($firmware);
@ -1724,7 +1724,7 @@ sub ReceiveCommand {
if ( ref($return) eq "HASH" ) { if ( ref($return) eq "HASH" ) {
if ( ref( $return->{maps} ) eq "ARRAY" ) { if ( ref( $return->{maps} ) eq "ARRAY" ) {
my @maps = @{ $return->{maps} }; my @maps = @{ $return->{maps} };
$hash->{helper}{MAPS} = $return->{maps}; $hash->{Helper}{MAPS} = $return->{maps};
if (@maps) { if (@maps) {
# take first - newest # take first - newest
@ -1824,7 +1824,7 @@ sub ReceiveCommand {
# loadmap # loadmap
elsif ( $service eq "loadmap" ) { elsif ( $service eq "loadmap" ) {
readingsBulkUpdate( $hash, ".map_cache", $data ); $hash->{Helper}{'.MAP_CACHE'} = $data;
} }
# requestVerification # requestVerification
@ -1875,12 +1875,12 @@ sub ReceiveCommand {
readingsEndUpdate( $hash, 1 ); readingsEndUpdate( $hash, 1 );
if ( defined( $hash->{helper}{".HTTP_CONNECTION"} ) if ( defined( $hash->{Helper}{".HTTP_CONNECTION"} )
and ( ( $keepalive && $closeConnection ) || !@successor ) ) and ( ( $keepalive && $closeConnection ) || !@successor ) )
{ {
Log3( $name, 4, "BOTVAC $name: Close connection" ); Log3( $name, 4, "BOTVAC $name: Close connection" );
::HttpUtils_Close( $hash->{helper}{".HTTP_CONNECTION"} ); ::HttpUtils_Close( $hash->{Helper}{".HTTP_CONNECTION"} );
undef( $hash->{helper}{".HTTP_CONNECTION"} ); undef( $hash->{Helper}{".HTTP_CONNECTION"} );
} }
if ($loadMap) { if ($loadMap) {
@ -1949,7 +1949,7 @@ sub SetRobot {
Log3( $name, 4, "BOTVAC $name: set active robot $robot" ); Log3( $name, 4, "BOTVAC $name: set active robot $robot" );
my @robots = @{ $hash->{helper}{ROBOTS} }; my @robots = @{ $hash->{Helper}{ROBOTS} };
readingsBulkUpdateIfChanged( $hash, "serial", $robots[$robot]->{serial} ); readingsBulkUpdateIfChanged( $hash, "serial", $robots[$robot]->{serial} );
readingsBulkUpdateIfChanged( $hash, "name", $robots[$robot]->{name} ); readingsBulkUpdateIfChanged( $hash, "name", $robots[$robot]->{name} );
readingsBulkUpdateIfChanged( $hash, "model", $robots[$robot]->{model} ); readingsBulkUpdateIfChanged( $hash, "model", $robots[$robot]->{model} );
@ -2380,8 +2380,10 @@ sub GetMap() {
my $name = $1; my $name = $1;
my $width = $3; my $width = $3;
my $height = $5; my $height = $5;
my $hash = $::defs{$name};
return ( "image/png", ReadingsVal( $name, ".map_cache", "" ) ); my $mapData = defined($hash->{Helper}{'.MAP_CACHE'}) ? $hash->{Helper}{'.MAP_CACHE'} : '';
return ( "image/png", $mapData );
} }
return ( "text/plain; charset=utf-8", return ( "text/plain; charset=utf-8",
@ -2394,8 +2396,8 @@ sub ShowStatistics {
my $hash = $::defs{$name}; my $hash = $::defs{$name};
return "maps for statistics are not available yet" return "maps for statistics are not available yet"
if ( !defined( $hash->{helper}{MAPS} ) if ( !defined( $hash->{Helper}{MAPS} )
|| @{ $hash->{helper}{MAPS} } == 0 ); || @{ $hash->{Helper}{MAPS} } == 0 );
return GetStatistics($hash); return GetStatistics($hash);
} }
@ -2403,7 +2405,7 @@ sub ShowStatistics {
sub GetStatistics { sub GetStatistics {
my ($hash) = @_; my ($hash) = @_;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $mapcount = @{ $hash->{helper}{MAPS} }; my $mapcount = @{ $hash->{Helper}{MAPS} };
my $model = ReadingsVal( $name, "model", "" ); my $model = ReadingsVal( $name, "model", "" );
my $ret = ""; my $ret = "";
@ -2460,7 +2462,7 @@ sub GetStatistics {
$ret .= '</tr>'; $ret .= '</tr>';
for ( my $i = 0 ; $i < $mapcount ; $i++ ) { for ( my $i = 0 ; $i < $mapcount ; $i++ ) {
my $map = \$hash->{helper}{MAPS}[$i]; my $map = \$hash->{Helper}{MAPS}[$i];
my $t1 = GetSecondsFromString( $$map->{end_at} ); my $t1 = GetSecondsFromString( $$map->{end_at} );
my $t2 = GetSecondsFromString( $$map->{start_at} ); my $t2 = GetSecondsFromString( $$map->{start_at} );
my $dt = my $dt =
@ -2579,8 +2581,8 @@ sub wsClose {
Log3( $name, 4, "BOTVAC(ws) $name: Closing socket connection" ); Log3( $name, 4, "BOTVAC(ws) $name: Closing socket connection" );
wsEncode( $hash, $normal_closure, "close" ); wsEncode( $hash, $normal_closure, "close" );
delete $hash->{HELPER}{WEBSOCKETS}; delete $hash->{Helper}{WEBSOCKETS};
delete $hash->{HELPER}{wsKey}; delete $hash->{Helper}{wsKey};
readingsSingleUpdate( $hash, 'state', 'ws_closed', 1 ) readingsSingleUpdate( $hash, 'state', 'ws_closed', 1 )
if ( ::DevIo_CloseDev($hash) ); if ( ::DevIo_CloseDev($hash) );
@ -2615,7 +2617,7 @@ sub wsHandshake {
Log3( $name, 4, "BOTVAC(ws) $name: Starting Websocket Handshake" ); Log3( $name, 4, "BOTVAC(ws) $name: Starting Websocket Handshake" );
wsWrite( $hash, $wsHandshakeCmd ); wsWrite( $hash, $wsHandshakeCmd );
$hash->{HELPER}{wsKey} = $wsKey; $hash->{Helper}{wsKey} = $wsKey;
return; return;
} }
@ -2638,7 +2640,7 @@ sub wsCheckHandshake {
if ( defined( $header{'sec-websocket-accept'} ) ) { if ( defined( $header{'sec-websocket-accept'} ) ) {
my $keyAccept = $header{'sec-websocket-accept'}; my $keyAccept = $header{'sec-websocket-accept'};
Log3( $name, 5, "BOTVAC(ws) $name: keyAccept: $keyAccept" ); Log3( $name, 5, "BOTVAC(ws) $name: keyAccept: $keyAccept" );
my $wsKey = $hash->{HELPER}{wsKey}; my $wsKey = $hash->{Helper}{wsKey};
my $expectedResponse = trim( my $expectedResponse = trim(
encode_base64( encode_base64(
pack( pack(
@ -2654,7 +2656,7 @@ sub wsCheckHandshake {
"BOTVAC(ws) $name: Successful WS connection to $hash->{DeviceName}" "BOTVAC(ws) $name: Successful WS connection to $hash->{DeviceName}"
); );
readingsSingleUpdate( $hash, 'state', 'ws_connected', 1 ); readingsSingleUpdate( $hash, 'state', 'ws_connected', 1 );
$hash->{HELPER}{WEBSOCKETS} = '1'; $hash->{Helper}{WEBSOCKETS} = '1';
} }
else { else {
wsClose($hash); wsClose($hash);
@ -2688,7 +2690,7 @@ sub wsRead {
return Log3( $name, 3, "BOTVAC(ws) $name: no data received" ) return Log3( $name, 3, "BOTVAC(ws) $name: no data received" )
unless ( defined $buf ); unless ( defined $buf );
if ( $hash->{HELPER}{WEBSOCKETS} ) { if ( $hash->{Helper}{WEBSOCKETS} ) {
Log3( $name, 4, Log3( $name, 4,
"BOTVAC(ws) $name: received data, start response processing:\n" "BOTVAC(ws) $name: received data, start response processing:\n"
. sprintf( "%v02X", $buf ) ); . sprintf( "%v02X", $buf ) );
@ -2719,9 +2721,9 @@ sub wsCallback {
Log3( $name, 5, "received callback with:\n$data" ); Log3( $name, 5, "received callback with:\n$data" );
my $parser = $param->{parser}; my $parser = $param->{parser};
&$parser( $hash, $data ); &$parser( $hash, $data );
asyncOutput( $hash->{HELPER}{CLCONF}, $data ) asyncOutput( $hash->{Helper}{CLCONF}, $data )
if $hash->{HELPER}{CLCONF}; if $hash->{Helper}{CLCONF};
delete $hash->{HELPER}{CLCONF}; delete $hash->{Helper}{CLCONF};
} }
else { else {
Log3( $name, 2, "received callback without Data and Error String!!!" ); Log3( $name, 2, "received callback without Data and Error String!!!" );