patch #10
@ -57,7 +57,7 @@
|
|||||||
package FHEM::GardenaSmartBridge;
|
package FHEM::GardenaSmartBridge;
|
||||||
use GPUtils qw(GP_Import GP_Export);
|
use GPUtils qw(GP_Import GP_Export);
|
||||||
|
|
||||||
# use Data::Dumper; #only for Debugging
|
#use Data::Dumper; #only for Debugging
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
@ -194,6 +194,7 @@ sub Initialize {
|
|||||||
|
|
||||||
# Consumer
|
# Consumer
|
||||||
$hash->{SetFn} = \&Set;
|
$hash->{SetFn} = \&Set;
|
||||||
|
$hash->{GetFn} = \&Get;
|
||||||
$hash->{DefFn} = \&Define;
|
$hash->{DefFn} = \&Define;
|
||||||
$hash->{UndefFn} = \&Undef;
|
$hash->{UndefFn} = \&Undef;
|
||||||
$hash->{DeleteFn} = \&Delete;
|
$hash->{DeleteFn} = \&Delete;
|
||||||
@ -394,6 +395,29 @@ sub Notify {
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
sub Get {
|
||||||
|
my $hash = shift // return;
|
||||||
|
my $aArg = shift // return;
|
||||||
|
|
||||||
|
my $name = shift @$aArg // return;
|
||||||
|
my $cmd = shift @$aArg
|
||||||
|
// return qq{"get $name" needs at least one argument};
|
||||||
|
|
||||||
|
if ( lc $cmd eq 'debug_devices_list' ) {
|
||||||
|
$hash->{helper}{debug_device_list} = 'get';
|
||||||
|
#Log3 $name, 2, Dumper($hash->{helper});
|
||||||
|
#Write($hash, undef, undef, undef, undef);
|
||||||
|
|
||||||
|
return 'coming soon';
|
||||||
|
} else {
|
||||||
|
my $list = "";
|
||||||
|
$list .= " debug_devices_list:noArg"
|
||||||
|
if ( AttrVal( $name, "debugJSON", "none") ne "none" );
|
||||||
|
|
||||||
|
return "Unknown argument $cmd,choose one of $list";
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sub Set {
|
sub Set {
|
||||||
my $hash = shift // return;
|
my $hash = shift // return;
|
||||||
@ -425,11 +449,6 @@ sub Set {
|
|||||||
|
|
||||||
StorePassword( $hash, $name, $aArg->[0] );
|
StorePassword( $hash, $name, $aArg->[0] );
|
||||||
}
|
}
|
||||||
elsif ( lc $cmd eq 'debug_devices_list' ) {
|
|
||||||
$hash->{helper}{debug_device_list} = 'set';
|
|
||||||
Log3 $name, 2, Dumper($hash->{helper});
|
|
||||||
Write($hash, undef, undef, undef, undef);
|
|
||||||
}
|
|
||||||
elsif ( lc $cmd eq 'deleteaccountpassword' ) {
|
elsif ( lc $cmd eq 'deleteaccountpassword' ) {
|
||||||
return "usage: $cmd" if ( scalar( @{$aArg} ) != 0 );
|
return "usage: $cmd" if ( scalar( @{$aArg} ) != 0 );
|
||||||
|
|
||||||
@ -443,8 +462,6 @@ sub Set {
|
|||||||
if ( not defined( ReadPassword( $hash, $name ) ) );
|
if ( not defined( ReadPassword( $hash, $name ) ) );
|
||||||
$list .= " deleteAccountPassword:noArg"
|
$list .= " deleteAccountPassword:noArg"
|
||||||
if ( defined( ReadPassword( $hash, $name ) ) );
|
if ( defined( ReadPassword( $hash, $name ) ) );
|
||||||
#$list .= " debug_devices_list:noArg"
|
|
||||||
# if ( AttrVal( $name, "debugJSON", "none") ne "none" );
|
|
||||||
return "Unknown argument $cmd, choose one of $list";
|
return "Unknown argument $cmd, choose one of $list";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -452,13 +469,13 @@ sub Set {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub Write {
|
sub Write {
|
||||||
my ( $hash, $payload, $deviceId, $abilities ) = @_;
|
my ( $hash, $payload, $deviceId, $abilities, $service_id ) = @_;
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
my ( $session_id, $header, $uri, $method );
|
my ( $session_id, $header, $uri, $method );
|
||||||
|
|
||||||
( $payload, $session_id, $header, $uri, $method, $deviceId, $abilities ) =
|
( $payload, $session_id, $header, $uri, $method, $deviceId, $service_id ) =
|
||||||
createHttpValueStrings( $hash, $payload, $deviceId, $abilities );
|
createHttpValueStrings( $hash, $payload, $deviceId, $abilities, $service_id );
|
||||||
|
|
||||||
HttpUtils_NonblockingGet(
|
HttpUtils_NonblockingGet(
|
||||||
{
|
{
|
||||||
@ -498,7 +515,7 @@ sub ErrorHandling {
|
|||||||
|
|
||||||
my $dname = $dhash->{NAME};
|
my $dname = $dhash->{NAME};
|
||||||
|
|
||||||
Log3 $name, 2, "GardenaSmartBridge ($name) - Request: $data";
|
Log3 $name, 4, "GardenaSmartBridge ($name) - Request: $data";
|
||||||
|
|
||||||
my $decode_json = eval { decode_json($data) };
|
my $decode_json = eval { decode_json($data) };
|
||||||
if ($@) {
|
if ($@) {
|
||||||
@ -756,9 +773,9 @@ sub ResponseProcessing {
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
elsif ( defined($hash->{helper}{debug_device_list} ) )
|
elsif ( exists($hash->{helper}{debug_device_list} ) )
|
||||||
{
|
{
|
||||||
Log3 $name, 4, "Debug Devices List";
|
Log3 $name, 4, 'Debug Devices List';
|
||||||
my $msg;
|
my $msg;
|
||||||
$msg = "test krams";
|
$msg = "test krams";
|
||||||
|
|
||||||
@ -772,7 +789,7 @@ sub ResponseProcessing {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
undef($hash->{helper}{debug_device_list});
|
delete $hash->{helper}{debug_device_list};
|
||||||
return $msg;
|
return $msg;
|
||||||
}
|
}
|
||||||
elsif (defined( $decode_json->{devices} )
|
elsif (defined( $decode_json->{devices} )
|
||||||
@ -883,7 +900,6 @@ sub WriteReadings {
|
|||||||
$v
|
$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 (
|
if (
|
||||||
(
|
(
|
||||||
$decode_json->{abilities}[0]{properties}
|
$decode_json->{abilities}[0]{properties}
|
||||||
@ -911,7 +927,7 @@ sub WriteReadings {
|
|||||||
{
|
{
|
||||||
#TODO: read valies if bridge connected to wifi
|
#TODO: read valies if bridge connected to wifi
|
||||||
readingsBulkUpdateIfChanged( $hash,
|
readingsBulkUpdateIfChanged( $hash,
|
||||||
'wifi_status-ssid', $v->{ssid} )
|
'wifi_status-ssid', $v->{ssid} )
|
||||||
if (ref($v->{ssid}) ne 'HASH');
|
if (ref($v->{ssid}) ne 'HASH');
|
||||||
readingsBulkUpdateIfChanged( $hash,
|
readingsBulkUpdateIfChanged( $hash,
|
||||||
'wifi_status-mac', $v->{mac} );
|
'wifi_status-mac', $v->{mac} );
|
||||||
@ -1155,7 +1171,7 @@ sub ParseJSON {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub createHttpValueStrings {
|
sub createHttpValueStrings {
|
||||||
my ( $hash, $payload, $deviceId, $abilities ) = @_;
|
my ( $hash, $payload, $deviceId, $abilities, $service_id ) = @_;
|
||||||
|
|
||||||
my $session_id = $hash->{helper}{session_id};
|
my $session_id = $hash->{helper}{session_id};
|
||||||
my $header = "Content-Type: application/json";
|
my $header = "Content-Type: application/json";
|
||||||
@ -1192,15 +1208,31 @@ sub createHttpValueStrings {
|
|||||||
|
|
||||||
$method = 'PUT';
|
$method = 'PUT';
|
||||||
my $dhash = $modules{GardenaSmartDevice}{defptr}{$deviceId};
|
my $dhash = $modules{GardenaSmartDevice}{defptr}{$deviceId};
|
||||||
|
|
||||||
$uri .=
|
$uri .=
|
||||||
'/devices/'
|
'/devices/'
|
||||||
. $deviceId
|
. $deviceId
|
||||||
. '/settings/'
|
. '/settings/'
|
||||||
. $dhash->{helper}{STARTINGPOINTID}
|
. $service_id
|
||||||
if ( defined($abilities)
|
if ( defined($abilities)
|
||||||
&& defined($payload)
|
&& defined($payload)
|
||||||
&& $abilities eq 'mower_settings' );
|
&& $abilities eq 'mower_settings' );
|
||||||
|
|
||||||
|
} # park until next schedules or override
|
||||||
|
elsif (defined($abilities)
|
||||||
|
&& defined($payload)
|
||||||
|
&& $abilities eq 'mower_timer' )
|
||||||
|
{
|
||||||
|
my $valve_id;
|
||||||
|
$method = 'PUT';
|
||||||
|
|
||||||
|
$uri .=
|
||||||
|
'/devices/'
|
||||||
|
. $deviceId
|
||||||
|
. '/abilities/'
|
||||||
|
. $abilities
|
||||||
|
. '/properties/mower_timer';
|
||||||
|
|
||||||
}
|
}
|
||||||
elsif (defined($abilities)
|
elsif (defined($abilities)
|
||||||
&& defined($payload)
|
&& defined($payload)
|
||||||
@ -1419,7 +1451,7 @@ sub DeletePassword {
|
|||||||
],
|
],
|
||||||
"release_status": "stable",
|
"release_status": "stable",
|
||||||
"license": "GPL_2",
|
"license": "GPL_2",
|
||||||
"version": "v2.2.1",
|
"version": "v2.2.2",
|
||||||
"author": [
|
"author": [
|
||||||
"Marko Oldenburg <leongaultier@gmail.com>"
|
"Marko Oldenburg <leongaultier@gmail.com>"
|
||||||
],
|
],
|
||||||
|
@ -63,7 +63,7 @@ use POSIX;
|
|||||||
use FHEM::Meta;
|
use FHEM::Meta;
|
||||||
use Time::Local;
|
use Time::Local;
|
||||||
|
|
||||||
use Data::Dumper; # only for debugging
|
#use Data::Dumper; # only for debugging
|
||||||
|
|
||||||
# try to use JSON::MaybeXS wrapper
|
# try to use JSON::MaybeXS wrapper
|
||||||
# for chance of better performance + open code
|
# for chance of better performance + open code
|
||||||
@ -203,9 +203,11 @@ sub Define {
|
|||||||
my $deviceId = $aArg->[2];
|
my $deviceId = $aArg->[2];
|
||||||
my $category = $aArg->[3];
|
my $category = $aArg->[3];
|
||||||
|
|
||||||
$hash->{DEVICEID} = $deviceId;
|
$hash->{DEVICEID} = $deviceId;
|
||||||
$hash->{VERSION} = version->parse($VERSION)->normal;
|
$hash->{VERSION} = version->parse($VERSION)->normal;
|
||||||
$hash->{helper}{STARTINGPOINTID} = '';
|
$hash->{helper}{STARTINGPOINTID} = '';
|
||||||
|
$hash->{helper}{schedules_paused_until_id} = '';
|
||||||
|
$hash->{helper}{eco_mode_id} = '';
|
||||||
|
|
||||||
CommandAttr( undef,
|
CommandAttr( undef,
|
||||||
"$name IODev $modules{GardenaSmartBridge}{defptr}{BRIDGE}->{NAME}" )
|
"$name IODev $modules{GardenaSmartBridge}{defptr}{BRIDGE}->{NAME}" )
|
||||||
@ -277,30 +279,53 @@ sub Set {
|
|||||||
|
|
||||||
my $payload;
|
my $payload;
|
||||||
my $abilities = '';
|
my $abilities = '';
|
||||||
|
my $service_id = '';
|
||||||
### mower
|
### mower
|
||||||
|
# service_id (eco, parkuntilfurhternotice, startpoints)
|
||||||
if ( lc $cmd eq 'parkuntilfurthernotice' ) {
|
if ( lc $cmd eq 'parkuntilfurthernotice' ) {
|
||||||
$payload = '"name":"park_until_further_notice"';
|
$payload = '"name":"park_until_further_notice"';
|
||||||
|
if ( ReadingsVal( $name, 'mower_type-mainboard_version', '0.0' ) > '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};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
elsif ( lc $cmd eq 'parkuntilnexttimer' ) {
|
elsif ( lc $cmd eq 'parkuntilnexttimer' ) {
|
||||||
$payload = '"name":"park_until_next_timer"';
|
$payload = '"name":"park_until_next_timer"';
|
||||||
|
if ( ReadingsVal( $name, 'mower_type-mainboard_version', '0.0' ) > '10.30' ){
|
||||||
|
$payload = '"properties":{"name":"mower_timer","value":0}' ;
|
||||||
|
$abilities = 'mower_timer';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
elsif ( lc $cmd eq 'startresumeschedule' ) {
|
elsif ( lc $cmd eq 'startresumeschedule' ) {
|
||||||
$payload = '"name":"start_resume_schedule"';
|
$payload = '"name":"start_resume_schedule"';
|
||||||
|
if ( ReadingsVal( $name, 'mower_type-mainboard_version', '0.0' ) > '10.30' ) {
|
||||||
|
$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' ) {
|
elsif ( lc $cmd eq 'startoverridetimer' ) {
|
||||||
$payload = '"name":"start_override_timer","parameters":{"duration":'
|
$payload = '"name":"start_override_timer","parameters":{"duration":'
|
||||||
. $aArg->[0] * 60 . '}';
|
. $aArg->[0] * 60 . '}';
|
||||||
|
if ( ReadingsVal( $name, 'mower_type-mainboard_version', '0.0' ) > '10.30' ){
|
||||||
|
$payload = '"properties":{"name":"mower_timer","value":'.$aArg->[0] * 60 .'}';
|
||||||
|
$abilities = 'mower_timer';
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
elsif ( lc $cmd eq 'startpoint' ) {
|
elsif ( lc $cmd eq 'startpoint' ) {
|
||||||
my $err;
|
my $err;
|
||||||
|
|
||||||
( $err, $payload, $abilities ) = SetPredefinedStartPoints( $hash, $aArg );
|
( $err, $payload, $abilities ) = SetPredefinedStartPoints( $hash, $aArg );
|
||||||
|
$service_id = $hash->{helper}{STARTINGPOINTID};
|
||||||
return $err if ( defined($err) );
|
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 ( ReadingsVal( $name, 'mower_type-mainboard_version', '0.0' ) > '10.30' );
|
||||||
|
$service_id = $hash->{helper}{eco_mode_id};
|
||||||
|
#$abilities['service_id'] = $hash->{helper}{SCHEDULESID} if ( ReadingsVal( $name, 'mower_type-mainboard_version', '0.0' ) > '10.30' );
|
||||||
|
}
|
||||||
### electronic_pressure_pump
|
### electronic_pressure_pump
|
||||||
elsif ( lc $cmd eq 'pumptimer' ) {
|
elsif ( lc $cmd eq 'pumptimer' ) {
|
||||||
$payload =
|
$payload =
|
||||||
@ -402,7 +427,7 @@ sub Set {
|
|||||||
|
|
||||||
$abilities = 'mower'
|
$abilities = 'mower'
|
||||||
if ( AttrVal( $name, 'model', 'unknown' ) eq 'mower' )
|
if ( AttrVal( $name, 'model', 'unknown' ) eq 'mower' )
|
||||||
&& $abilities ne 'mower_settings';
|
&& ($abilities !~ /mower_settings|mower_timer/);
|
||||||
$abilities = 'watering'
|
$abilities = 'watering'
|
||||||
if ( AttrVal( $name, 'model', 'unknown' ) eq 'ic24'
|
if ( AttrVal( $name, 'model', 'unknown' ) eq 'ic24'
|
||||||
|| AttrVal( $name, 'model', 'unknown' ) eq 'watering_computer' );
|
|| AttrVal( $name, 'model', 'unknown' ) eq 'watering_computer' );
|
||||||
@ -414,7 +439,7 @@ sub Set {
|
|||||||
$hash->{helper}{deviceAction} = $payload;
|
$hash->{helper}{deviceAction} = $payload;
|
||||||
readingsSingleUpdate( $hash, "state", "send command to gardena cloud", 1 );
|
readingsSingleUpdate( $hash, "state", "send command to gardena cloud", 1 );
|
||||||
|
|
||||||
IOWrite( $hash, $payload, $hash->{DEVICEID}, $abilities );
|
IOWrite( $hash, $payload, $hash->{DEVICEID}, $abilities, $service_id );
|
||||||
Log3 $name, 4,
|
Log3 $name, 4,
|
||||||
"GardenaSmartBridge ($name) - IOWrite: $payload $hash->{DEVICEID} $abilities IODevHash=$hash->{IODev}";
|
"GardenaSmartBridge ($name) - IOWrite: $payload $hash->{DEVICEID} $abilities IODevHash=$hash->{IODev}";
|
||||||
|
|
||||||
@ -573,7 +598,21 @@ sub WriteReadings {
|
|||||||
} while ( $abilities >= 0 );
|
} while ( $abilities >= 0 );
|
||||||
|
|
||||||
do {
|
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 ( $decode_json->{settings}[$settings]{name} eq 'schedules_paused_until'
|
||||||
|
|| $decode_json->{settings}[$settings]{name} eq 'eco_mode'
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if ( $hash->{helper}{$decode_json->{settings}[$settings]{name}.'_id'} ne
|
||||||
|
$decode_json->{settings}[$settings]{id} )
|
||||||
|
{
|
||||||
|
$hash->{helper}{$decode_json->{settings}[$settings]{name}.'_id'} =
|
||||||
|
$decode_json->{settings}[$settings]{id};
|
||||||
|
}
|
||||||
|
}
|
||||||
if ( ref( $decode_json->{settings}[$settings]{value} ) eq "ARRAY"
|
if ( ref( $decode_json->{settings}[$settings]{value} ) eq "ARRAY"
|
||||||
&& $decode_json->{settings}[$settings]{name} eq 'starting_points' )
|
&& $decode_json->{settings}[$settings]{name} eq 'starting_points' )
|
||||||
{
|
{
|
||||||
@ -883,6 +922,7 @@ sub SetPredefinedStartPoints {
|
|||||||
|
|
||||||
$payload = '"settings": ' . encode_json($decode_json_settings);
|
$payload = '"settings": ' . encode_json($decode_json_settings);
|
||||||
$abilities = 'mower_settings';
|
$abilities = 'mower_settings';
|
||||||
|
#$abilities['service_id'] = $hash->{helper}{STARTINGPOINTID};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return
|
return
|
||||||
@ -1213,7 +1253,7 @@ sub SetPredefinedStartPoints {
|
|||||||
],
|
],
|
||||||
"release_status": "stable",
|
"release_status": "stable",
|
||||||
"license": "GPL_2",
|
"license": "GPL_2",
|
||||||
"version": "v2.0.3",
|
"version": "v2.0.4",
|
||||||
"author": [
|
"author": [
|
||||||
"Marko Oldenburg <leongaultier@gmail.com>"
|
"Marko Oldenburg <leongaultier@gmail.com>"
|
||||||
],
|
],
|
||||||
|
Reference in New Issue
Block a user