add new mower firmeware cmds

This commit is contained in:
Sebastian 2021-04-07 17:41:05 +02:00
parent a07f380df6
commit dd931efbc4
2 changed files with 80 additions and 24 deletions

View File

@ -405,9 +405,9 @@ sub Get {
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);
*/
#Log3 $name, 2, Dumper($hash->{helper});
#Write($hash, undef, undef, undef, undef);
return 'coming soon';
} else {
my $list = "";
@ -469,13 +469,13 @@ sub Set {
}
sub Write {
my ( $hash, $payload, $deviceId, $abilities ) = @_;
my ( $hash, $payload, $deviceId, $abilities, $service_id ) = @_;
my $name = $hash->{NAME};
my ( $session_id, $header, $uri, $method );
( $payload, $session_id, $header, $uri, $method, $deviceId, $abilities ) =
createHttpValueStrings( $hash, $payload, $deviceId, $abilities );
( $payload, $session_id, $header, $uri, $method, $deviceId, $service_id ) =
createHttpValueStrings( $hash, $payload, $deviceId, $abilities, $service_id );
HttpUtils_NonblockingGet(
{
@ -495,8 +495,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;
}
@ -1171,7 +1171,7 @@ sub ParseJSON {
}
sub createHttpValueStrings {
my ( $hash, $payload, $deviceId, $abilities ) = @_;
my ( $hash, $payload, $deviceId, $abilities, $service_id ) = @_;
my $session_id = $hash->{helper}{session_id};
my $header = "Content-Type: application/json";
@ -1208,15 +1208,31 @@ sub createHttpValueStrings {
$method = 'PUT';
my $dhash = $modules{GardenaSmartDevice}{defptr}{$deviceId};
$uri .=
'/devices/'
. $deviceId
. '/settings/'
. $dhash->{helper}{STARTINGPOINTID}
. $service_id
if ( defined($abilities)
&& defined($payload)
&& $abilities eq 'mower_settings' );
} # park until next scheduel
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)
&& defined($payload)

View File

@ -63,7 +63,7 @@ use POSIX;
use FHEM::Meta;
use Time::Local;
use Data::Dumper; # only for debugging
#use Data::Dumper; # only for debugging
# try to use JSON::MaybeXS wrapper
# for chance of better performance + open code
@ -203,9 +203,11 @@ sub Define {
my $deviceId = $aArg->[2];
my $category = $aArg->[3];
$hash->{DEVICEID} = $deviceId;
$hash->{VERSION} = version->parse($VERSION)->normal;
$hash->{helper}{STARTINGPOINTID} = '';
$hash->{DEVICEID} = $deviceId;
$hash->{VERSION} = version->parse($VERSION)->normal;
$hash->{helper}{STARTINGPOINTID} = '';
$hash->{helper}{schedules_paused_until_id} = '';
$hash->{helper}{eco_mode_id} = '';
CommandAttr( undef,
"$name IODev $modules{GardenaSmartBridge}{defptr}{BRIDGE}->{NAME}" )
@ -277,30 +279,53 @@ sub Set {
my $payload;
my $abilities = '';
### mower
my $service_id = '';
### mower
# service_id (eco, parkuntilfurhternotice, startpoints)
if ( lc $cmd eq 'parkuntilfurthernotice' ) {
$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"';
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' ) {
$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' ) {
$payload = '"name":"start_override_timer","parameters":{"duration":'
. $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' ) {
my $err;
( $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 ( 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
elsif ( lc $cmd eq 'pumptimer' ) {
$payload =
@ -399,10 +424,10 @@ sub Set {
return "Unknown argument $cmd, choose one of $list";
}
$abilities = 'mower'
if ( AttrVal( $name, 'model', 'unknown' ) eq 'mower' )
&& $abilities ne 'mower_settings';
&& ($abilities !~ /mower_settings|mower_timer/);
$abilities = 'watering'
if ( AttrVal( $name, 'model', 'unknown' ) eq 'ic24'
|| AttrVal( $name, 'model', 'unknown' ) eq 'watering_computer' );
@ -414,7 +439,7 @@ sub Set {
$hash->{helper}{deviceAction} = $payload;
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,
"GardenaSmartBridge ($name) - IOWrite: $payload $hash->{DEVICEID} $abilities IODevHash=$hash->{IODev}";
@ -573,7 +598,21 @@ sub WriteReadings {
} 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");
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"
&& $decode_json->{settings}[$settings]{name} eq 'starting_points' )
{
@ -883,6 +922,7 @@ sub SetPredefinedStartPoints {
$payload = '"settings": ' . encode_json($decode_json_settings);
$abilities = 'mower_settings';
#$abilities['service_id'] = $hash->{helper}{STARTINGPOINTID};
}
else {
return
@ -1213,7 +1253,7 @@ sub SetPredefinedStartPoints {
],
"release_status": "stable",
"license": "GPL_2",
"version": "v2.0.3",
"version": "v2.0.4",
"author": [
"Marko Oldenburg <leongaultier@gmail.com>"
],