From 9e54af515b85f4ff1e4cc7f304b862170ab3c862 Mon Sep 17 00:00:00 2001 From: LeonGaultier Date: Fri, 3 May 2024 10:52:43 +0000 Subject: [PATCH] 74_GardenaSmartDevice: fix patch code scheduling by hhhdg git-svn-id: https://svn.fhem.de/fhem/trunk@28833 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/73_GardenaSmartBridge.pm | 98 ++++++++++++++++++------------ fhem/FHEM/74_GardenaSmartDevice.pm | 76 +++++++++++++++-------- 3 files changed, 112 insertions(+), 63 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 76bc657c1..26587bf1a 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it + - bugfix: 74_GardenaSmartDevice: fix patch code scheduling by hhhdg - feature: 74_AutomowerConnect.pm: new mower schedule editor - bugfix: 76_SolarForecast: possible Illegal division by zero if Attr ctrlGenPVdeviation is set to continuously diff --git a/fhem/FHEM/73_GardenaSmartBridge.pm b/fhem/FHEM/73_GardenaSmartBridge.pm index fe21726ce..524578ee7 100644 --- a/fhem/FHEM/73_GardenaSmartBridge.pm +++ b/fhem/FHEM/73_GardenaSmartBridge.pm @@ -2,7 +2,7 @@ # # Developed with VSCodium and richterger perl plugin. # -# (c) 2017-2022 Copyright: Marko Oldenburg (fhemdevelopment at cooltux dot net) +# (c) 2017-2024 Copyright: Marko Oldenburg (fhemdevelopment at cooltux dot net) # All rights reserved # # Special thanks goes to comitters: @@ -75,9 +75,9 @@ eval { use IO::Socket::SSL; 1 } # try to use JSON::MaybeXS wrapper # for chance of better performance + open code eval { - require JSON::MaybeXS; - import JSON::MaybeXS qw( decode_json encode_json ); - 1; + require JSON::MaybeXS; + import JSON::MaybeXS qw( decode_json encode_json ); + 1; } or do { # try to use JSON wrapper @@ -629,31 +629,32 @@ sub ErrorHandling { if ($decode_json) { if ( ref( $decode_json->{errors} ) eq "ARRAY" && exists( $decode_json->{errors} ) ) - # replace defined with exists - # && defined( $decode_json->{errors} ) ) + + # replace defined with exists + # && defined( $decode_json->{errors} ) ) { # $decode_json->{errors} -> ARRAY # $decode_json->{errors}[0] -> HASH - if (exists ($decode_json->{errors}[0]{error}) ) { - readingsBulkUpdate( - $dhash, - "state", - $decode_json->{errors}[0]{error} . ' ' - . $decode_json->{errors}[0]{attribute}, - 1 - ); - readingsBulkUpdate( - $dhash, - "lastRequestState", - $decode_json->{errors}[0]{error} . ' ' - . $decode_json->{errors}[0]{attribute}, - 1 - ); - Log3 $dname, 5, - "GardenaSmartBridge ($dname) - RequestERROR: " - . $decode_json->{errors}[0]{error} . " " - . $decode_json->{errors}[0]{attribute}; - } # fi exists error + if ( exists( $decode_json->{errors}[0]{error} ) ) { + readingsBulkUpdate( + $dhash, + "state", + $decode_json->{errors}[0]{error} . ' ' + . $decode_json->{errors}[0]{attribute}, + 1 + ); + readingsBulkUpdate( + $dhash, + "lastRequestState", + $decode_json->{errors}[0]{error} . ' ' + . $decode_json->{errors}[0]{attribute}, + 1 + ); + Log3 $dname, 5, + "GardenaSmartBridge ($dname) - RequestERROR: " + . $decode_json->{errors}[0]{error} . " " + . $decode_json->{errors}[0]{attribute}; + } # fi exists error } } else { @@ -1059,6 +1060,20 @@ sub WriteReadings { if ( ref($v) eq 'ARRAY' ); #$v = encode_utf8($v); + $v = ' ' if ( !defined $v ); + Log3 $name, 4, + "Gardena DEBUG DEBUG DEBUG stage 1 " + . $decode_json->{abilities}[0]{properties}[$properties] + {name} + if ( $decode_json->{abilities}[0]{properties}[$properties] + {name} !~ /ethernet_status|wifi_status/ ); + Log3 $name, 4, "Gardena DEBUG DEBUG DEBUG stage 2" . $t + if ( $decode_json->{abilities}[0]{properties}[$properties] + {name} !~ /ethernet_status|wifi_status/ ); + Log3 $name, 4, "Gardena DEBUG DEBUG DEBUG stage 3" . $v + if ( $decode_json->{abilities}[0]{properties}[$properties] + {name} !~ /ethernet_status|wifi_status/ ); + readingsBulkUpdateIfChanged( $hash, $decode_json->{abilities}[0]{properties}[$properties] @@ -1076,16 +1091,22 @@ sub WriteReadings { ) && ref($v) eq 'HASH' ) - { - if ($v->{is_connected} ) { - readingsBulkUpdateIfChanged( $hash, - $decode_json->{abilities}[0]{properties}[$properties]{name}.'-ip', $v->{ip} ) - if ( ref( $v->{ip} ) ne 'HASH' ); - readingsBulkUpdateIfChanged( $hash, - $decode_json->{abilities}[0]{properties}[$properties]{name}.'-isconnected', $v->{is_connected} ) - if ( $v->{is_connected} ); + { + if ( $v->{is_connected} ) { + readingsBulkUpdateIfChanged( + $hash, + $decode_json->{abilities}[0]{properties} + [$properties]{name} . '-ip', + $v->{ip} + ) if ( ref( $v->{ip} ) ne 'HASH' ); + readingsBulkUpdateIfChanged( + $hash, + $decode_json->{abilities}[0]{properties} + [$properties]{name} . '-isconnected', + $v->{is_connected} + ) if ( $v->{is_connected} ); } - } # fi ethernet and wifi + } # fi ethernet and wifi } $properties--; @@ -1315,17 +1336,16 @@ sub createHttpValueStrings { } # park until next schedules or override elsif (defined($abilities) && defined($payload) - && $abilities eq 'mower_timer' ) + && $abilities eq 'mower' ) { my $valve_id; - $method = 'PUT'; $uri .= '/devices/' . $deviceId . '/abilities/' . $abilities - . '/properties/mower_timer'; + . '/commands/manual_start'; } elsif (defined($abilities) @@ -1561,7 +1581,7 @@ sub DeletePassword { ], "release_status": "stable", "license": "GPL_2", - "version": "v2.6.1", + "version": "v2.6.2", "author": [ "Marko Oldenburg " ], diff --git a/fhem/FHEM/74_GardenaSmartDevice.pm b/fhem/FHEM/74_GardenaSmartDevice.pm index 7cff62549..60d0f5c6f 100644 --- a/fhem/FHEM/74_GardenaSmartDevice.pm +++ b/fhem/FHEM/74_GardenaSmartDevice.pm @@ -2,7 +2,7 @@ # # Developed with VSCodium and richterger perl plugin. # -# (c) 2017-2022 Copyright: Marko Oldenburg (fhemdevelopment at cooltux dot net) +# (c) 2017-2024 Copyright: Marko Oldenburg (fhemdevelopment at cooltux dot net) # All rights reserved # # Special thanks goes to comitters: @@ -324,8 +324,9 @@ sub Set { 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'; + $payload = + '"mowerTimer":0,"startingPointDistance":null,"areaId":null'; + $abilities = 'mower'; } } elsif ( lc $cmd eq 'startresumeschedule' ) { @@ -339,13 +340,15 @@ sub Set { } } 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'; - } + + # $payload = '"name":"start_override_timer","parameters":{"duration":' + # . $aArg->[0] * 60 . '}'; + # if ( $mainboard_version > 10.30 ) { + $payload = '"startingPointDistance":null,"areaId":null, "mowerTimer": ' + . $aArg->[0] * 60; + $abilities = 'mower'; + + # } removed code < 10.30 api changes March 2024 } elsif ( lc $cmd eq 'startpoint' ) { @@ -735,7 +738,8 @@ sub WriteReadings { . RigReadingsValue( $hash, $propertie->{value} ) # cast all data to string with "" ) - if ( exists( $propertie->{value} ) + if ( + exists( $propertie->{value} ) && $decode_json->{abilities}[$abilities]{name} . '-' . $propertie->{name} ne 'radio-quality' && $decode_json->{abilities}[$abilities]{name} . '-' @@ -754,7 +758,10 @@ sub WriteReadings { . $propertie->{name} ne 'ic24-valves_connected' && $decode_json->{abilities}[$abilities]{name} . '-' . $propertie->{name} ne 'ic24-valves_master_config' - && ref( $propertie->{value} ) ne "HASH" ); + && ( $decode_json->{abilities}[$abilities]{name} . '-' + . $propertie->{name} ) !~ /scheduling-timeslot_state_\d/ + && ref( $propertie->{value} ) ne "HASH" + ); readingsBulkUpdateIfChanged( $hash, @@ -851,7 +858,30 @@ sub WriteReadings { } } - # ic24 and other watering devices calc irrigation left in sec + # decode timeslot_state_N arrays code by hhhdg + if ( defined( $propertie->{value} ) + && $decode_json->{abilities}[$abilities]{name} . '-' + . $propertie->{name} =~ /scheduling-timeslot_state_\d/ + && ref( $propertie->{value} ) eq "ARRAY" ) + { + while ( my ( $r, $v ) = each @{ $propertie->{value} } ) { + if ( ref($v) eq "HASH" ) { + my $entry = $r + 1; + while ( my ( $i_r, $i_v ) = each %{$v} ) { + readingsBulkUpdateIfChanged( + $hash, + $decode_json->{abilities}[$abilities]{name} + . '-' + . $propertie->{name} . '_' + . $entry . '_' + . $i_r, + RigReadingsValue( $hash, $i_v ) + ); + } + } + } + } # fi defined + # ic24 and other watering devices calc irrigation left in sec readingsBulkUpdateIfChanged( $hash, $decode_json->{abilities}[$abilities]{name} . '-' @@ -907,15 +937,15 @@ sub WriteReadings { foreach my $dev_schedules ( sort keys %{ $hash->{READINGS} } ) { my $dev_reading = ReadingsVal( $name, $dev_schedules, "error" ); push @ist, $dev_reading - if $dev_schedules =~ /schedule.*\d_id/; # push reading _id + if $dev_schedules =~ /schedule.*\d+_id/; # push reading _id push @ist, $1 if $dev_schedules =~ - /schedule.*_(\d)_id/; # push readigs d from x_id + /schedule.*_(\d+)_id/; # push readigs d from x_id Log3 $name, 5, "[DEBUG] $name - Schedule - Key ist : $dev_schedules "; Log3 $name, 5, "[DEBUG] $name - Schedule - ID FOUND $dev_reading" - if $dev_schedules =~ /schedule.*_\d_id/; # cloud hat SOLL + if $dev_schedules =~ /schedule.*_\d+_id/; # cloud hat SOLL } #Log3 $name, 5, "[DEBUG] Cloud:".Dumper(@soll) . "- Internal:". Dumper(@ist); @@ -951,15 +981,13 @@ sub WriteReadings { && scalar(@soll) != scalar( @ist / 2 ) ) { while ( my $old_schedule_id = shift(@ist) ) { - if ( length($old_schedule_id) == 1 ) { - foreach ( keys %{ $hash->{READINGS} } ) { - delete $hash->{READINGS}->{$_} - if ( $_ =~ - /scheduling-schedules_event_$old_schedule_id.*/ ); - } + foreach ( keys %{ $hash->{READINGS} } ) { + delete $hash->{READINGS}->{$_} + if ( $_ =~ + /scheduling-schedules_event_${old_schedule_id}_.*/ ); } # fi Log3 $name, 5, -"[DEBUG] - $name : deletereading scheduling-schedules_event_$old_schedule_id.*" +"[DEBUG] - $name : deletereading scheduling-schedules_event_${old_schedule_id}_.*" if length($old_schedule_id) == 1; } } @@ -2684,7 +2712,7 @@ sub SetPredefinedStartPoints { ], "release_status": "stable", "license": "GPL_2", - "version": "v2.6.1", + "version": "v2.6.3", "author": [ "Marko Oldenburg " ],