diff --git a/fhem/CHANGED b/fhem/CHANGED index 07f00fd5d..81455fabb 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -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. + - bugfix: 74_AutomowerConnect: improved background image loading + Commandref: Hint to connect application key with Automower Connect + API in Developer Portal. - bugfix: 74_AutomowerConnect: prevent division by zero, delay ws init force new access token when set client_secret - change: 74_AutomowerConnect: Common.pm, automowerconnect.js diff --git a/fhem/FHEM/74_AutomowerConnect.pm b/fhem/FHEM/74_AutomowerConnect.pm index a736d10da..ac5688bc8 100644 --- a/fhem/FHEM/74_AutomowerConnect.pm +++ b/fhem/FHEM/74_AutomowerConnect.pm @@ -692,19 +692,24 @@ sub Attr { } elsif ( $attrName eq 'mapImagePath' ) { if( $cmd eq "set") { + if ($attrVal =~ '(webp|png|jpg|jpeg)$' ) { + $hash->{helper}{MAP_PATH} = $attrVal; $hash->{helper}{MAP_MIME} = "image/".$1; + ::FHEM::Devices::AMConnect::Common::readMap( $hash ); - if ($attrVal =~ /(\d+)x(\d+)/) { - CommandAttr($hash,"$name mapImageWidthHeight $1 $2"); + if ( $attrVal =~ /(\d+)x(\d+)/ ) { + $attr{$name}{mapImageWidthHeight} = "$1 $2"; } - ::FHEM::Devices::AMConnect::Common::readMap( $hash ); Log3 $name, 3, "$iam $cmd $attrName $attrVal"; + } else { + return "$iam $cmd $attrName wrong image type, use webp, png, jpeg or jpg"; Log3 $name, 3, "$iam $cmd $attrName wrong image type, use webp, png, jpeg or jpg"; + } } elsif( $cmd eq "del" ) { @@ -763,9 +768,13 @@ sub Attr { my ( $x1, $y1, $x2, $y2 ) = ( $1, $2, $4, $5 ); AttrVal( $name,'mapImageCoordinatesToRegister', '' ) =~ /(-?\d*\.?\d+)\s(-?\d*\.?\d+)(\R|\s)(-?\d*\.?\d+)\s(-?\d*\.?\d+)/; my ( $lo1, $la1, $lo2, $la2 ) = ( $1, $2, $4, $5 ); + + return "$iam $attrName illegal value 0 for the difference of longitudes." unless ( $lo1 - $lo2 ); + return "$iam $attrName illegal value 0 for the difference of latitudes." unless ( $la1 - $la2 ); + my $scx = int( ( $x1 - $x2) / ( $lo1 - $lo2 ) ); my $scy = int( ( $y1 - $y2 ) / ( $la1 - $la2 ) ); - CommandAttr($hash,"$name scaleToMeterXY $scx $scy"); + $attr{$name}{scaleToMeterXY} = "$scx $scy"; } else { return "$iam $attrName has a wrong format use linewise pairs or the attribute mapImageCoordinatesToRegister was not set before."; @@ -929,6 +938,7 @@ __END__
  • To get access to the API an application has to be created in the Husqvarna Developer Portal.
  • During registration an application key (client_id) and an application secret (client secret) is provided. Use these for for the module.
  • +
  • Don't forget to connect you API key to the Automower API.
  • The module uses client credentials as grant type for authorization.

@@ -1010,11 +1020,6 @@ __END__
  • defaultDesignAttributesToAttribute
    set <name> mapZonesTemplateToAttribute
    Load default design attributes.
  • - - -

  • - set <name>
    -



  • @@ -1188,13 +1193,9 @@ __END__ }'
    -
  • disable
  • -
  • disabledForIntervals
  • - - -

  • - attr <name> <>
    -
  • +
  • disable
  • +
  • disabledForIntervals
  • +


    @@ -1254,14 +1255,17 @@ __END__
  • Es ist möglich alles was die API anbietet zu steuern, z.B. Mähplan,Scheinwerfer, Schnitthöhe und Aktionen wie, Start, Pause, Parken usw.
  • Zonen können selbst definiert werden.
  • Die Schnitthöhe kann je selbstdefinierter Zone eingestellt werden.
  • -
  • Die Daten aus der API sind im Gerätehash gespeichert, Mit {Dumper $defs{<device name>}} in der Befehlezeile können die Daten angezeigt werden und daraus userReadings erstellt werden.

  • +
  • Die Daten aus der API sind im Gerätehash gespeichert, Mit {Dumper $defs{<device name>}} in der Befehlezeile können die Daten angezeigt werden und daraus userReadings erstellt werden.
  • +
    Anforderungen

    • Für den Zugriff auf die API muss eine Application angelegt werden, im Husqvarna Developer Portal.
    • Währenddessen wird ein Application Key (client_id) und ein Application Secret (client secret) bereitgestellt. Diese sind für dieses Modul zu nutzen.
    • +
    • Der Application Key muss im Portal mit der Automower API verbunden werden.
    • Das Modul nutzt Client Credentials als Granttype zur Authorisierung.
    • +

    @@ -1272,7 +1276,7 @@ __END__ define myMower AutomowerConnect 123456789012345678901234567890123456 Erstes Gerät: die Defaultmähernummer ist 0.
    Es muss ein client_secret gesetzt werden. Es ist das Application Secret vom Husqvarna Developer Portal.
    set myMower <client secret>
    -

    +

    @@ -1342,10 +1346,9 @@ __END__
  • defaultDesignAttributesToAttribute
    set <name> mapZonesTemplateToAttribute
    Läd die Standartdesignattribute.
  • - -

  • - set <name>
    -
  • +
    + +
    Get @@ -1375,12 +1378,10 @@ __END__
  • errorStack
    get <name> errorStack
    Listet die gespeicherten Fehler auf.
  • -

    +

    - -
    Attributes
    diff --git a/fhem/lib/FHEM/Devices/AMConnect/Common.pm b/fhem/lib/FHEM/Devices/AMConnect/Common.pm index 8e9945f50..588ae3c73 100644 --- a/fhem/lib/FHEM/Devices/AMConnect/Common.pm +++ b/fhem/lib/FHEM/Devices/AMConnect/Common.pm @@ -181,9 +181,6 @@ my $mapZonesTpl = '{ newzonedatasets => 0, positionsTime => 0, statusTime => 0, - MAP_PATH => '', - MAP_MIME => '', - MAP_CACHE => '', cspos => [], areapos => [], errorstack => [], @@ -280,18 +277,29 @@ my $mapZonesTpl = '{ AddExtension( $name, \&GetMap, "$type/$name/map" ); + if ( $::init_done ) { + + my $attrVal = $attr{$name}{mapImagePath}; + + if ($attrVal =~ '(webp|png|jpg|jpeg)$' ) { + + $hash->{helper}{MAP_PATH} = $attrVal; + $hash->{helper}{MAP_MIME} = "image/".$1; + readMap( $hash ); + + } + + } + if( $hash->{helper}->{passObj}->getReadPassword($name) ) { RemoveInternalTimer($hash); InternalTimer( gettimeofday() + 2, \&::FHEM::AutomowerConnect::APIAuth, $hash, 1); - InternalTimer( gettimeofday() + 20, \&readMap, $hash, 0); - DevIo_setStates( $hash, "disconnected" ); readingsSingleUpdate( $hash, 'device_state', 'defined', 1 ); } else { - DevIo_setStates( $hash, "disconnected" ); readingsSingleUpdate( $hash, 'device_state', 'defined - client_secret missing', 1 ); } @@ -1033,23 +1041,31 @@ sub readMap { my $name = $hash->{NAME}; my $type = $hash->{TYPE}; my $iam = "$type $name readMap:"; - RemoveInternalTimer( $hash, \&::FHEM::Devices::AMConnect::Common::readMap ); my $filename = $hash->{helper}{MAP_PATH}; - + if ( $filename and -e $filename ) { + open my $fh, '<:raw', $filename or die $!; my $content = ''; + while (1) { + my $success = read $fh, $content, 1024, length($content); die $! if not defined $success; last if not $success; + } + close $fh; $hash->{helper}{MAP_CACHE} = $content; Log3 $name, 5, "$iam file \"$filename\" content length: ".length($content); + } else { + Log3 $name, 2, "$iam file \"$filename\" does not exist."; + } + } #########################