From 8263bd2911f53f987b4798d5f87e9b54b1f3c927 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Tue, 9 Mar 2021 08:46:11 +0100 Subject: [PATCH 1/8] fix undefined value as an ARRAY reference --- 73_GardenaSmartBridge.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/73_GardenaSmartBridge.pm b/73_GardenaSmartBridge.pm index df1431c..d1f4d5f 100644 --- a/73_GardenaSmartBridge.pm +++ b/73_GardenaSmartBridge.pm @@ -829,7 +829,8 @@ sub WriteReadings { } readingsBulkUpdateIfChanged( $hash, 'zones', - scalar( @{ $decode_json->{zones} } ) ); + scalar( @{ $decode_json->{zones} } ) ) + if ( ref($decode_json->{zones}) eq 'ARRAY' ); } elsif ($decode_json->{id} ne $hash->{helper}{locations_id} && ref( $decode_json->{abilities} ) eq 'ARRAY' @@ -1376,7 +1377,7 @@ sub DeletePassword { ], "release_status": "stable", "license": "GPL_2", - "version": "v2.0.3", + "version": "v2.0.4", "author": [ "Marko Oldenburg " ], -- 2.49.0 From 93e740956eaab75d06c8a155048a946e53a17650 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Tue, 9 Mar 2021 08:50:59 +0100 Subject: [PATCH 2/8] change git structure --- .../73_GardenaSmartBridge.pm | 0 .../74_GardenaSmartDevice.pm | 0 controls_GardenaSmartDevice.txt | 2 + hooks/pre-commit | 40 +++++++++++++++++++ 4 files changed, 42 insertions(+) rename 73_GardenaSmartBridge.pm => FHEM/73_GardenaSmartBridge.pm (100%) rename 74_GardenaSmartDevice.pm => FHEM/74_GardenaSmartDevice.pm (100%) create mode 100644 controls_GardenaSmartDevice.txt create mode 100755 hooks/pre-commit diff --git a/73_GardenaSmartBridge.pm b/FHEM/73_GardenaSmartBridge.pm similarity index 100% rename from 73_GardenaSmartBridge.pm rename to FHEM/73_GardenaSmartBridge.pm diff --git a/74_GardenaSmartDevice.pm b/FHEM/74_GardenaSmartDevice.pm similarity index 100% rename from 74_GardenaSmartDevice.pm rename to FHEM/74_GardenaSmartDevice.pm diff --git a/controls_GardenaSmartDevice.txt b/controls_GardenaSmartDevice.txt new file mode 100644 index 0000000..551752c --- /dev/null +++ b/controls_GardenaSmartDevice.txt @@ -0,0 +1,2 @@ +UPD 2021-03-09_08:45:53 42674 FHEM/73_GardenaSmartBridge.pm +UPD 2020-05-01_22:05:14 45622 FHEM/74_GardenaSmartDevice.pm diff --git a/hooks/pre-commit b/hooks/pre-commit new file mode 100755 index 0000000..deda783 --- /dev/null +++ b/hooks/pre-commit @@ -0,0 +1,40 @@ +#!/usr/bin/perl -w + +use File::Basename; +use POSIX qw(strftime); +use strict; + +my @filenames = ( + 'FHEM/73_GardenaSmartBridge.pm', + 'FHEM/74_GardenaSmartDevice.pm', +); + +my $controlsfile = 'controls_GardenaSmartDevice.txt'; + +open(FH, ">$controlsfile") || return("Can't open $controlsfile: $!"); + +for my $filename (@filenames) { + my @statOutput = stat($filename); + + if (scalar @statOutput != 13) { + printf 'error: stat has unexpected return value for ' . $filename . "\n"; + next; + } + + my $mtime = $statOutput[9]; + my $date = POSIX::strftime("%Y-%m-%d", localtime($mtime)); + my $time = POSIX::strftime("%H:%M:%S", localtime($mtime)); + my $filetime = $date."_".$time; + + my $filesize = $statOutput[7]; + + printf FH 'UPD ' . $filetime . ' ' . $filesize . ' ' .$filename . "\n"; +} + +close(FH); + +system("git add $controlsfile"); + +print 'Create controls File succesfully' . "\n"; + +exit 0; -- 2.49.0 From 929571b198c6a1cc08bebca580f7a3fc36e6824f Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Wed, 10 Mar 2021 16:13:39 +0100 Subject: [PATCH 3/8] add debug logging --- FHEM/73_GardenaSmartBridge.pm | 5 +++++ controls_GardenaSmartDevice.txt | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/FHEM/73_GardenaSmartBridge.pm b/FHEM/73_GardenaSmartBridge.pm index d1f4d5f..60519c3 100644 --- a/FHEM/73_GardenaSmartBridge.pm +++ b/FHEM/73_GardenaSmartBridge.pm @@ -484,6 +484,11 @@ sub ErrorHandling { my $hash = $param->{hash}; my $name = $hash->{NAME}; my $dhash = $hash; + + Log3($name, 1, qq(GardenaSmartBridge ($name) - Daten: ${data}); + Log3($name, 1, qq(GardenaSmartBridge ($name) - Error: ${err}) + if ( defined($err) + and $err ); $dhash = $modules{GardenaSmartDevice}{defptr}{ $param->{'device_id'} } if ( defined( $param->{'device_id'} ) ); diff --git a/controls_GardenaSmartDevice.txt b/controls_GardenaSmartDevice.txt index 551752c..9430f58 100644 --- a/controls_GardenaSmartDevice.txt +++ b/controls_GardenaSmartDevice.txt @@ -1,2 +1,2 @@ -UPD 2021-03-09_08:45:53 42674 FHEM/73_GardenaSmartBridge.pm +UPD 2021-03-10_16:13:27 42859 FHEM/73_GardenaSmartBridge.pm UPD 2020-05-01_22:05:14 45622 FHEM/74_GardenaSmartDevice.pm -- 2.49.0 From f5f4dfc18e5114ac07fb9cbc98820ae710fb410a Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Wed, 10 Mar 2021 17:50:28 +0100 Subject: [PATCH 4/8] fix syntax error --- FHEM/73_GardenaSmartBridge.pm | 4 ++-- controls_GardenaSmartDevice.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/FHEM/73_GardenaSmartBridge.pm b/FHEM/73_GardenaSmartBridge.pm index 60519c3..9167fda 100644 --- a/FHEM/73_GardenaSmartBridge.pm +++ b/FHEM/73_GardenaSmartBridge.pm @@ -485,8 +485,8 @@ sub ErrorHandling { my $name = $hash->{NAME}; my $dhash = $hash; - Log3($name, 1, qq(GardenaSmartBridge ($name) - Daten: ${data}); - Log3($name, 1, qq(GardenaSmartBridge ($name) - Error: ${err}) + Log3($name, 1, qq(GardenaSmartBridge ($name) - Daten: ${data})); + Log3($name, 1, qq(GardenaSmartBridge ($name) - Error: ${err})) if ( defined($err) and $err ); diff --git a/controls_GardenaSmartDevice.txt b/controls_GardenaSmartDevice.txt index 9430f58..da0e85d 100644 --- a/controls_GardenaSmartDevice.txt +++ b/controls_GardenaSmartDevice.txt @@ -1,2 +1,2 @@ -UPD 2021-03-10_16:13:27 42859 FHEM/73_GardenaSmartBridge.pm +UPD 2021-03-10_17:50:23 42861 FHEM/73_GardenaSmartBridge.pm UPD 2020-05-01_22:05:14 45622 FHEM/74_GardenaSmartDevice.pm -- 2.49.0 From ad0ab78d9afa015490f2991519b501fe6414bf2b Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Wed, 10 Mar 2021 18:32:28 +0100 Subject: [PATCH 5/8] add message key and output to state --- FHEM/73_GardenaSmartBridge.pm | 20 +++++++++++++++----- controls_GardenaSmartDevice.txt | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/FHEM/73_GardenaSmartBridge.pm b/FHEM/73_GardenaSmartBridge.pm index 9167fda..5af77f0 100644 --- a/FHEM/73_GardenaSmartBridge.pm +++ b/FHEM/73_GardenaSmartBridge.pm @@ -484,11 +484,6 @@ sub ErrorHandling { my $hash = $param->{hash}; my $name = $hash->{NAME}; my $dhash = $hash; - - Log3($name, 1, qq(GardenaSmartBridge ($name) - Daten: ${data})); - Log3($name, 1, qq(GardenaSmartBridge ($name) - Error: ${err})) - if ( defined($err) - and $err ); $dhash = $modules{GardenaSmartDevice}{defptr}{ $param->{'device_id'} } if ( defined( $param->{'device_id'} ) ); @@ -796,6 +791,12 @@ sub ResponseProcessing { . " Tail: " . $tail; } + elsif ( defined($decode_json->{message}) + && $decode_json->{message} ) + { + + WriteReadings( $hash, $decode_json ); + } return; } @@ -812,6 +813,15 @@ sub WriteReadings { # print Dumper $decode_json; my $name = $hash->{NAME}; + + + if ( defined($decode_json->{message}) + && $decode_json->{message} ) + { + readingsBeginUpdate($hash); + readingsBulkUpdateIfChanged( $hash, 'state', $decode_json->{message} ); + readingsEndUpdate( $hash, 1 ); + } if ( defined( $decode_json->{id} ) && $decode_json->{id} diff --git a/controls_GardenaSmartDevice.txt b/controls_GardenaSmartDevice.txt index da0e85d..8715d1e 100644 --- a/controls_GardenaSmartDevice.txt +++ b/controls_GardenaSmartDevice.txt @@ -1,2 +1,2 @@ -UPD 2021-03-10_17:50:23 42861 FHEM/73_GardenaSmartBridge.pm +UPD 2021-03-10_18:32:20 43098 FHEM/73_GardenaSmartBridge.pm UPD 2020-05-01_22:05:14 45622 FHEM/74_GardenaSmartDevice.pm -- 2.49.0 From bf70f2ffec7c557c8fb81cb2dea72b93738d4402 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Wed, 10 Mar 2021 18:38:30 +0100 Subject: [PATCH 6/8] fix little bug --- FHEM/73_GardenaSmartBridge.pm | 11 +++++------ controls_GardenaSmartDevice.txt | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/FHEM/73_GardenaSmartBridge.pm b/FHEM/73_GardenaSmartBridge.pm index 5af77f0..22e3131 100644 --- a/FHEM/73_GardenaSmartBridge.pm +++ b/FHEM/73_GardenaSmartBridge.pm @@ -791,15 +791,14 @@ sub ResponseProcessing { . " Tail: " . $tail; } - elsif ( defined($decode_json->{message}) - && $decode_json->{message} ) - { - - WriteReadings( $hash, $decode_json ); - } return; } + elsif ( defined($decode_json->{message}) + && $decode_json->{message} ) + { + WriteReadings( $hash, $decode_json ); + } Log3 $name, 3, "GardenaSmartBridge ($name) - no Match for processing data"; diff --git a/controls_GardenaSmartDevice.txt b/controls_GardenaSmartDevice.txt index 8715d1e..888a35a 100644 --- a/controls_GardenaSmartDevice.txt +++ b/controls_GardenaSmartDevice.txt @@ -1,2 +1,2 @@ -UPD 2021-03-10_18:32:20 43098 FHEM/73_GardenaSmartBridge.pm +UPD 2021-03-10_18:38:26 43072 FHEM/73_GardenaSmartBridge.pm UPD 2020-05-01_22:05:14 45622 FHEM/74_GardenaSmartDevice.pm -- 2.49.0 From 36c96abaf8a93ac2f6aac18158a1d8f750c053e7 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Wed, 10 Mar 2021 18:43:14 +0100 Subject: [PATCH 7/8] add new API URL --- FHEM/73_GardenaSmartBridge.pm | 4 ++-- controls_GardenaSmartDevice.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/FHEM/73_GardenaSmartBridge.pm b/FHEM/73_GardenaSmartBridge.pm index 22e3131..64870e1 100644 --- a/FHEM/73_GardenaSmartBridge.pm +++ b/FHEM/73_GardenaSmartBridge.pm @@ -232,8 +232,8 @@ sub Define { $hash->{BRIDGE} = 1; $hash->{URL} = AttrVal( $name, 'gardenaBaseURL', - 'https://sg-api.dss.husqvarnagroup.net' ) - . '/sg-1'; + 'https://api.smart.gardena.dev' ) + . '/v1'; $hash->{VERSION} = version->parse($VERSION)->normal; $hash->{INTERVAL} = 60; $hash->{NOTIFYDEV} = "global,$name"; diff --git a/controls_GardenaSmartDevice.txt b/controls_GardenaSmartDevice.txt index 888a35a..d788541 100644 --- a/controls_GardenaSmartDevice.txt +++ b/controls_GardenaSmartDevice.txt @@ -1,2 +1,2 @@ -UPD 2021-03-10_18:38:26 43072 FHEM/73_GardenaSmartBridge.pm +UPD 2021-03-10_18:43:05 43062 FHEM/73_GardenaSmartBridge.pm UPD 2020-05-01_22:05:14 45622 FHEM/74_GardenaSmartDevice.pm -- 2.49.0 From a86bb7822af099646b1640a6f0f70e10eb8547f4 Mon Sep 17 00:00:00 2001 From: Sebastian Schwaz Date: Fri, 26 Mar 2021 17:00:44 +0100 Subject: [PATCH 8/8] fix api --- FHEM/73_GardenaSmartBridge.pm | 89 +++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 41 deletions(-) diff --git a/FHEM/73_GardenaSmartBridge.pm b/FHEM/73_GardenaSmartBridge.pm index 64870e1..bd15158 100644 --- a/FHEM/73_GardenaSmartBridge.pm +++ b/FHEM/73_GardenaSmartBridge.pm @@ -28,7 +28,7 @@ # GNU General Public License for more details. # # -# $Id$ +# $Id: 73_GardenaSmartBridge.pm 22957 2020-10-12 07:01:56Z CoolTux $ # ############################################################################### ## @@ -56,7 +56,7 @@ package FHEM::GardenaSmartBridge; use GPUtils qw(GP_Import GP_Export); -# use Data::Dumper; #only for Debugging +#use Data::Dumper; #only for Debugging use strict; use warnings; @@ -232,7 +232,7 @@ sub Define { $hash->{BRIDGE} = 1; $hash->{URL} = AttrVal( $name, 'gardenaBaseURL', - 'https://api.smart.gardena.dev' ) + 'https://smart.gardena.com' ) . '/v1'; $hash->{VERSION} = version->parse($VERSION)->normal; $hash->{INTERVAL} = 60; @@ -315,12 +315,12 @@ sub Attr { } elsif ( $attrName eq 'gardenaBaseURL' ) { if ( $cmd eq 'set' ) { - $hash->{URL} = $attrVal . '/sg-1'; + $hash->{URL} = $attrVal; Log3 $name, 3, "GardenaSmartBridge ($name) - set gardenaBaseURL to: $attrVal"; } elsif ( $cmd eq 'del' ) { - $hash->{URL} = 'https://sg-api.dss.husqvarnagroup.net/sg-1'; + $hash->{URL} = 'https://smart.gardena.com/v1'; } } @@ -470,8 +470,8 @@ sub Write { "GardenaSmartBridge ($name) - Send with URL: $hash->{URL}$uri, HEADER: secret!, DATA: secret!, METHOD: $method" ); -# Log3($name, 3, -# "GardenaSmartBridge ($name) - Send with URL: $hash->{URL}$uri, HEADER: $header, DATA: $payload, METHOD: $method"); + # Log3($name, 3, + # "GardenaSmartBridge ($name) - Send with URL: $hash->{URL}$uri, HEADER: $header, DATA: $payload, METHOD: $method"); return; } @@ -490,6 +490,7 @@ sub ErrorHandling { my $dname = $dhash->{NAME}; + # Log3 $name, 4, Dumper($data); my $decode_json = eval { decode_json($data) }; if ($@) { Log3 $name, 3, "GardenaSmartBridge ($name) - JSON error while request"; @@ -710,12 +711,15 @@ sub ResponseProcessing { } } - # print Dumper $decode_json; + # print Dumper $decode_json; - if ( defined( $decode_json->{sessions} ) && $decode_json->{sessions} ) { + if ( defined( $decode_json->{data} ) && $decode_json->{data} + && ref($decode_json->{data}) eq 'HASH' + && !defined( $hash->{helper}->{user_id})) { - $hash->{helper}{session_id} = $decode_json->{sessions}{token}; - $hash->{helper}{user_id} = $decode_json->{sessions}{user_id}; + $hash->{helper}{session_id} = $decode_json->{data}{id}; + $hash->{helper}{user_id} = $decode_json->{data}{attributes}->{user_id}; + $hash->{helper}{refresh_tokebn} = $decode_json->{data}{attributes}->{refresh_token}; Write( $hash, undef, undef, undef ); Log3 $name, 3, "GardenaSmartBridge ($name) - fetch locations id"; @@ -794,11 +798,6 @@ sub ResponseProcessing { return; } - elsif ( defined($decode_json->{message}) - && $decode_json->{message} ) - { - WriteReadings( $hash, $decode_json ); - } Log3 $name, 3, "GardenaSmartBridge ($name) - no Match for processing data"; @@ -812,15 +811,6 @@ sub WriteReadings { # print Dumper $decode_json; my $name = $hash->{NAME}; - - - if ( defined($decode_json->{message}) - && $decode_json->{message} ) - { - readingsBeginUpdate($hash); - readingsBulkUpdateIfChanged( $hash, 'state', $decode_json->{message} ); - readingsEndUpdate( $hash, 1 ); - } if ( defined( $decode_json->{id} ) && $decode_json->{id} @@ -843,8 +833,7 @@ sub WriteReadings { } readingsBulkUpdateIfChanged( $hash, 'zones', - scalar( @{ $decode_json->{zones} } ) ) - if ( ref($decode_json->{zones}) eq 'ARRAY' ); + scalar( @{ $decode_json->{zones} } ) ); } elsif ($decode_json->{id} ne $hash->{helper}{locations_id} && ref( $decode_json->{abilities} ) eq 'ARRAY' @@ -973,16 +962,28 @@ sub getToken { if ( defined( $hash->{helper}{locations_id} ) && $hash->{helper}{locations_id} ); + # Write( + # $hash, + # '"sessions": {"email": "' + # . AttrVal( $name, 'gardenaAccountEmail', 'none' ) + # . '","password": "' + # . ReadPassword( $hash, $name ) . '"}', + # undef, + # undef + # ); + Write( - $hash, - '"sessions": {"email": "' - . AttrVal( $name, 'gardenaAccountEmail', 'none' ) - . '","password": "' - . ReadPassword( $hash, $name ) . '"}', - undef, - undef - ); + $hash, + '"data": {"type":"token", "attributes":{"username": "' + . AttrVal( $name, 'gardenaAccountEmail', 'none' ) + . '","password": "' + . ReadPassword( $hash, $name ) . '", "client_id":"smartgarden-jwt-client"}}', + undef, + undef + ); +Log3 $name, 4, '"data": {"type":"token", "attributes":{"username": "' . AttrVal( $name, 'gardenaAccountEmail', 'none' ) . '","password": "' + . ReadPassword( $hash, $name ) . '", "client_id":"smartgarden-jwt-client"}}'; Log3 $name, 3, "GardenaSmartBridge ($name) - send credentials to fetch Token and locationId"; @@ -1137,25 +1138,31 @@ sub createHttpValueStrings { my $header = "Content-Type: application/json"; my $uri = ''; my $method = 'POST'; - $header .= "\r\nX-Session: $session_id" - if ( defined( $hash->{helper}{session_id} ) ); + $header .= "\r\nAuthorization: Bearer $session_id" + if ( defined($hash->{helper}{session_id}) ); + $header .= "\r\nAuthorization-Provider: husqvarna" + if ( defined($hash->{helper}{session_id}) ); + + # $header .= "\r\nx-api-key: $session_id" + # if ( defined( $hash->{helper}{session_id} ) ); $payload = '{' . $payload . '}' if ( defined($payload) ); $payload = '{}' if ( !defined($payload) ); if ( $payload eq '{}' ) { $method = 'GET'; - $uri .= '/locations/?user_id=' . $hash->{helper}{user_id} + $payload = ''; + $uri .= '/locations/?locatioId=null&user_id=' . $hash->{helper}{user_id} if ( exists( $hash->{helper}{user_id} ) && !defined( $hash->{helper}{locations_id} ) ); readingsSingleUpdate( $hash, 'state', 'fetch locationId', 1 ) if ( !defined( $hash->{helper}{locations_id} ) ); - $uri .= '/sessions' if ( !defined( $hash->{helper}{session_id} ) ); + $uri .= '/auth/token' if ( !defined( $hash->{helper}{session_id} ) ); $uri .= '/devices' if (!defined($abilities) && defined( $hash->{helper}{locations_id} ) ); } - $uri .= '/sessions' if ( !defined( $hash->{helper}{session_id} ) ); + $uri .= '/auth/token' if ( !defined( $hash->{helper}{session_id} ) ); if ( defined( $hash->{helper}{locations_id} ) ) { if ( defined($abilities) && $abilities eq 'mower_settings' ) { @@ -1391,7 +1398,7 @@ sub DeletePassword { ], "release_status": "stable", "license": "GPL_2", - "version": "v2.0.4", + "version": "v2.1.0", "author": [ "Marko Oldenburg " ], -- 2.49.0