Merge branch 'patch-sebastian' into devel
This commit is contained in:
commit
472b37271d
@ -232,8 +232,8 @@ sub Define {
|
|||||||
$hash->{BRIDGE} = 1;
|
$hash->{BRIDGE} = 1;
|
||||||
$hash->{URL} =
|
$hash->{URL} =
|
||||||
AttrVal( $name, 'gardenaBaseURL',
|
AttrVal( $name, 'gardenaBaseURL',
|
||||||
'https://sg-api.dss.husqvarnagroup.net' )
|
'https://smart.gardena.com' )
|
||||||
. '/sg-1';
|
. '/v1';
|
||||||
$hash->{VERSION} = version->parse($VERSION)->normal;
|
$hash->{VERSION} = version->parse($VERSION)->normal;
|
||||||
$hash->{INTERVAL} = 60;
|
$hash->{INTERVAL} = 60;
|
||||||
$hash->{NOTIFYDEV} = "global,$name";
|
$hash->{NOTIFYDEV} = "global,$name";
|
||||||
@ -315,12 +315,12 @@ sub Attr {
|
|||||||
}
|
}
|
||||||
elsif ( $attrName eq 'gardenaBaseURL' ) {
|
elsif ( $attrName eq 'gardenaBaseURL' ) {
|
||||||
if ( $cmd eq 'set' ) {
|
if ( $cmd eq 'set' ) {
|
||||||
$hash->{URL} = $attrVal . '/sg-1';
|
$hash->{URL} = $attrVal;
|
||||||
Log3 $name, 3,
|
Log3 $name, 3,
|
||||||
"GardenaSmartBridge ($name) - set gardenaBaseURL to: $attrVal";
|
"GardenaSmartBridge ($name) - set gardenaBaseURL to: $attrVal";
|
||||||
}
|
}
|
||||||
elsif ( $cmd eq 'del' ) {
|
elsif ( $cmd eq 'del' ) {
|
||||||
$hash->{URL} = 'https://sg-api.dss.husqvarnagroup.net/sg-1';
|
$hash->{URL} = 'https://smart.gardena.com/v1';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -490,6 +490,7 @@ sub ErrorHandling {
|
|||||||
|
|
||||||
my $dname = $dhash->{NAME};
|
my $dname = $dhash->{NAME};
|
||||||
|
|
||||||
|
# Log3 $name, 4, Dumper($data);
|
||||||
my $decode_json = eval { decode_json($data) };
|
my $decode_json = eval { decode_json($data) };
|
||||||
if ($@) {
|
if ($@) {
|
||||||
Log3 $name, 3, "GardenaSmartBridge ($name) - JSON error while request";
|
Log3 $name, 3, "GardenaSmartBridge ($name) - JSON error while request";
|
||||||
@ -712,10 +713,13 @@ 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}{session_id} = $decode_json->{data}{id};
|
||||||
$hash->{helper}{user_id} = $decode_json->{sessions}{user_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 );
|
Write( $hash, undef, undef, undef );
|
||||||
Log3 $name, 3, "GardenaSmartBridge ($name) - fetch locations id";
|
Log3 $name, 3, "GardenaSmartBridge ($name) - fetch locations id";
|
||||||
@ -794,11 +798,6 @@ sub ResponseProcessing {
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
elsif ( defined($decode_json->{message})
|
|
||||||
&& $decode_json->{message} )
|
|
||||||
{
|
|
||||||
WriteReadings( $hash, $decode_json );
|
|
||||||
}
|
|
||||||
|
|
||||||
Log3 $name, 3, "GardenaSmartBridge ($name) - no Match for processing data";
|
Log3 $name, 3, "GardenaSmartBridge ($name) - no Match for processing data";
|
||||||
|
|
||||||
@ -813,15 +812,6 @@ sub WriteReadings {
|
|||||||
|
|
||||||
my $name = $hash->{NAME};
|
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} )
|
if ( defined( $decode_json->{id} )
|
||||||
&& $decode_json->{id}
|
&& $decode_json->{id}
|
||||||
&& defined( $decode_json->{name} )
|
&& defined( $decode_json->{name} )
|
||||||
@ -843,8 +833,7 @@ sub WriteReadings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
readingsBulkUpdateIfChanged( $hash, 'zones',
|
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}
|
elsif ($decode_json->{id} ne $hash->{helper}{locations_id}
|
||||||
&& ref( $decode_json->{abilities} ) eq 'ARRAY'
|
&& ref( $decode_json->{abilities} ) eq 'ARRAY'
|
||||||
@ -973,16 +962,28 @@ sub getToken {
|
|||||||
if ( defined( $hash->{helper}{locations_id} )
|
if ( defined( $hash->{helper}{locations_id} )
|
||||||
&& $hash->{helper}{locations_id} );
|
&& $hash->{helper}{locations_id} );
|
||||||
|
|
||||||
|
# Write(
|
||||||
|
# $hash,
|
||||||
|
# '"sessions": {"email": "'
|
||||||
|
# . AttrVal( $name, 'gardenaAccountEmail', 'none' )
|
||||||
|
# . '","password": "'
|
||||||
|
# . ReadPassword( $hash, $name ) . '"}',
|
||||||
|
# undef,
|
||||||
|
# undef
|
||||||
|
# );
|
||||||
|
|
||||||
Write(
|
Write(
|
||||||
$hash,
|
$hash,
|
||||||
'"sessions": {"email": "'
|
'"data": {"type":"token", "attributes":{"username": "'
|
||||||
. AttrVal( $name, 'gardenaAccountEmail', 'none' )
|
. AttrVal( $name, 'gardenaAccountEmail', 'none' )
|
||||||
. '","password": "'
|
. '","password": "'
|
||||||
. ReadPassword( $hash, $name ) . '"}',
|
. ReadPassword( $hash, $name ) . '", "client_id":"smartgarden-jwt-client"}}',
|
||||||
undef,
|
undef,
|
||||||
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,
|
Log3 $name, 3,
|
||||||
"GardenaSmartBridge ($name) - send credentials to fetch Token and locationId";
|
"GardenaSmartBridge ($name) - send credentials to fetch Token and locationId";
|
||||||
|
|
||||||
@ -1137,25 +1138,31 @@ sub createHttpValueStrings {
|
|||||||
my $header = "Content-Type: application/json";
|
my $header = "Content-Type: application/json";
|
||||||
my $uri = '';
|
my $uri = '';
|
||||||
my $method = 'POST';
|
my $method = 'POST';
|
||||||
$header .= "\r\nX-Session: $session_id"
|
$header .= "\r\nAuthorization: Bearer $session_id"
|
||||||
if ( defined($hash->{helper}{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 = '{' . $payload . '}' if ( defined($payload) );
|
||||||
$payload = '{}' if ( !defined($payload) );
|
$payload = '{}' if ( !defined($payload) );
|
||||||
|
|
||||||
if ( $payload eq '{}' ) {
|
if ( $payload eq '{}' ) {
|
||||||
$method = 'GET';
|
$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} )
|
if ( exists( $hash->{helper}{user_id} )
|
||||||
&& !defined( $hash->{helper}{locations_id} ) );
|
&& !defined( $hash->{helper}{locations_id} ) );
|
||||||
readingsSingleUpdate( $hash, 'state', 'fetch locationId', 1 )
|
readingsSingleUpdate( $hash, 'state', 'fetch locationId', 1 )
|
||||||
if ( !defined( $hash->{helper}{locations_id} ) );
|
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'
|
$uri .= '/devices'
|
||||||
if (!defined($abilities)
|
if (!defined($abilities)
|
||||||
&& defined( $hash->{helper}{locations_id} ) );
|
&& 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( $hash->{helper}{locations_id} ) ) {
|
||||||
if ( defined($abilities) && $abilities eq 'mower_settings' ) {
|
if ( defined($abilities) && $abilities eq 'mower_settings' ) {
|
||||||
@ -1391,7 +1398,7 @@ sub DeletePassword {
|
|||||||
],
|
],
|
||||||
"release_status": "stable",
|
"release_status": "stable",
|
||||||
"license": "GPL_2",
|
"license": "GPL_2",
|
||||||
"version": "v2.0.4",
|
"version": "v2.1.0",
|
||||||
"author": [
|
"author": [
|
||||||
"Marko Oldenburg <leongaultier@gmail.com>"
|
"Marko Oldenburg <leongaultier@gmail.com>"
|
||||||
],
|
],
|
||||||
|
1
controls_GardenaSmart.txt
Normal file
1
controls_GardenaSmart.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
UPD 2021-03-26_22:20:12 43636 FHEM/73_GardenaSmartBridge.pm
|
@ -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
|
UPD 2020-05-01_22:05:14 45622 FHEM/74_GardenaSmartDevice.pm
|
||||||
|
Loading…
x
Reference in New Issue
Block a user