From 01e1a0df6708aeab4364bbcaada81d008a9b0ab0 Mon Sep 17 00:00:00 2001 From: Ellert <> Date: Sun, 25 Jun 2023 11:44:25 +0000 Subject: [PATCH] 74_AutomowerConnect: Common.pm, automowerconnect.js, fix problem with empty positions array, java script cleanup git-svn-id: https://svn.fhem.de/fhem/trunk@27706 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 2 + fhem/lib/FHEM/Devices/AMConnect/Common.pm | 143 +++++++++++----------- fhem/www/pgm2/automowerconnect.js | 128 +++++++++---------- 3 files changed, 132 insertions(+), 141 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index dd90000cf..63c432a71 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,7 @@ # 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. + - bugfix: 74_AutomowerConnect: Common.pm, automowerconnect.js, fix promlem + with empty positions array - feature: 74_AutomowerConnect: Common.pm, add additional API polling - feature: 76_SMAInverter: bugfix DC-Power - change: 74_AutomowerConnect: Common.pm, automowerconnect.js diff --git a/fhem/lib/FHEM/Devices/AMConnect/Common.pm b/fhem/lib/FHEM/Devices/AMConnect/Common.pm index de2eb249d..ee893e9d5 100644 --- a/fhem/lib/FHEM/Devices/AMConnect/Common.pm +++ b/fhem/lib/FHEM/Devices/AMConnect/Common.pm @@ -195,6 +195,7 @@ my $mapZonesTpl = '{ maxLat => -90, imageHeight => 650, imageWidthHeight => '350 650', + map_init_delay => 2, mapdesign => $mapAttr, mapZonesTpl => $mapZonesTpl, posMinMax => "-180 90\n180 -90", @@ -447,87 +448,82 @@ sub FW_detailFn { my $type = $hash->{TYPE}; return '' if( AttrVal($name, 'disable', 0) || !AttrVal($name, 'showMap', 1) ); - if ( $hash->{helper} && $hash->{helper}{mower} && $hash->{helper}{mower}{attributes} && $hash->{helper}{mower}{attributes}{positions} && @{$hash->{helper}{mower}{attributes}{positions}} > 0 ) { + my $img = "$FW_ME/$type/$name/map"; + my $zoom=AttrVal( $name,"mapImageZoom", 0.7 ); + my $backgroundcolor = AttrVal($name, 'mapBackgroundColor',''); + my $bgstyle = $backgroundcolor ? " background-color:$backgroundcolor;" : ''; + my $design = AttrVal( $name, 'mapDesignAttributes', $hash->{helper}{mapdesign} ); + my @adesign = split(/\R/,$design); + my $mapDesign = 'data-'.join("data-",@adesign); - my $img = "$FW_ME/$type/$name/map"; - my $zoom=AttrVal( $name,"mapImageZoom", 0.7 ); - my $backgroundcolor = AttrVal($name, 'mapBackgroundColor',''); - my $bgstyle = $backgroundcolor ? " background-color:$backgroundcolor;" : ''; - my $design = AttrVal( $name, 'mapDesignAttributes', $hash->{helper}{mapdesign} ); - my @adesign = split(/\R/,$design); - my $mapDesign = 'data-'.join("data-",@adesign); + my ($picx,$picy) = AttrVal( $name,"mapImageWidthHeight", $hash->{helper}{imageWidthHeight} ) =~ /(\d+)\s(\d+)/; + $picx=int($picx*$zoom); + $picy=int($picy*$zoom); - my ($picx,$picy) = AttrVal( $name,"mapImageWidthHeight", $hash->{helper}{imageWidthHeight} ) =~ /(\d+)\s(\d+)/; - $picx=int($picx*$zoom); - $picy=int($picy*$zoom); + my ( $lonlo, $latlo, $dummy, $lonru, $latru ) = AttrVal( $name,"mapImageCoordinatesToRegister",$hash->{helper}{posMinMax} ) =~ /(-?\d*\.?\d+)\s(-?\d*\.?\d+)(\R|\s)(-?\d*\.?\d+)\s(-?\d*\.?\d+)/; + my $mapx = $lonlo-$lonru; + my $mapy = $latlo-$latru; - my ( $lonlo, $latlo, $dummy, $lonru, $latru ) = AttrVal( $name,"mapImageCoordinatesToRegister",$hash->{helper}{posMinMax} ) =~ /(-?\d*\.?\d+)\s(-?\d*\.?\d+)(\R|\s)(-?\d*\.?\d+)\s(-?\d*\.?\d+)/; - my $mapx = $lonlo-$lonru; - my $mapy = $latlo-$latru; + AttrVal($name,'scaleToMeterXY', $hash->{helper}{scaleToMeterLongitude} . ' ' .$hash->{helper}{scaleToMeterLatitude}) =~ /(-?\d+)\s+(-?\d+)/; + my $scalx = ( $lonru - $lonlo ) * $1; + my $scaly = ( $latlo - $latru ) * $2; - AttrVal($name,'scaleToMeterXY', $hash->{helper}{scaleToMeterLongitude} . ' ' .$hash->{helper}{scaleToMeterLatitude}) =~ /(-?\d+)\s+(-?\d+)/; - my $scalx = ( $lonru - $lonlo ) * $1; - my $scaly = ( $latlo - $latru ) * $2; + # CHARGING STATION POSITION + my $csimgpos = AttrVal( $name,"chargingStationImagePosition","right" ); + my $xm = $hash->{helper}{chargingStation}{longitude} // 10.1165; + my $ym = $hash->{helper}{chargingStation}{latitude} // 51.28; - # CHARGING STATION POSITION - my $csimgpos = AttrVal( $name,"chargingStationImagePosition","right" ); - my $xm = $hash->{helper}{chargingStation}{longitude} // 10.1165; - my $ym = $hash->{helper}{chargingStation}{latitude} // 51.28; + my ($cslo,$csla) = AttrVal( $name,"chargingStationCoordinates","$xm $ym" ) =~ /(-?\d*\.?\d+)\s(-?\d*\.?\d+)/; + my $cslon = int(($lonlo-$cslo) * $picx / $mapx); + my $cslat = int(($latlo-$csla) * $picy / $mapy); + my $csdata = 'data-csimgpos="'.$csimgpos.'" data-cslon="'.$cslon.'" data-cslat="'.$cslat.'"'; - my ($cslo,$csla) = AttrVal( $name,"chargingStationCoordinates","$xm $ym" ) =~ /(-?\d*\.?\d+)\s(-?\d*\.?\d+)/; - my $cslon = int(($lonlo-$cslo) * $picx / $mapx); - my $cslat = int(($latlo-$csla) * $picy / $mapy); - my $csdata = 'data-csimgpos="'.$csimgpos.'" data-cslon="'.$cslon.'" data-cslat="'.$cslat.'"'; - - # AREA LIMITS - my $arealimits = AttrVal($name,'mowingAreaLimits',''); - my $limi = ''; - if ($arealimits) { - my @lixy = (split(/\s|,|\R$/,$arealimits)); - $limi = int( ( $lonlo - $lixy[ 0 ] ) * $picx / $mapx ) . "," . int( ( $latlo - $lixy[ 1 ] ) * $picy / $mapy ); - for (my $i=2;$i<@lixy;$i+=2){ - $limi .= ",".int( ( $lonlo - $lixy[ $i ] ) * $picx / $mapx).",".int( ( $latlo-$lixy[$i+1] ) * $picy / $mapy); - } + # AREA LIMITS + my $arealimits = AttrVal($name,'mowingAreaLimits',''); + my $limi = ''; + if ($arealimits) { + my @lixy = (split(/\s|,|\R$/,$arealimits)); + $limi = int( ( $lonlo - $lixy[ 0 ] ) * $picx / $mapx ) . "," . int( ( $latlo - $lixy[ 1 ] ) * $picy / $mapy ); + for (my $i=2;$i<@lixy;$i+=2){ + $limi .= ",".int( ( $lonlo - $lixy[ $i ] ) * $picx / $mapx).",".int( ( $latlo-$lixy[$i+1] ) * $picy / $mapy); } - $limi = 'data-areaLimitsPath="'.$limi.'"'; - - # PROPERTY LIMITS - my $propertylimits = AttrVal($name,'propertyLimits',''); - my $propli = ''; - if ($propertylimits) { - my @propxy = (split(/\s|,|\R$/,$propertylimits)); - $propli = int(($lonlo-$propxy[0]) * $picx / $mapx).",".int(($latlo-$propxy[1]) * $picy / $mapy); - for (my $i=2;$i<@propxy;$i+=2){ - $propli .= ",".int(($lonlo-$propxy[$i]) * $picx / $mapx).",".int(($latlo-$propxy[$i+1]) * $picy / $mapy); - } - } - $propli = 'data-propertyLimitsPath="'.$propli.'"'; - - my $ret = ""; - $ret .= ""; - $ret .= "