71 Commits

Author SHA1 Message Date
1498f73b10 Merge pull request 'devel' (#49) from devel into master
Reviewed-on: #49
2022-02-09 14:16:38 +01:00
8ae1510a71 Merge pull request 'patch-async_run_parseJson' (#48) from patch-async_run_parseJson into devel
Reviewed-on: #48
2022-02-09 14:11:54 +01:00
b211fe2b56 Subject line (try to keep under 50 characters)
Multi-line description of commit,
feel free to be detailed.

[Ticket: X]
2022-02-09 13:51:13 +01:00
85c7b3fa0a change condition to grep wintermode
[Ticket: no]
2022-02-09 10:29:40 +01:00
65df7eb47b chage state to hibernate
[Ticket: no]
2022-02-08 11:56:46 +01:00
13e7e24911 change version number, ready for testing
[Ticket: no]
2022-02-01 18:42:33 +01:00
b61458a45e code clean up
after add run parseJSON function ansynchron

[Ticket: no]
2022-02-01 17:01:49 +01:00
673445e339 Subject line (try to keep under 50 characters)
Multi-line description of commit,
feel free to be detailed.

[Ticket: X]
2022-02-01 13:05:53 +01:00
157e9fc58c Subject line (try to keep under 50 characters)
Multi-line description of commit,
feel free to be detailed.

[Ticket: X]
2022-02-01 12:53:37 +01:00
f3f2688292 Subject line (try to keep under 50 characters)
Multi-line description of commit,
feel free to be detailed.

[Ticket: X]
2022-02-01 12:42:32 +01:00
5d245d5a3d Subject line (try to keep under 50 characters)
Multi-line description of commit,
feel free to be detailed.

[Ticket: X]
2022-02-01 11:53:08 +01:00
ddbe145179 Subject line (try to keep under 50 characters)
Multi-line description of commit,
feel free to be detailed.

[Ticket: X]
2022-02-01 10:59:08 +01:00
bd06f26248 no array reference found. will be check
[Ticket: no]
2022-02-01 09:54:42 +01:00
8e470ccbb6 Subject line (try to keep under 50 characters)
Undefined subroutine &FHEM::GardenaSmartBridge::CleanSubprocess called

[Ticket: none]
2022-02-01 09:26:31 +01:00
7c01c1c790 make parseJSON function to run asynchron
in installations wirh many of Gardena devices,
 the parseJSON function run long time.
 This patch make the parseJSON function asybchron

[Ticket: #47]
2022-01-31 19:43:20 +01:00
7b30b50cf1 Merge pull request 'ready for release' (#46) from testing into master
Reviewed-on: #46
2021-10-27 05:20:13 +02:00
32eec48ce6 Merge pull request 'devel' (#45) from devel into testing
Reviewed-on: #45
2021-09-27 11:24:53 +02:00
5545ac1370 Merge pull request 'change controlfile' (#44) from patch-controlfile into devel
Reviewed-on: #44
2021-09-27 11:24:20 +02:00
d186f3e6c8 change controlfile 2021-09-27 11:21:17 +02:00
eec264b014 Merge pull request 'devel' (#43) from devel into testing
Reviewed-on: #43
Reviewed-by: Marko Oldenburg <marko@noreply@cooltux.net>
2021-09-24 20:01:46 +02:00
ef1aabfcb0 Merge pull request 'patch-token_expired' (#42) from patch-token_expired into devel
Reviewed-on: #42
Reviewed-by: Marko Oldenburg <marko@noreply@cooltux.net>
2021-09-11 20:23:39 +02:00
c3882d4af3 enable hook on new system 2021-08-07 23:54:37 +02:00
43b4c15a9d debug, token fix 2021-08-07 23:52:29 +02:00
908fe4fc24 check also location_id so we have token and user id ... 2021-07-28 21:51:36 +02:00
b423fc73fc pump version 2021-07-28 21:45:10 +02:00
9abd0a9173 fix helper debug device for post 2021-07-28 21:42:34 +02:00
2af38efe42 Merge pull request 'devel' (#40) from devel into testing
Reviewed-on: #40
Reviewed-by: Marko Oldenburg <marko@noreply@cooltux.net>
2021-07-23 11:27:48 +02:00
8ddb1a8233 Merge pull request 'patch-power_timer' (#39) from patch-power_timer into devel
Reviewed-on: #39
Reviewed-by: Marko Oldenburg <marko@noreply@cooltux.net>
2021-07-21 13:59:10 +02:00
23be875b9f Merge branch 'devel' into patch-power_timer 2021-07-21 13:58:25 +02:00
5294e3fea5 Merge pull request 'patch-mower_timestamp_start' (#37) from patch-mower_timestamp_start into devel
Reviewed-on: #37
Reviewed-by: Marko Oldenburg <marko@noreply@cooltux.net>
2021-07-16 21:20:28 +02:00
12c4a0d5ba increase slider to 720 2021-07-16 20:26:16 +02:00
a856bb574a fix empty arg array condition 2021-07-13 17:22:03 +02:00
4e52ea8215 add payload propertie 2021-07-12 12:01:02 +02:00
70c54892d8 change to unixtimestamp 2021-06-28 20:11:18 +02:00
b49d7f643b Merge pull request 'patch-connect_problems' (#35) from patch-connect_problems into devel
Reviewed-on: #35
Reviewed-by: Marko Oldenburg <marko@noreply@cooltux.net>
2021-06-28 18:39:21 +02:00
cf93bbdba6 missed ); 2021-06-28 16:16:10 +02:00
9d3ddb088b add mower timestamp to readings 2021-06-28 16:11:39 +02:00
48e526a627 fixup 2021-06-28 10:47:51 +02:00
113dec6551 cleanup code 2021-06-28 10:27:23 +02:00
71ef5799c2 remove debug stuff 2021-06-28 10:24:43 +02:00
49ef217d12 initdone 2021-06-21 22:44:38 +02:00
65f031e1c2 fix2 2021-06-21 21:18:34 +02:00
10718f1355 hard post 2021-06-21 20:46:23 +02:00
b0638c525e test 2021-06-21 20:44:39 +02:00
0adf1d8a3b fix 2021-06-21 19:36:18 +02:00
a0d8125d32 payload 2021-06-21 19:31:51 +02:00
b6866dd44a add some function 2021-06-21 19:24:41 +02:00
6f0aee2a69 debug 2021-06-19 10:46:28 +02:00
acb482e37f pump version 2021-06-18 12:35:39 +02:00
0ec53ea1b3 add init 2021-06-17 19:17:27 +02:00
08bb518e9a removed debug stuff 2021-06-16 20:05:53 +02:00
33eb0ed012 comment Dumper 2021-06-16 10:11:52 +02:00
70af6fd6a3 fix token 404 2021-06-16 10:11:12 +02:00
44a251f7f7 fix json error by empty response, add test log level 1 for notify 2021-06-11 19:05:54 +02:00
0aa3e543a8 Merge pull request 'merge des aktuellen devel in testing' (#34) from devel into testing
Reviewed-on: #34
Reviewed-by: Sebastian Schwaz <sebastianschwarz@noreply@cooltux.net>
2021-06-09 13:53:43 +02:00
97b8a6edab fixing connection / interval / 404 error 2021-06-09 13:23:28 +02:00
a7d374596d Merge pull request 'patch-wintermode' (#33) from patch-wintermode into devel
Reviewed-on: #33
Reviewed-by: Marko Oldenburg <marko@noreply@cooltux.net>
2021-06-06 19:23:34 +02:00
cf0772f6ae missed 2 of them( notify ) 2021-06-05 18:47:43 +02:00
fe23d695e4 undo notify regexp 2021-06-05 18:42:27 +02:00
9a6241b608 Merge branch 'patch-wintermode' of ssh://git.cooltux.net:8222/FHEM/mod-GardenaSmart into patch-wintermode 2021-06-05 09:30:40 +02:00
065eebb858 comment dumper 2021-06-05 09:30:31 +02:00
1f3465a12d Merge branch 'devel' into patch-wintermode 2021-06-05 09:29:03 +02:00
e3674c401d change timestamp for schedule stop 2021-06-05 09:24:29 +02:00
1dde30c52c fix notifys, 2021-06-04 15:31:05 +02:00
5fb14e80a8 Merge pull request 'patch-watercontrol_schedule' (#32) from patch-watercontrol_schedule into devel
Reviewed-on: #32
Reviewed-by: Marko Oldenburg <marko@noreply@cooltux.net>
2021-05-30 22:37:05 +02:00
c9f212a641 variable fix 2021-05-29 22:08:35 +02:00
9e20c40b37 wintermode 2021-05-28 20:56:19 +02:00
e9d37309b4 versionsbump 2021-05-28 20:35:57 +02:00
613e14b4f9 cmdref 2021-05-28 20:28:07 +02:00
6e5f2d98b3 buttonconfing + cmdref 2021-05-28 20:25:44 +02:00
249f996db7 add stop/resume schedule 2021-05-26 20:37:39 +02:00
3 changed files with 682 additions and 394 deletions

View File

@ -1,8 +1,8 @@
###############################################################################
#
# Developed with Kate
# Developed with VSCodium and richterger perl plugin.
#
# (c) 2017-2021 Copyright: Marko Oldenburg (fhemdevelopment at cooltux dot net)
# (c) 2017-2022 Copyright: Marko Oldenburg (fhemdevelopment at cooltux dot net)
# All rights reserved
#
# Special thanks goes to comitters:
@ -57,7 +57,6 @@
package FHEM::GardenaSmartBridge;
use GPUtils qw(GP_Import GP_Export);
use strict;
use warnings;
use POSIX;
@ -66,11 +65,12 @@ use FHEM::Meta;
use HttpUtils;
my $missingModul = '';
eval "use Encode qw(encode encode_utf8 decode_utf8);1"
eval { use Encode qw /encode_utf8 decode_utf8/; 1 }
or $missingModul .= "Encode ";
# eval "use JSON;1" || $missingModul .= 'JSON ';
eval "use IO::Socket::SSL;1" or $missingModul .= 'IO::Socket::SSL ';
eval { use IO::Socket::SSL; 1 }
or $missingModul .= 'IO::Socket::SSL ';
# try to use JSON::MaybeXS wrapper
# for chance of better performance + open code
@ -78,15 +78,11 @@ eval {
require JSON::MaybeXS;
import JSON::MaybeXS qw( decode_json encode_json );
1;
};
if ($@) {
$@ = undef;
} or do {
# try to use JSON wrapper
# for chance of better performance
eval {
# JSON preference order
local $ENV{PERL_JSON_BACKEND} =
'Cpanel::JSON::XS,JSON::XS,JSON::PP,JSON::backportPP'
@ -95,10 +91,7 @@ if ($@) {
require JSON;
import JSON qw( decode_json encode_json );
1;
};
if ($@) {
$@ = undef;
} or do {
# In rare cases, Cpanel::JSON::XS may
# be installed but JSON|JSON::MaybeXS not ...
@ -106,10 +99,7 @@ if ($@) {
require Cpanel::JSON::XS;
import Cpanel::JSON::XS qw(decode_json encode_json);
1;
};
if ($@) {
$@ = undef;
} or do {
# In rare cases, JSON::XS may
# be installed but JSON not ...
@ -117,10 +107,7 @@ if ($@) {
require JSON::XS;
import JSON::XS qw(decode_json encode_json);
1;
};
if ($@) {
$@ = undef;
} or do {
# Fallback to built-in JSON which SHOULD
# be available since 5.014 ...
@ -128,20 +115,17 @@ if ($@) {
require JSON::PP;
import JSON::PP qw(decode_json encode_json);
1;
};
if ($@) {
$@ = undef;
} or do {
# Fallback to JSON::backportPP in really rare cases
require JSON::backportPP;
import JSON::backportPP qw(decode_json encode_json);
1;
}
}
}
}
}
};
};
};
};
};
## Import der FHEM Funktionen
#-- Run before package compilation
@ -181,7 +165,7 @@ BEGIN {
#-- Export to main context with different name
GP_Export(
qw(
Initialize
Initialize
)
);
@ -205,6 +189,7 @@ sub Initialize {
$hash->{AttrFn} = \&Attr;
$hash->{AttrList} =
'debugJSON:0,1 '
. 'debugDEVICE:0,1 '
. 'disable:1 '
. 'interval '
. 'disabledForIntervals '
@ -234,9 +219,7 @@ sub Define {
my $name = shift @$aArg;
$hash->{BRIDGE} = 1;
$hash->{URL} =
AttrVal( $name, 'gardenaBaseURL',
'https://smart.gardena.com' )
. '/v1';
AttrVal( $name, 'gardenaBaseURL', 'https://smart.gardena.com' ) . '/v1';
$hash->{VERSION} = version->parse($VERSION)->normal;
$hash->{INTERVAL} = 60;
$hash->{NOTIFYDEV} = "global,$name";
@ -258,7 +241,7 @@ sub Undef {
my $hash = shift;
my $name = shift;
RemoveInternalTimer($hash);
RemoveInternalTimer( $hash, "FHEM::GardenaSmartBridge::getDevices" );
delete $modules{GardenaSmartBridge}{defptr}{BRIDGE}
if ( defined( $modules{GardenaSmartBridge}{defptr}{BRIDGE} ) );
@ -279,7 +262,8 @@ sub Attr {
if ( $attrName eq 'disable' ) {
if ( $cmd eq 'set' && $attrVal eq '1' ) {
RemoveInternalTimer($hash);
RemoveInternalTimer( $hash,
"FHEM::GardenaSmartBridge::getDevices" );
readingsSingleUpdate( $hash, 'state', 'inactive', 1 );
Log3 $name, 3, "GardenaSmartBridge ($name) - disabled";
}
@ -304,13 +288,15 @@ sub Attr {
if ( $cmd eq 'set' ) {
return 'Interval must be greater than 0'
if ( $attrVal == 0 );
RemoveInternalTimer($hash);
RemoveInternalTimer( $hash,
"FHEM::GardenaSmartBridge::getDevices" );
$hash->{INTERVAL} = $attrVal;
Log3 $name, 3,
"GardenaSmartBridge ($name) - set interval: $attrVal";
}
elsif ( $cmd eq 'del' ) {
RemoveInternalTimer($hash);
RemoveInternalTimer( $hash,
"FHEM::GardenaSmartBridge::getDevices" );
$hash->{INTERVAL} = 60;
Log3 $name, 3,
"GardenaSmartBridge ($name) - delete User interval and set default: 60";
@ -352,25 +338,21 @@ sub Notify {
@{$events} or grep /^DEFINED.$name$/,
@{$events} or grep /^MODIFIED.$name$/,
@{$events} or grep /^ATTR.$name.gardenaAccountEmail.+/,
@{$events} or grep /^DELETEATTR.$name.disable$/,
@{$events}
)
)
|| (
$devtype eq 'GardenaSmartBridge'
&& (
grep /^gardenaAccountPassword.+/,
@{$events}
)
)
|| ( $devtype eq 'GardenaSmartBridge'
&& ( grep /^gardenaAccountPassword.+/, @{$events} ) )
&& $init_done
);
getDevices($hash)
if (
$devtype eq 'Global'
&& (
grep /^DELETEATTR.$name.disable$/,
@{$events} or grep /^ATTR.$name.disable.0$/,
grep /^ATTR.$name.disable.0$/,
@{$events} or grep /^DELETEATTR.$name.interval$/,
@{$events} or grep /^ATTR.$name.interval.[0-9]+/,
@{$events}
@ -387,7 +369,6 @@ sub Notify {
)
)
{
InternalTimer( gettimeofday() + $hash->{INTERVAL},
"FHEM::GardenaSmartBridge::getDevices", $hash );
Log3 $name, 4,
@ -396,6 +377,7 @@ sub Notify {
return;
}
sub Get {
my $hash = shift // return;
my $aArg = shift // return;
@ -407,15 +389,16 @@ sub Get {
if ( lc $cmd eq 'debug_devices_list' ) {
my $device = shift @$aArg;
$hash->{helper}{debug_device} = $device;
Write($hash, undef, undef, undef, undef);
return undef;
} else {
Write( $hash, undef, undef, undef, undef );
return;
}
else {
my $list = "";
$list .= " debug_devices_list:"
.join( ',', @{ $hash->{helper}{deviceList} })
if ( AttrVal( $name, "debugJSON", "none") ne "none"
&& exists($hash->{helper}{deviceList}) );
return "Unknown argument $cmd,choose one of $list";
$list .=
" debug_devices_list:" . join( ',', @{ $hash->{helper}{deviceList} } )
if ( AttrVal( $name, "debugDEVICE", "none" ) ne "none"
&& exists( $hash->{helper}{deviceList} ) );
return "Unknown argument $cmd,choose one of $list";
}
}
@ -424,8 +407,9 @@ sub Set {
my $aArg = shift // return;
my $name = shift @$aArg // return;
my $cmd = shift @$aArg // return qq{"set $name" needs at least one argument};
my $cmd = shift @$aArg
// return qq{"set $name" needs at least one argument};
# Das Argument für das Passwort, also das Passwort an sich darf keine = enthalten!!!
if ( lc $cmd eq 'getdevicesstate' ) {
@ -475,20 +459,22 @@ sub Write {
my ( $session_id, $header, $uri, $method );
( $payload, $session_id, $header, $uri, $method, $deviceId, $service_id ) =
createHttpValueStrings( $hash, $payload, $deviceId, $abilities, $service_id );
createHttpValueStrings( $hash, $payload, $deviceId, $abilities,
$service_id );
HttpUtils_NonblockingGet(
{
url => $hash->{URL} . $uri,
timeout => 15,
hash => $hash,
device_id => $deviceId,
data => $payload,
method => $method,
header => $header,
doTrigger => 1,
cl => $hash->{CL},
callback => \&ErrorHandling
url => $hash->{URL} . $uri,
timeout => 15,
incrementalTimeout => 1,
hash => $hash,
device_id => $deviceId,
data => $payload,
method => $method,
header => $header,
doTrigger => 1,
cl => $hash->{CL},
callback => \&ErrorHandling
}
);
@ -496,8 +482,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;
}
@ -515,10 +501,10 @@ sub ErrorHandling {
if ( defined( $param->{'device_id'} ) );
my $dname = $dhash->{NAME};
Log3 $name, 4, "GardenaSmartBridge ($name) - Request: $data";
my $decode_json = eval { decode_json($data) };
my $decode_json = eval { decode_json($data) } if ( length($data) > 0 );
if ($@) {
Log3 $name, 3, "GardenaSmartBridge ($name) - JSON error while request";
}
@ -698,6 +684,11 @@ sub ErrorHandling {
. $param->{code};
}
if ( !defined( $hash->{helper}{session_id} ) ) {
readingsSingleUpdate( $hash, 'token', 'none', 1 );
InternalTimer( gettimeofday() + 5,
"FHEM::GardenaSmartBridge::getToken", $hash );
}
readingsEndUpdate( $dhash, 1 );
Log3 $dname, 5,
@ -710,30 +701,68 @@ sub ErrorHandling {
return;
}
if (defined($hash->{helper}{debug_device})){
Log3 $name, 5, "GardenaSmartBridge DEBUG Device";
my @device_spec = ("name", "id", "category");
my $devJson=$decode_json->{devices};
my $output = '.:{ DEBUG OUTPUT for '.$devJson->{name}.' }:. \n';
for my $spec (@device_spec) {
$output .= "$spec : $devJson->{$spec} \n";
}
#settings
$output .= '\n=== Settings \n';
my $i = 0;
for my $dev_settings ( @ { $devJson->{settings} } ) {
$output .= "[".$i++."]id: $dev_settings->{id} \n";
$output .= "name: $dev_settings->{name} ";
if (ref ($dev_settings->{value}) eq 'ARRAY'
|| ref ($dev_settings->{value}) eq 'HASH'){
$output .= 'N/A \n';
} else {
$output .= "value: $dev_settings->{value} \n";
elsif ( defined( $decode_json->{message} )
&& $decode_json->{message} eq 'Unauthorized' )
{
Log3 $name, 3,
"GardenaSmartBridge ($name) - Unauthorized -> fetch new token ";
getToken($hash);
return;
}
if ( defined( $hash->{helper}{debug_device} )
&& $hash->{helper}{debug_device} ne 'none' )
{
Log3 $name, 4, "GardenaSmartBridge DEBUG Device";
delete $hash->{helper}{debug_device};
my @device_spec = ( "name", "id", "category" );
my $devJson = $decode_json->{devices};
my $output = '.:{ DEBUG OUTPUT for ' . $devJson->{name} . ' }:. \n';
for my $spec (@device_spec) {
$output .= "$spec : $devJson->{$spec} \n";
}
}
$hash->{helper}{debug_device_output} = $output;
asyncOutput($param->{cl}, $hash->{helper}{debug_device_output});
return;
#settings
$output .= '\n=== Settings \n';
my $i = 0;
for my $dev_settings ( @{ $devJson->{settings} } ) {
$output .= "[" . $i++ . "]id: $dev_settings->{id} \n";
$output .= "name: $dev_settings->{name} ";
if ( ref( $dev_settings->{value} ) eq 'ARRAY'
|| ref( $dev_settings->{value} ) eq 'HASH' )
{
$output .= 'N/A \n';
}
else {
$output .= "value: $dev_settings->{value} \n";
}
}
$output .= '\n=== Abilities \n';
$i = 0;
for my $dev_settings ( @{ $devJson->{abilities} } ) {
$output .= "[" . $i++ . "]id: $dev_settings->{id} \n";
$output .= "name: $dev_settings->{name} ";
if ( ref( $dev_settings->{value} ) eq 'ARRAY'
|| ref( $dev_settings->{value} ) eq 'HASH' )
{
$output .= 'N/A \n';
}
else {
$output .= "value: $dev_settings->{value} \n";
}
}
$hash->{helper}{debug_device_output} = $output;
asyncOutput( $param->{cl}, $hash->{helper}{debug_device_output} );
return;
}
readingsSingleUpdate( $hash, 'state', 'Connected', 1 )
if ( defined( $hash->{helper}{locations_id} ) );
@ -762,15 +791,21 @@ sub ResponseProcessing {
}
}
# print Dumper $decode_json;
if ( defined( $decode_json->{data} )
&& $decode_json->{data}
&& ref( $decode_json->{data} ) eq 'HASH'
&& !defined( $hash->{helper}->{user_id} ) )
{
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->{data}{id};
$hash->{helper}{user_id} = $decode_json->{data}{attributes}->{user_id};
$hash->{helper}{refresh_token} =
$decode_json->{data}{attributes}->{refresh_token};
$hash->{helper}{token_expired} =
gettimeofday() + $decode_json->{data}{attributes}->{expires_in};
$hash->{helper}{session_id} = $decode_json->{data}{id};
$hash->{helper}{user_id} = $decode_json->{data}{attributes}->{user_id};
$hash->{helper}{refresh_token} = $decode_json->{data}{attributes}->{refresh_token};
InternalTimer( $hash->{helper}{token_expired},
"FHEM::GardenaSmartBridge::getToken", $hash );
Write( $hash, undef, undef, undef );
Log3 $name, 3, "GardenaSmartBridge ($name) - fetch locations id";
@ -802,51 +837,36 @@ sub ResponseProcessing {
&& ref( $decode_json->{devices} ) eq 'ARRAY'
&& scalar( @{ $decode_json->{devices} } ) > 0 )
{
my @buffer = split( '"devices":\[', $json );
my ( $json, $tail ) = ParseJSON( $hash, $buffer[1] );
require SubProcess;
while ($json) {
my $subprocess =
SubProcess->new( { onRun => \&ResponseSubprocessing } );
$subprocess->{buffer} = $buffer[1];
Log3 $name, 5,
"GardenaSmartBridge ($name) - Decoding JSON message. Length: "
. length($json)
. " Content: "
. $json;
Log3 $name, 5,
"GardenaSmartBridge ($name) - Vor Sub: Laenge JSON: "
. length($json)
. " Content: "
. $json
. " Tail: "
. $tail;
my $pid = $subprocess->run();
if ( defined($tail) and $tail ) {
$decode_json = eval { decode_json($json) };
if ($@) {
Log3 $name, 5,
"GardenaSmartBridge ($name) - JSON error while request: $@";
}
if ( !defined($pid) ) {
Log3( $name, 1,
qq{GardenaSmartBridge ($name) - Cannot execute parse json asynchronously}
);
Dispatch( $hash, $json, undef )
if ( $decode_json->{category} ne 'gateway' );
WriteReadings( $hash, $decode_json )
if ( defined( $decode_json->{category} )
&& $decode_json->{category} eq 'gateway' );
}
( $json, $tail ) = ParseJSON( $hash, $tail );
Log3 $name, 5,
"GardenaSmartBridge ($name) - Nach Sub: Laenge JSON: "
. length($json)
. " Content: "
. $json
. " Tail: "
. $tail;
CleanSubprocess($hash);
readingsSingleUpdate( $hash, 'state',
'Cannot execute parse json asynchronously', 1 );
return;
}
Log3( $name, 4,
qq{GardenaSmartBridge ($name) - execute parse json asynchronously (PID="$pid")}
);
$hash->{".fhem"}{subprocess} = $subprocess;
InternalTimer( gettimeofday() + 1,
"FHEM::GardenaSmartBridge::PollChild", $hash );
return;
}
@ -855,12 +875,148 @@ sub ResponseProcessing {
return;
}
sub ResponseProcessingFinalFromSubProcessing {
my $hash = shift;
my $response = shift;
my $name = $hash->{NAME};
my @response = split '\|,', $response;
Log3( $name, 4,
qq{GardenaSmartBridge ($name) - got result from asynchronous parsing} );
my $decode_json;
Log3( $name, 4, qq{GardenaSmartBridge ($name) - asynchronous finished.} );
if ( scalar(@response) > 0 ) {
for my $json (@response) {
#################
$decode_json = eval { decode_json($json) };
if ($@) {
Log3 $name, 5,
"GardenaSmartBridge ($name) - JSON error while request: $@";
}
Dispatch( $hash, $json, undef )
if ( $decode_json->{category} ne 'gateway' );
WriteReadings( $hash, $decode_json )
if ( defined( $decode_json->{category} )
&& $decode_json->{category} eq 'gateway' );
}
}
return;
}
sub PollChild {
my $hash = shift;
my $name = $hash->{NAME};
if ( defined( $hash->{".fhem"}{subprocess} ) ) {
my $subprocess = $hash->{".fhem"}{subprocess};
my $response = $subprocess->readFromChild();
if ( defined($response) ) {
ResponseProcessingFinalFromSubProcessing( $hash, $response );
$subprocess->wait();
CleanSubprocess($hash);
}
Log3( $name, 4,
qq{GardenaSmartBridge ($name) - still waiting ($subprocess->{lasterror}).}
);
InternalTimer( gettimeofday() + 1,
"FHEM::GardenaSmartBridge::PollChild", $hash );
return;
}
return;
}
# ResponseSubprocessin muss in eine async ausgelagert werden
######################################
# Begin Childprozess
######################################
sub ResponseSubprocessing {
my $subprocess = shift;
my $buffer = $subprocess->{buffer};
my @response = ();
my ( $json, $tail ) = ParseJSON($buffer);
while ($json) {
if ( defined($tail) and $tail ) {
push @response, $json;
}
( $json, $tail ) = ParseJSON($tail);
}
$subprocess->writeToParent( join '|', @response );
return;
}
sub ParseJSON {
my $buffer = shift;
my $open = 0;
my $close = 0;
my $msg = '';
my $tail = '';
if ($buffer) {
for my $c ( split //, $buffer ) {
if ( $open == $close && $open > 0 ) {
$tail .= $c;
}
else {
if ( $c eq '{' ) {
$open++;
}
elsif ( $c eq '}' ) {
$close++;
}
$msg .= $c;
}
}
if ( $open != $close ) {
$tail = $msg;
$msg = '';
}
}
return ( $msg, $tail );
}
######################################
# End Childprozess
######################################
sub CleanSubprocess {
my $hash = shift;
my $name = $hash->{NAME};
delete( $hash->{".fhem"}{subprocess} );
Log3( $name, 4, qq{GardenaSmartBridge ($name) - clean Subprocess} );
}
sub WriteReadings {
my $hash = shift;
my $decode_json = shift;
# print Dumper $decode_json;
my $name = $hash->{NAME};
if ( defined( $decode_json->{id} )
@ -904,8 +1060,9 @@ sub WriteReadings {
$decode_json->{abilities}[0]{properties}[$properties]
{name} . '-' . $t,
$v
)
if ($decode_json->{abilities}[0]{properties}[$properties]{name} !~ /ethernet_status|wifi_status/ );
)
if ( $decode_json->{abilities}[0]{properties}[$properties]
{name} !~ /ethernet_status|wifi_status/ );
if (
(
$decode_json->{abilities}[0]{properties}
@ -931,10 +1088,9 @@ sub WriteReadings {
elsif ( $decode_json->{abilities}[0]{properties}
[$properties]{name} eq 'wifi_status' )
{
#TODO: read valies if bridge connected to wifi
readingsBulkUpdateIfChanged( $hash,
'wifi_status-ssid', $v->{ssid} )
if (ref($v->{ssid}) ne 'HASH');
'wifi_status-ssid', $v->{ssid} )
if ( ref( $v->{ssid} ) ne 'HASH' );
readingsBulkUpdateIfChanged( $hash,
'wifi_status-mac', $v->{mac} );
readingsBulkUpdateIfChanged( $hash,
@ -967,23 +1123,25 @@ sub getDevices {
my $hash = shift;
my $name = $hash->{NAME};
RemoveInternalTimer($hash);
RemoveInternalTimer( $hash, "FHEM::GardenaSmartBridge::getDevices" );
if ( not IsDisabled($name) ) {
delete $hash->{helper}{deviceList};
my @list;
@list = devspec2array('TYPE=GardenaSmartDevice');
for my $gardenaDev (@list){
push( @{ $hash->{helper}{deviceList} }, $gardenaDev );
for my $gardenaDev (@list) {
push( @{ $hash->{helper}{deviceList} }, $gardenaDev );
}
Write( $hash, undef, undef, undef );
Log3 $name, 4,
"GardenaSmartBridge ($name) - fetch device list and device states";
if ( AttrVal( $name, 'gardenaAccountEmail', 'none' ) ne 'none'
&& ( defined( ReadPassword( $hash, $name ) ) ) )
{
Write( $hash, undef, undef, undef );
Log3 $name, 4,
"GardenaSmartBridge ($name) - fetch device list and device states";
} # fi gardenaAccountEmail
}
else {
readingsSingleUpdate( $hash, 'state', 'disabled', 1 );
Log3 $name, 3, "GardenaSmartBridge ($name) - device is disabled";
}
@ -1005,36 +1163,29 @@ sub getToken {
readingsSingleUpdate( $hash, 'state', 'get token', 1 );
delete $hash->{helper}{session_id}
if ( defined( $hash->{helper}{session_id} )
&& $hash->{helper}{session_id} );
if ( exists( $hash->{helper}{session_id} ) );
delete $hash->{helper}{user_id}
if ( defined( $hash->{helper}{user_id} ) && $hash->{helper}{user_id} );
if ( exists( $hash->{helper}{user_id} ) );
delete $hash->{helper}{locations_id}
if ( defined( $hash->{helper}{locations_id} )
&& $hash->{helper}{locations_id} );
if ( exists( $hash->{helper}{locations_id} ) );
# Write(
# $hash,
# '"sessions": {"email": "'
# . AttrVal( $name, 'gardenaAccountEmail', 'none' )
# . '","password": "'
# . ReadPassword( $hash, $name ) . '"}',
# undef,
# undef
# );
Write(
$hash,
'"data": {"type":"token", "attributes":{"username": "'
. AttrVal( $name, 'gardenaAccountEmail', 'none' )
. '","password": "'
. ReadPassword( $hash, $name ) . '", "client_id":"smartgarden-jwt-client"}}',
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, 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";
@ -1085,7 +1236,7 @@ sub ReadPassword {
Log3 $name, 3,
"GardenaSmartBridge ($name) - unable to read password from file: $err";
return undef;
return;
}
@ -1111,7 +1262,7 @@ sub ReadPassword {
else {
Log3 $name, 3, "GardenaSmartBridge ($name) - No password in file";
return undef;
return;
}
return;
@ -1129,59 +1280,6 @@ sub Rename {
return;
}
sub ParseJSON {
my $hash = shift;
my $buffer = shift;
my $name = $hash->{NAME};
my $open = 0;
my $close = 0;
my $msg = '';
my $tail = '';
if ($buffer) {
for my $c ( split //, $buffer ) {
if ( $open == $close && $open > 0 ) {
$tail .= $c;
Log3 $name, 5,
"GardenaSmartBridge ($name) - $open == $close and $open > 0";
}
elsif ( ( $open == $close ) && ( $c ne '{' ) ) {
Log3 $name, 5,
"GardenaSmartBridge ($name) - Garbage character before message: "
. $c;
}
else {
if ( $c eq '{' ) {
$open++;
}
elsif ( $c eq '}' ) {
$close++;
}
$msg .= $c;
}
}
if ( $open != $close ) {
$tail = $msg;
$msg = '';
}
}
Log3 $name, 5,
"GardenaSmartBridge ($name) - return msg: $msg and tail: $tail";
return ( $msg, $tail );
}
sub createHttpValueStrings {
my ( $hash, $payload, $deviceId, $abilities, $service_id ) = @_;
@ -1190,30 +1288,33 @@ sub createHttpValueStrings {
my $uri = '';
my $method = 'POST';
$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}) );
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) );
$payload = '{}' if ( !defined($payload) );
if ( $payload eq '{}' ) {
$method = 'GET';
$method = 'GET' if ( defined( $hash->{helper}{session_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 .= '/auth/token' if ( !defined( $hash->{helper}{session_id} ) );
if ( exists( $hash->{helper}{user_id} )
&& !defined( $hash->{helper}{locations_id} ) );
$uri .= '/devices'
if (!defined($abilities)
&& defined( $hash->{helper}{locations_id} ) );
}
$uri = '/devices/'.InternalVal($hash->{helper}{debug_device}, 'DEVICEID', 0 ) if ( exists ($hash->{helper}{debug_device}));
$uri =
'/devices/' . InternalVal( $hash->{helper}{debug_device}, 'DEVICEID', 0 )
if ( defined( $hash->{helper}{debug_device} )
&& defined( $hash->{helper}{locations_id} ) );
$uri = '/auth/token' if ( !defined( $hash->{helper}{session_id} ) );
if ( defined( $hash->{helper}{locations_id} ) ) {
@ -1221,17 +1322,13 @@ sub createHttpValueStrings {
$method = 'PUT';
my $dhash = $modules{GardenaSmartDevice}{defptr}{$deviceId};
$uri .=
'/devices/'
. $deviceId
. '/settings/'
. $service_id
$uri .= '/devices/' . $deviceId . '/settings/' . $service_id
if ( defined($abilities)
&& defined($payload)
&& $abilities =~ /.*_settings/ );
} # park until next schedules or override
} # park until next schedules or override
elsif (defined($abilities)
&& defined($payload)
&& $abilities eq 'mower_timer' )
@ -1254,7 +1351,7 @@ sub createHttpValueStrings {
my $valve_id;
if ( $payload =~ m#watering_timer_(\d)# ) {
$method = 'PUT';
$method = 'PUT';
$valve_id = $1;
}
$uri .=
@ -1262,7 +1359,11 @@ sub createHttpValueStrings {
. $deviceId
. '/abilities/'
. $abilities
. ( defined($valve_id) ? '/properties/watering_timer_'. $valve_id : '/command')
. (
defined($valve_id)
? '/properties/watering_timer_' . $valve_id
: '/command'
);
}
elsif (defined($abilities)
@ -1279,6 +1380,19 @@ sub createHttpValueStrings {
. $abilities
. '/properties/manual_watering_timer';
}
elsif (defined($abilities)
&& defined($payload)
&& $abilities eq 'watering_button_config' )
{
$method = 'PUT';
$uri .=
'/devices/'
. $deviceId
. '/abilities/watering'
. '/properties/button_config_time';
}
elsif (defined($abilities)
&& defined($payload)
@ -1463,9 +1577,9 @@ sub DeletePassword {
],
"release_status": "stable",
"license": "GPL_2",
"version": "v2.4.0",
"version": "v2.4.7",
"author": [
"Marko Oldenburg <leongaultier@gmail.com>"
"Marko Oldenburg <fhemdevelopment@cooltux.net>"
],
"x_fhem_maintainer": [
"CoolTux"

View File

@ -1,8 +1,8 @@
###############################################################################
#
# Developed with Kate
# Developed with VSCodium and richterger perl plugin.
#
# (c) 2017-2021 Copyright: Marko Oldenburg (fhemdevelopment at cooltux dot net)
# (c) 2017-2022 Copyright: Marko Oldenburg (fhemdevelopment at cooltux dot net)
# All rights reserved
#
# Special thanks goes to comitters:
@ -72,15 +72,11 @@ eval {
require JSON::MaybeXS;
import JSON::MaybeXS qw( decode_json encode_json );
1;
};
if ($@) {
$@ = undef;
} or do {
# try to use JSON wrapper
# for chance of better performance
eval {
# JSON preference order
local $ENV{PERL_JSON_BACKEND} =
'Cpanel::JSON::XS,JSON::XS,JSON::PP,JSON::backportPP'
@ -89,10 +85,7 @@ if ($@) {
require JSON;
import JSON qw( decode_json encode_json );
1;
};
if ($@) {
$@ = undef;
} or do {
# In rare cases, Cpanel::JSON::XS may
# be installed but JSON|JSON::MaybeXS not ...
@ -100,10 +93,7 @@ if ($@) {
require Cpanel::JSON::XS;
import Cpanel::JSON::XS qw(decode_json encode_json);
1;
};
if ($@) {
$@ = undef;
} or do {
# In rare cases, JSON::XS may
# be installed but JSON not ...
@ -111,10 +101,7 @@ if ($@) {
require JSON::XS;
import JSON::XS qw(decode_json encode_json);
1;
};
if ($@) {
$@ = undef;
} or do {
# Fallback to built-in JSON which SHOULD
# be available since 5.014 ...
@ -122,20 +109,17 @@ if ($@) {
require JSON::PP;
import JSON::PP qw(decode_json encode_json);
1;
};
if ($@) {
$@ = undef;
} or do {
# Fallback to JSON::backportPP in really rare cases
require JSON::backportPP;
import JSON::backportPP qw(decode_json encode_json);
1;
}
}
}
}
}
};
};
};
};
};
## Import der FHEM Funktionen
#-- Run before package compilation
@ -164,7 +148,7 @@ BEGIN {
#-- Export to main context with different name
GP_Export(
qw(
Initialize
Initialize
)
);
@ -204,18 +188,23 @@ sub Define {
my $deviceId = $aArg->[2];
my $category = $aArg->[3];
$hash->{DEVICEID} = $deviceId;
$hash->{VERSION} = version->parse($VERSION)->normal;
$hash->{helper}{STARTINGPOINTID} = '';
$hash->{helper}{schedules_paused_until_id} = '';
$hash->{helper}{eco_mode_id} = '';
$hash->{DEVICEID} = $deviceId;
$hash->{VERSION} = version->parse($VERSION)->normal;
$hash->{helper}{STARTINGPOINTID} = '';
$hash->{helper}{schedules_paused_until_id} = '';
$hash->{helper}{eco_mode_id} = '';
$hash->{helper}{button_config_time_id} = '';
$hash->{helper}{winter_mode_id} = '';
$hash->{helper}{_id} = '';
# IrrigationControl valve control max 6
$hash->{helper}{schedules_paused_until_1_id} = '';
$hash->{helper}{schedules_paused_until_2_id} = '';
$hash->{helper}{schedules_paused_until_3_id} = '';
$hash->{helper}{schedules_paused_until_4_id} = '';
$hash->{helper}{schedules_paused_until_5_id} = '';
$hash->{helper}{schedules_paused_until_6_id} = '';
$hash->{helper}{schedules_paused_until_1_id} = '';
$hash->{helper}{schedules_paused_until_2_id} = '';
$hash->{helper}{schedules_paused_until_3_id} = '';
$hash->{helper}{schedules_paused_until_4_id} = '';
$hash->{helper}{schedules_paused_until_5_id} = '';
$hash->{helper}{schedules_paused_until_6_id} = '';
CommandAttr( undef,
"$name IODev $modules{GardenaSmartBridge}{defptr}{BRIDGE}->{NAME}" )
@ -279,16 +268,18 @@ sub Attr {
}
sub Set {
my $hash = shift // return;
my $aArg = shift // return;
my $hash = shift // return;
my $aArg = shift // return;
my $name = shift @$aArg;
my $cmd = shift @$aArg // return qq{"set $name" needs at least one argument};
my $name = shift @$aArg;
my $cmd = shift @$aArg
// return qq{"set $name" needs at least one argument};
my $payload;
my $abilities;
my $service_id;
my $mainboard_version = ReadingsVal( $name, 'mower_type-mainboard_version', 0.0 );
my $mainboard_version =
ReadingsVal( $name, 'mower_type-mainboard_version', 0.0 );
#set default abilitie ... overwrite in cmd to change
$abilities = 'mower'
@ -301,51 +292,62 @@ sub Set {
$abilities = 'manual_watering'
if ( AttrVal( $name, 'model', 'unknown' ) eq 'electronic_pressure_pump' );
### mower
### mower
# service_id (eco, parkuntilfurhternotice, startpoints)
if ( lc $cmd eq 'parkuntilfurthernotice' ) {
$payload = '"name":"park_until_further_notice"';
if ( $mainboard_version > 10.30 ) {
$payload = ' "settings":{"name":"schedules_paused_until","value":"2040-12-31T22:00:00.000Z","device":"'.$hash->{DEVICEID}.'"}';
$abilities = 'mower_settings' ;
$service_id = $hash->{helper}{schedules_paused_until_id};
$payload =
' "settings":{"name":"schedules_paused_until","value":"2038-01-18T00:00:00.000Z","device":"'
. $hash->{DEVICEID} . '"}';
$abilities = 'mower_settings';
$service_id = $hash->{helper}{schedules_paused_until_id};
}
}
elsif ( lc $cmd eq 'parkuntilnexttimer' ) {
elsif ( lc $cmd eq 'parkuntilnexttimer' ) {
$payload = '"name":"park_until_next_timer"';
if ( $mainboard_version > 10.30 ){
$payload = '"properties":{"name":"mower_timer","value":0}' ;
$abilities = 'mower_timer';
if ( $mainboard_version > 10.30 ) {
$payload = '"properties":{"name":"mower_timer","value":0}';
$abilities = 'mower_timer';
}
}
elsif ( lc $cmd eq 'startresumeschedule' ) {
$payload = '"name":"start_resume_schedule"';
if ( $mainboard_version > 10.30 ) {
$payload = ' "settings":{"name":"schedules_paused_until","value":"","device":"'.$hash->{DEVICEID}.'"}';
$abilities = 'mower_settings' ;
$service_id = $hash->{helper}{schedules_paused_until_id};
$payload =
' "settings":{"name":"schedules_paused_until","value":"","device":"'
. $hash->{DEVICEID} . '"}';
$abilities = 'mower_settings';
$service_id = $hash->{helper}{schedules_paused_until_id};
}
}
elsif ( lc $cmd eq 'startoverridetimer' ) {
$payload = '"name":"start_override_timer","parameters":{"duration":'
. $aArg->[0] * 60 . '}';
if ( $mainboard_version > 10.30 ){
$payload = '"properties":{"name":"mower_timer","value":'.$aArg->[0] * 60 .'}';
$abilities = 'mower_timer';
if ( $mainboard_version > 10.30 ) {
$payload = '"properties":{"name":"mower_timer","value":'
. $aArg->[0] * 60 . '}';
$abilities = 'mower_timer';
}
}
elsif ( lc $cmd eq 'startpoint' ) {
my $err;
( $err, $payload, $abilities ) = SetPredefinedStartPoints( $hash, $aArg );
( $err, $payload, $abilities ) =
SetPredefinedStartPoints( $hash, $aArg );
$service_id = $hash->{helper}{STARTINGPOINTID};
return $err if ( defined($err) );
}
elsif ( lc $cmd eq 'eco' ) {
$payload = '"settings": {"name": "eco_mode", "value": '.$aArg->[0].', "device": "'.$hash->{DEVICEID}.'"}';
$abilities = 'mower_settings' if ( $mainboard_version > 10.30 );
$payload =
'"settings": {"name": "eco_mode", "value": '
. $aArg->[0]
. ', "device": "'
. $hash->{DEVICEID} . '"}';
$abilities = 'mower_settings' if ( $mainboard_version > 10.30 );
$service_id = $hash->{helper}{eco_mode_id};
#$abilities['service_id'] = $hash->{helper}{SCHEDULESID} if ( $mainboard_version > 10.30 );
#$abilities['service_id'] = $hash->{helper}{SCHEDULESID} if ( $mainboard_version > 10.30 );
}
### electronic_pressure_pump
elsif ( lc $cmd eq 'pumptimer' ) {
@ -361,6 +363,17 @@ sub Set {
. $aArg->[0] * 60
. ',"valve_id":1}}';
}
elsif ( lc $cmd eq 'manualbuttontime' ) {
$service_id = $hash->{helper}{button_config_time_id};
$payload =
'"properties":{"name":"button_config_time",'
. '"value":'
. $aArg->[0] * 60
. ',"timestamp":"2021-05-26T19:06:23.680Z"'
. ',"at_bound":null,"unit":"seconds","ability":"'
. $service_id . '"}';
$abilities = 'watering_button_config';
}
elsif ( $cmd =~ m{\AcancelOverride}xms ) {
my $valve_id = 1;
@ -377,14 +390,40 @@ sub Set {
. ',"valve_id":'
. $valve_id . '}}';
}
elsif ( $cmd =~ /.*Schedule/ ) {
my $duration = (
(
defined( $aArg->[0] )
? (
(
( Time::Piece->new ) +
( ONE_HOUR * $aArg->[0] ) -
( Time::Piece->new )->tzoffset
)->datetime
)
. '.000Z'
: '2038-01-18T00:00:00.000Z'
)
);
$abilities = 'wateringcomputer_settings';
$service_id = $hash->{helper}->{'schedules_paused_until_id'};
$payload =
'"settings":{"name":"schedules_paused_until"'
. ', "value":"'
. ( $cmd eq 'resumeSchedule' ? '' : $duration )
. '","device":"'
. $hash->{DEVICEID} . '"}';
}
elsif ( lc $cmd eq 'on' || lc $cmd eq 'off' || lc $cmd eq 'on-for-timer' ) {
my $val = (
defined($aArg) && ref($aArg) eq 'ARRAY'
scalar( !@$aArg == 0 ) && ref($aArg) eq 'ARRAY'
? $aArg->[0] * 60
: lc $cmd
);
$payload = '"properties":{"value":"' . $val . '"}';
$payload =
'"properties":{"name":"power_timer", "value":"' . $val . '"}';
}
### Watering ic24
elsif ( $cmd =~ m{\AmanualDurationValve\d\z}xms ) {
@ -402,34 +441,51 @@ sub Set {
. ',"valve_id":'
. $valve_id . '}}';
}
elsif ( $cmd eq 'closeAllValves' ){
$payload = '"name":"close_all_valves","parameters":{}';
elsif ( $cmd eq 'closeAllValves' ) {
$payload = '"name":"close_all_valves","parameters":{}';
}
elsif ( $cmd =~ /.*ScheduleValve/ ){
my $valve_id = $aArg->[0];
my $duration = (( defined($aArg->[1]) ? ( ((Time::Piece->new)+(ONE_HOUR * $aArg->[1]) - (Time::Piece->new)->tzoffset )->datetime ).'.000Z' : '2040-12-31T22:00:00.000Z'));
elsif ( $cmd =~ /.*ScheduleValve/ ) {
my $valve_id = $aArg->[0];
my $duration = (
(
defined( $aArg->[1] )
? (
(
( Time::Piece->new ) +
( ONE_HOUR * $aArg->[1] ) -
( Time::Piece->new )->tzoffset
)->datetime
)
. '.000Z'
: '2038-01-18T00:00:00.000Z'
)
);
$abilities = 'irrigation_settings';
$service_id = $hash->{helper}->{'schedules_paused_until_'.$valve_id.'_id'};
$payload = '"settings":{"name":"schedules_paused_until_'
. $valve_id
. '", "value":"'
. ($cmd eq 'resumeScheduleValve' ? '' : $duration )
. '","device":"'
. $hash->{DEVICEID}
. '"}';
$abilities = 'irrigation_settings';
$service_id =
$hash->{helper}->{ 'schedules_paused_until_' . $valve_id . '_id' };
$payload =
'"settings":{"name":"schedules_paused_until_'
. $valve_id
. '", "value":"'
. ( $cmd eq 'resumeScheduleValve' ? '' : $duration )
. '","device":"'
. $hash->{DEVICEID} . '"}';
}
### Sensors
elsif ( lc $cmd eq 'refresh' ) {
my $sensname = $aArg->[0];
if ( lc $sensname eq 'temperature' ) {
if ( ReadingsVal( $name, 'device_info-category', 'sensor' ) eq 'sensor') {
$payload = '"name":"measure_ambient_temperature"';
$abilities = 'ambient_temperature';
} else {
$payload = '"name":"measure_soil_temperature"';
$abilities = 'soil_temperature';
if ( ReadingsVal( $name, 'device_info-category', 'sensor' ) eq
'sensor' )
{
$payload = '"name":"measure_ambient_temperature"';
$abilities = 'ambient_temperature';
}
else {
$payload = '"name":"measure_soil_temperature"';
$abilities = 'soil_temperature';
}
}
elsif ( lc $sensname eq 'light' ) {
@ -441,8 +497,16 @@ sub Set {
$payload = '"name":"measure_soil_humidity"';
$abilities = 'humidity';
}
}
## winter sleep
elsif ( lc $cmd eq 'winter_mode' ) {
$payload =
'"settings":{"name":"winter_mode","value":"'
. $aArg->[0]
. '","device":"'
. $hash->{DEVICEID} . '"}';
$abilities = 'winter_settings';
$service_id = $hash->{helper}->{'winter_mode_id'};
}
else {
@ -452,7 +516,8 @@ sub Set {
'parkUntilFurtherNotice:noArg parkUntilNextTimer:noArg startResumeSchedule:noArg startOverrideTimer:slider,0,1,240 startpoint'
if ( AttrVal( $name, 'model', 'unknown' ) eq 'mower' );
$list .= 'manualOverride:slider,1,1,59 cancelOverride:noArg'
$list .=
'manualOverride:slider,1,1,59 cancelOverride:noArg resumeSchedule:noArg stopSchedule manualButtonTime:slider,0,2,100'
if ( AttrVal( $name, 'model', 'unknown' ) eq 'watering_computer' );
$list .=
@ -461,14 +526,18 @@ sub Set {
$list .= 'refresh:temperature,humidity'
if ( AttrVal( $name, 'model', 'unknown' ) eq 'sensor' );
# add light for old sensors
$list .= ',light'
if ( AttrVal( $name, 'model', 'unknown' ) eq 'sensor'
&& ReadingsVal($name, 'device_info-category', 'unknown') eq 'sensor' );
if ( AttrVal( $name, 'model', 'unknown' ) eq 'sensor'
&& ReadingsVal( $name, 'device_info-category', 'unknown' ) eq
'sensor' );
$list .= 'on:noArg off:noArg on-for-timer:slider,0,1,60'
$list .= 'on:noArg off:noArg on-for-timer:slider,0,1,720'
if ( AttrVal( $name, 'model', 'unknown' ) eq 'power' );
# all devices has abilitie to fall a sleep
$list .= ' winter_mode:awake,hibernate';
return "Unknown argument $cmd, choose one of $list";
}
@ -547,6 +616,32 @@ sub WriteReadings {
for my $propertie (
@{ $decode_json->{abilities}[$abilities]{properties} } )
{
if (
exists( $decode_json->{abilities}[$abilities]{name} )
&& ( $decode_json->{abilities}[$abilities]{name} eq
'watering' )
)
{
if ( $propertie->{name} eq 'button_config_time' ) {
if ( $hash->{helper}{ $propertie->{name} . '_id' } ne
$decode_json->{abilities}[$abilities]{id} )
{
$hash->{helper}{ $propertie->{name} . '_id' } =
$decode_json->{abilities}[$abilities]{id};
}
readingsBulkUpdateIfChanged(
$hash,
'manualButtonTime',
(
RigReadingsValue(
$hash, $propertie->{value} / 60
)
)
);
next;
}
}
readingsBulkUpdateIfChanged(
$hash,
$decode_json->{abilities}[$abilities]{name} . '-'
@ -596,6 +691,22 @@ sub WriteReadings {
. $propertie->{name} eq 'light-light' )
);
readingsBulkUpdateIfChanged(
$hash,
$decode_json->{abilities}[$abilities]{name} . '-'
. $propertie->{name}
. '_timestamp',
Time::Piece->strptime(
RigReadingsValue( $hash, $propertie->{timestamp} ),
"%Y-%m-%d %H:%M:%S" )->strftime('%s')
)
if (
defined( $propertie->{value} )
&& ( $decode_json->{abilities}[$abilities]{name} . '-'
. $propertie->{name} eq 'mower_timer-mower_timer' )
);
readingsBulkUpdateIfChanged(
$hash,
$decode_json->{abilities}[$abilities]{name} . '-'
@ -633,25 +744,40 @@ sub WriteReadings {
$abilities--;
} while ( $abilities >= 0 );
do {
#Log3 $name, 1, "Settings pro Device : ".$decode_json->{settings}[$settings]{name};
#Log3 $name, 1, " - KEIN ARRAY" if ( ref( $decode_json->{settings}[$settings]{value} ) ne "ARRAY");
#Log3 $name, 1, " - IST ARRAY" if ( ref( $decode_json->{settings}[$settings]{value} ) eq "ARRAY");
my $winter_mode;
if ( exists($decode_json->{settings}[$settings]{name})
&& (
$decode_json->{settings}[$settings]{name} =~ /schedules_paused_until_?\d?$/
|| $decode_json->{settings}[$settings]{name} eq 'eco_mode' )
)
{
if ( $hash->{helper}{$decode_json->{settings}[$settings]{name}.'_id'} ne
do {
#Log3 $name, 1, "Settings pro Device : ".$decode_json->{settings}[$settings]{name};
#Log3 $name, 1, " - KEIN ARRAY" if ( ref( $decode_json->{settings}[$settings]{value} ) ne "ARRAY");
#Log3 $name, 1, " - IST ARRAY" if ( ref( $decode_json->{settings}[$settings]{value} ) eq "ARRAY");
if (
exists( $decode_json->{settings}[$settings]{name} )
&& ( $decode_json->{settings}[$settings]{name} =~
/schedules_paused_until_?\d?$/
|| $decode_json->{settings}[$settings]{name} eq 'eco_mode'
|| $decode_json->{settings}[$settings]{name} eq 'winter_mode' )
)
{
if ( $hash->{helper}
{ $decode_json->{settings}[$settings]{name} . '_id' } ne
$decode_json->{settings}[$settings]{id} )
{
$hash->{helper}{$decode_json->{settings}[$settings]{name}.'_id'} =
$hash->{helper}
{ $decode_json->{settings}[$settings]{name} . '_id' } =
$decode_json->{settings}[$settings]{id};
}
# save winter mode as reading
if ( $decode_json->{settings}[$settings]{name} eq 'winter_mode' ) {
readingsBulkUpdateIfChanged( $hash, 'winter_mode',
$decode_json->{settings}[$settings]{value} );
$winter_mode = $decode_json->{settings}[$settings]{value};
}
}
if ( ref( $decode_json->{settings}[$settings]{value} ) eq "ARRAY"
&& $decode_json->{settings}[$settings]{name} eq 'starting_points' )
{
@ -683,36 +809,69 @@ sub WriteReadings {
$settings--;
} while ( $settings >= 0 );
my $online_state = ReadingsVal($name , 'device_info-connection_status', 'unknown');
if ( $winter_mode ne 'hibernate' ) {
setState($hash);
}
else {
readingsBulkUpdate( $hash, 'state',
RigReadingsValue( $hash, 'hibernate' ) );
}
readingsEndUpdate( $hash, 1 );
Log3 $name, 4, "GardenaSmartDevice ($name) - readings was written";
return;
}
sub setState {
my $hash = shift;
my $name = $hash->{NAME};
my $online_state =
ReadingsVal( $name, 'device_info-connection_status', 'unknown' );
readingsBulkUpdate( $hash, 'state',
$online_state eq 'online' ?
ReadingsVal( $name, 'mower-status', 'readingsValError') : 'offline'
)
$online_state eq 'online'
? ReadingsVal( $name, 'mower-status', 'readingsValError' )
: 'offline' )
if ( AttrVal( $name, 'model', 'unknown' ) eq 'mower' );
readingsBulkUpdate(
$hash, 'state',
(
ReadingsVal( $name, 'watering-watering_timer_1_duration', 0 )
=~ m{\A[1-9]([0-9]+)?\z}xms
ReadingsVal( $name, 'watering-watering_timer_1_duration', 0 ) =~
m{\A[1-9]([0-9]+)?\z}xms
? RigReadingsValue( $hash, 'open' )
: RigReadingsValue( $hash, 'closed' )
)
) if ( AttrVal( $name, 'model', 'unknown' ) eq 'watering_computer' );
if ( AttrVal( $name, 'model', 'unknown' ) eq 'sensor' ) {
my $state_string = ( ReadingsVal($name, 'device_info-category', 'unknown') eq 'sensor') ? 'T: ' .ReadingsVal( $name, 'ambient_temperature-temperature', 'readingsValError' ) . '°C, ' : 'T: ' .ReadingsVal( $name, 'soil_temperature-temperature', 'readingsValError' ) . '°C, ' ;
$state_string .= 'H: '. ReadingsVal( $name, 'humidity-humidity', 'readingsValError' ). '%';
$state_string .= ', L: ' . ReadingsVal( $name, 'light-light', 'readingsValError' ) . 'lux' if (ReadingsVal($name, 'device_info-category', 'unknown') eq 'sensor');
# if ( $online_state eq 'offline') {
# readingsBulkUpdate( $hash, 'humidity-humidity', '-1' );
# readingsBulkUpdate( $hash, 'ambient_temperature-temperature', '-1' ) if (ReadingsVal($name, 'device_info-category', 'unknown') eq 'sensor');
# readingsBulkUpdate( $hash, 'light-light', '-1' ) if (ReadingsVal($name, 'device_info-category', 'unknown') eq 'sensor');
# }
readingsBulkUpdate($hash, 'state', $online_state eq 'online' ? $state_string : 'offline' )
my $state_string =
( ReadingsVal( $name, 'device_info-category', 'unknown' ) eq
'sensor' )
? 'T: '
. ReadingsVal( $name, 'ambient_temperature-temperature',
'readingsValError' )
. '°C, '
: 'T: '
. ReadingsVal( $name, 'soil_temperature-temperature',
'readingsValError' )
. '°C, ';
$state_string .= 'H: '
. ReadingsVal( $name, 'humidity-humidity', 'readingsValError' ) . '%';
$state_string .= ', L: '
. ReadingsVal( $name, 'light-light', 'readingsValError' ) . 'lux'
if ( ReadingsVal( $name, 'device_info-category', 'unknown' ) eq
'sensor' );
# if ( $online_state eq 'offline') {
# readingsBulkUpdate( $hash, 'humidity-humidity', '-1' );
# readingsBulkUpdate( $hash, 'ambient_temperature-temperature', '-1' ) if (ReadingsVal($name, 'device_info-category', 'unknown') eq 'sensor');
# readingsBulkUpdate( $hash, 'light-light', '-1' ) if (ReadingsVal($name, 'device_info-category', 'unknown') eq 'sensor');
# }
readingsBulkUpdate( $hash, 'state',
$online_state eq 'online' ? $state_string : 'offline' );
}
readingsBulkUpdate(
@ -730,10 +889,6 @@ sub WriteReadings {
ReadingsVal( $name, 'power-power_timer', 'no info from power-timer' ) )
if ( AttrVal( $name, 'model', 'unknown' ) eq 'power' );
readingsEndUpdate( $hash, 1 );
Log3 $name, 4, "GardenaSmartDevice ($name) - readings was written";
return;
}
@ -843,7 +998,8 @@ sub ReadingLangGerman {
'closed' => 'geschlossen',
'included' => 'inbegriffen',
'active' => 'aktiv',
'inactive' => 'nicht aktiv'
'inactive' => 'nicht aktiv',
'hibernate' => 'Winterschlaf',
);
if (
@ -897,7 +1053,7 @@ sub Zulu2LocalString {
return (
sprintf(
"%04d-%02d-%02d %02d:%02d:%s",
$lyear, $lmonth, $lday,
$lyear, $lmonth, $lday,
$lhour, $datemin, substr( $rest, 0, 2 )
)
);
@ -918,10 +1074,10 @@ sub Zulu2LocalString {
}
sub SetPredefinedStartPoints {
my $hash = shift;
my $aArg = shift;
my $hash = shift;
my $aArg = shift;
my ($startpoint_state,$startpoint_num,@morestartpoints) = @{$aArg};
my ( $startpoint_state, $startpoint_num, @morestartpoints ) = @{$aArg};
my $name = $hash->{NAME};
my $payload;
@ -969,6 +1125,7 @@ sub SetPredefinedStartPoints {
$payload = '"settings": ' . encode_json($decode_json_settings);
$abilities = 'mower_settings';
#$abilities['service_id'] = $hash->{helper}{STARTINGPOINTID};
}
else {
@ -1125,6 +1282,10 @@ sub SetPredefinedStartPoints {
<a name="GardenaSmartDeviceset"></a>
<b>set</b>
<ul>
<li>winter_mode - awake | hibernate</li>
</ul>
<ul>
<h3>mower</h3>
<li>parkUntilFurtherNotice</li>
<li>parkUntilNextTimer</li>
<li>startOverrideTimer - (in minutes, 60 = 1h, 1440 = 24h, 4320 = 72h)</li>
@ -1134,10 +1295,14 @@ sub SetPredefinedStartPoints {
<li>set NAME startpoint enable 1</li>
<li>set NAME startpoint disable 3 enable 1</li>
</ul>
<h3>irrigation control</h3>
<li>resumeScheduleValve - start schedule irrigation on valve n</li>
<li>stopScheduleValve - stop schedule irrigation on valve n (Default: 2040-12-31T22:00:00.000Z) | optional params hours (now + hours)</li>
<li>stopScheduleValve - stop schedule irrigation on valve n (Default: 2038-01-18T00:00:00.000Z) | optional params hours (now + hours)</li>
<li>closeAllValves - close all valves</li>
<h3>water control</h3>
<li>manualButtonTime - set manual time for button press (in minutes) 0 disable button</li>
<li>stopSchedule - stop schedule for now + n hours (Default: 2038-01-18T00:00:00.000Z)</li>
<li>resumeSchedule - resume schedule</li>
</ul>
</ul>
@ -1273,6 +1438,10 @@ sub SetPredefinedStartPoints {
<a name="GardenaSmartDeviceset"></a>
<b>set</b>
<ul>
<li>winter_mode - aufw&auml;cken (awake)| winterschlaf (hibernate)</li>
</ul>
<ul>
<h3>m&auml;her</h3>
<li>parkUntilFurtherNotice - Parken des M&auml;hers unter Umgehung des Zeitplans</li>
<li>parkUntilNextTimer - Parken bis zum n&auml;chsten Zeitplan</li>
<li>startOverrideTimer - Manuelles m&auml;hen (in Minuten, 60 = 1h, 1440 = 24h, 4320 = 72h)</li>
@ -1282,9 +1451,14 @@ sub SetPredefinedStartPoints {
<li>set NAME startpoint enable 1</li>
<li>set NAME startpoint disable 3 enable 1</li>
</ul>
<h3>irrigation control</h3>
<li>resumeScheduleValve - Startet Bew&aauml;sserung am Ventil n nach Zeitplan</li>
<li>stopScheduleValve - Setzt Bew&aauml;sserung am Ventil n aus (Default: 2040-12-31T22:00:00.000Z) | Optionaler Parameter Stunden (Jetzt + Stunden)</li>
<li>stopScheduleValve - Setzt Bew&aauml;sserung am Ventil n aus (Default: 2038-01-18T00:00:00.000Z) | Optionaler Parameter Stunden (Jetzt + Stunden)</li>
<li>closeAllValves - Stopt Bew&aauml;sserung an allen Ventilen </li>
<h3>water control</h3>
<li>manualButtonTime - setzt die Dauer f&uuml;r den manuellen Knopf (in Minuten) 0 Schaltet den Knopf aus</li>
<li>stopSchedule - Halte Zeitplan an für x Stunden - (Default: 2038-01-18T00:00:00.000Z)</li>
<li>resumeSchedule - Weiterf&uuml;hrung des Zeitplans</li>
</ul>
</ul>
@ -1307,9 +1481,9 @@ sub SetPredefinedStartPoints {
],
"release_status": "stable",
"license": "GPL_2",
"version": "v2.4.0",
"version": "v2.4.3",
"author": [
"Marko Oldenburg <leongaultier@gmail.com>"
"Marko Oldenburg <fhemdevelopment@cooltux.net>"
],
"x_fhem_maintainer": [
"CoolTux"

View File

@ -1,2 +1,2 @@
UPD 2021-05-22_04:53:56 46135 FHEM/73_GardenaSmartBridge.pm
UPD 2021-05-22_04:54:14 51644 FHEM/74_GardenaSmartDevice.pm
UPD 2022-02-01_18:41:32 49520 FHEM/73_GardenaSmartBridge.pm
UPD 2022-02-09_13:50:50 57267 FHEM/74_GardenaSmartDevice.pm