From 59e267e9b15ed71e8a685241cdaca6456ca6b917 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 15 Apr 2021 13:01:30 +0200 Subject: [PATCH 01/17] add some debug funktion --- FHEM/73_GardenaSmartBridge.pm | 80 ++++++++++++++++++++++++++--------- 1 file changed, 59 insertions(+), 21 deletions(-) diff --git a/FHEM/73_GardenaSmartBridge.pm b/FHEM/73_GardenaSmartBridge.pm index 7517fd6..5076537 100644 --- a/FHEM/73_GardenaSmartBridge.pm +++ b/FHEM/73_GardenaSmartBridge.pm @@ -156,8 +156,11 @@ BEGIN { readingsBeginUpdate readingsEndUpdate Log3 + devspec2array + asyncOutput CommandAttr AttrVal + InternalVal ReadingsVal CommandDefMod modules @@ -402,17 +405,31 @@ sub Get { 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); + my $device = shift @$aArg; + $hash->{helper}{debug_device} = $device; + Write($hash, undef, undef, undef, undef); + #while (!defined ($hash->{helper}{debug_device_output} )){ + # select(undef, undef, undef, 0.5); + #} + #Log3 $name, 2, "OUTPUT".$hash->{helper}{debug_device_output}; + #delete $hash->{helper}{debug_device}; + #delete $hash->{helper}{debug_device_output}; - return 'coming soon'; + return undef; #$hash->{helper}{debug_device_output}; + }elsif ( lc $cmd eq 'debug_device' ) { + Log3 $name, 2, "DEBUG DEVICE INFOS Device $hash->{helper}{debug_device}"; + delete $hash->{helper}{debug_device}; + return $hash->{helper}{debug_device_output}; + } else { my $list = ""; - $list .= " debug_devices_list:noArg" - if ( AttrVal( $name, "debugJSON", "none") ne "none" ); + $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"; @@ -487,6 +504,7 @@ sub Write { method => $method, header => $header, doTrigger => 1, + cl => $hash->{CL}, callback => \&ErrorHandling } ); @@ -514,7 +532,9 @@ sub ErrorHandling { if ( defined( $param->{'device_id'} ) ); my $dname = $dhash->{NAME}; - + + #$param->{cl} = $hash->{CL} if( $hash->{TOKEN} and ref($hash->{CL}) eq 'HASH' ); + Log3 $name, 4, "GardenaSmartBridge ($name) - Request: $data"; my $decode_json = eval { decode_json($data) }; @@ -709,7 +729,31 @@ 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"; + } + } + $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} ) ); ResponseProcessing( $hash, $data ) @@ -773,19 +817,6 @@ sub ResponseProcessing { return; } - elsif ( exists($hash->{helper}{debug_device_list}) ) { - Log3 $name, 4, "Debug Devices List"; - my $msg; - $msg = "test krams"; - - my @buffer = split( '"devices":\[', $json ); - my ( $json, $tail ) = ParseJSON( $hash, $buffer[1] ); - - $decode_json = eval { decode_json($json) }; - - delete $hash->{helper}{debug_device_list}; - return $msg; - } elsif (defined( $decode_json->{devices} ) && ref( $decode_json->{devices} ) eq 'ARRAY' && scalar( @{ $decode_json->{devices} } ) > 0 ) @@ -960,6 +991,12 @@ sub getDevices { if ( not IsDisabled($name) ) { + delete $hash->{helper}{deviceList}; + my @list; + @list = devspec2array('TYPE=GardenaSmartDevice'); + 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"; @@ -1195,6 +1232,7 @@ sub createHttpValueStrings { && defined( $hash->{helper}{locations_id} ) ); } + $uri = '/devices/'.InternalVal($hash->{helper}{debug_device}, 'DEVICEID', 0 ) if ( exists ($hash->{helper}{debug_device})); $uri = '/auth/token' if ( !defined( $hash->{helper}{session_id} ) ); if ( defined( $hash->{helper}{locations_id} ) ) { From 0943335044f372526306aec43676794643d69113 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 16 Apr 2021 11:10:38 +0200 Subject: [PATCH 02/17] clean up code --- FHEM/73_GardenaSmartBridge.pm | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/FHEM/73_GardenaSmartBridge.pm b/FHEM/73_GardenaSmartBridge.pm index 5076537..efd00dd 100644 --- a/FHEM/73_GardenaSmartBridge.pm +++ b/FHEM/73_GardenaSmartBridge.pm @@ -405,34 +405,19 @@ sub Get { 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' ) { my $device = shift @$aArg; $hash->{helper}{debug_device} = $device; - Write($hash, undef, undef, undef, undef); - #while (!defined ($hash->{helper}{debug_device_output} )){ - # select(undef, undef, undef, 0.5); - #} - #Log3 $name, 2, "OUTPUT".$hash->{helper}{debug_device_output}; - #delete $hash->{helper}{debug_device}; - #delete $hash->{helper}{debug_device_output}; - - return undef; #$hash->{helper}{debug_device_output}; - }elsif ( lc $cmd eq 'debug_device' ) { - Log3 $name, 2, "DEBUG DEVICE INFOS Device $hash->{helper}{debug_device}"; - delete $hash->{helper}{debug_device}; - return $hash->{helper}{debug_device_output}; - + Write($hash, undef, undef, undef, undef); + return undef; } 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"; - + 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"; } } @@ -533,8 +518,6 @@ sub ErrorHandling { my $dname = $dhash->{NAME}; - #$param->{cl} = $hash->{CL} if( $hash->{TOKEN} and ref($hash->{CL}) eq 'HASH' ); - Log3 $name, 4, "GardenaSmartBridge ($name) - Request: $data"; my $decode_json = eval { decode_json($data) }; From 450a6ce7547a4d530aaf80953483bd7936d17c74 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Thu, 22 Apr 2021 18:19:46 +0200 Subject: [PATCH 03/17] change head of module files --- FHEM/73_GardenaSmartBridge.pm | 2 +- FHEM/74_GardenaSmartDevice.pm | 4 ++-- controls_GardenaSmartDevice.txt | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/FHEM/73_GardenaSmartBridge.pm b/FHEM/73_GardenaSmartBridge.pm index efd00dd..79ab0d9 100644 --- a/FHEM/73_GardenaSmartBridge.pm +++ b/FHEM/73_GardenaSmartBridge.pm @@ -2,7 +2,7 @@ # # Developed with Kate # -# (c) 2017-2019 Copyright: Marko Oldenburg (leongaultier at gmail dot com) +# (c) 2017-2011 Copyright: Marko Oldenburg (fhemdevelopment at cooltux dot net) # All rights reserved # # Special thanks goes to comitters: diff --git a/FHEM/74_GardenaSmartDevice.pm b/FHEM/74_GardenaSmartDevice.pm index bdd4e00..970216f 100644 --- a/FHEM/74_GardenaSmartDevice.pm +++ b/FHEM/74_GardenaSmartDevice.pm @@ -2,7 +2,7 @@ # # Developed with Kate # -# (c) 2017-2019 Copyright: Marko Oldenburg (leongaultier at gmail dot com) +# (c) 2017-2021 Copyright: Marko Oldenburg (fhemdevelopment at cooltux dot net) # All rights reserved # # Special thanks goes to comitters: @@ -687,7 +687,7 @@ sub WriteReadings { readingsEndUpdate( $hash, 1 ); - Log3 $name, 4, "GardenaSmartDevice ($name) - readings was written}"; + Log3 $name, 4, "GardenaSmartDevice ($name) - readings was written"; return; } diff --git a/controls_GardenaSmartDevice.txt b/controls_GardenaSmartDevice.txt index b23262b..47d0a64 100644 --- a/controls_GardenaSmartDevice.txt +++ b/controls_GardenaSmartDevice.txt @@ -1,2 +1,2 @@ -UPD 2021-04-16_07:16:18 45056 FHEM/73_GardenaSmartBridge.pm -UPD 2021-04-16_07:16:18 48342 FHEM/74_GardenaSmartDevice.pm +UPD 2021-04-22_09:07:36 46169 FHEM/73_GardenaSmartBridge.pm +UPD 2021-04-22_09:13:02 48346 FHEM/74_GardenaSmartDevice.pm From d3c636a5cec346e365e7412c7565e98a5588da77 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Thu, 22 Apr 2021 19:10:00 +0200 Subject: [PATCH 04/17] fix Use of uninitialized value in concatenation #14 --- FHEM/74_GardenaSmartDevice.pm | 5 +++-- controls_GardenaSmartDevice.txt | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/FHEM/74_GardenaSmartDevice.pm b/FHEM/74_GardenaSmartDevice.pm index 970216f..c209601 100644 --- a/FHEM/74_GardenaSmartDevice.pm +++ b/FHEM/74_GardenaSmartDevice.pm @@ -604,8 +604,9 @@ sub WriteReadings { #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 ( exists($decode_json->{settings}[$settings]{name} + && ( $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 diff --git a/controls_GardenaSmartDevice.txt b/controls_GardenaSmartDevice.txt index 47d0a64..fa3d927 100644 --- a/controls_GardenaSmartDevice.txt +++ b/controls_GardenaSmartDevice.txt @@ -1,2 +1,2 @@ -UPD 2021-04-22_09:07:36 46169 FHEM/73_GardenaSmartBridge.pm -UPD 2021-04-22_09:13:02 48346 FHEM/74_GardenaSmartDevice.pm +UPD 2021-04-22_18:29:35 46169 FHEM/73_GardenaSmartBridge.pm +UPD 2021-04-22_19:09:15 48416 FHEM/74_GardenaSmartDevice.pm From 8c6dd44c8da561194337a41cfd9c316a35839947 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Fri, 23 Apr 2021 10:57:03 +0200 Subject: [PATCH 05/17] change condition syntax --- FHEM/74_GardenaSmartDevice.pm | 2 +- controls_GardenaSmartDevice.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/FHEM/74_GardenaSmartDevice.pm b/FHEM/74_GardenaSmartDevice.pm index c209601..d8b8a32 100644 --- a/FHEM/74_GardenaSmartDevice.pm +++ b/FHEM/74_GardenaSmartDevice.pm @@ -604,7 +604,7 @@ sub WriteReadings { #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} + if ( defined($decode_json->{settings}[$settings]{name} && ( $decode_json->{settings}[$settings]{name} eq 'schedules_paused_until' || $decode_json->{settings}[$settings]{name} eq 'eco_mode' ) ) diff --git a/controls_GardenaSmartDevice.txt b/controls_GardenaSmartDevice.txt index fa3d927..90efd14 100644 --- a/controls_GardenaSmartDevice.txt +++ b/controls_GardenaSmartDevice.txt @@ -1,2 +1,2 @@ UPD 2021-04-22_18:29:35 46169 FHEM/73_GardenaSmartBridge.pm -UPD 2021-04-22_19:09:15 48416 FHEM/74_GardenaSmartDevice.pm +UPD 2021-04-23_10:56:46 48417 FHEM/74_GardenaSmartDevice.pm From dd66897bbef68d50d514079b0ce3dbb708f45850 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Sat, 24 Apr 2021 15:39:29 +0200 Subject: [PATCH 06/17] change condition for error handling --- FHEM/74_GardenaSmartDevice.pm | 2 +- controls_GardenaSmartDevice.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/FHEM/74_GardenaSmartDevice.pm b/FHEM/74_GardenaSmartDevice.pm index d8b8a32..533e4db 100644 --- a/FHEM/74_GardenaSmartDevice.pm +++ b/FHEM/74_GardenaSmartDevice.pm @@ -604,7 +604,7 @@ sub WriteReadings { #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 ( defined($decode_json->{settings}[$settings]{name} + if ( exists($decode_json->{settings}[$settings] && ( $decode_json->{settings}[$settings]{name} eq 'schedules_paused_until' || $decode_json->{settings}[$settings]{name} eq 'eco_mode' ) ) diff --git a/controls_GardenaSmartDevice.txt b/controls_GardenaSmartDevice.txt index 90efd14..0d18254 100644 --- a/controls_GardenaSmartDevice.txt +++ b/controls_GardenaSmartDevice.txt @@ -1,2 +1,2 @@ UPD 2021-04-22_18:29:35 46169 FHEM/73_GardenaSmartBridge.pm -UPD 2021-04-23_10:56:46 48417 FHEM/74_GardenaSmartDevice.pm +UPD 2021-04-24_15:39:15 48410 FHEM/74_GardenaSmartDevice.pm From 01499e86cf82fcabe5cdc46fa259e27ad8247aeb Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Mon, 26 Apr 2021 09:39:47 +0200 Subject: [PATCH 07/17] fixing --- FHEM/74_GardenaSmartDevice.pm | 2 +- controls_GardenaSmartDevice.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/FHEM/74_GardenaSmartDevice.pm b/FHEM/74_GardenaSmartDevice.pm index 533e4db..bcfa790 100644 --- a/FHEM/74_GardenaSmartDevice.pm +++ b/FHEM/74_GardenaSmartDevice.pm @@ -604,7 +604,7 @@ sub WriteReadings { #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] + if ( defined($settings) && ( $decode_json->{settings}[$settings]{name} eq 'schedules_paused_until' || $decode_json->{settings}[$settings]{name} eq 'eco_mode' ) ) diff --git a/controls_GardenaSmartDevice.txt b/controls_GardenaSmartDevice.txt index 0d18254..4484ca0 100644 --- a/controls_GardenaSmartDevice.txt +++ b/controls_GardenaSmartDevice.txt @@ -1,2 +1,2 @@ -UPD 2021-04-22_18:29:35 46169 FHEM/73_GardenaSmartBridge.pm -UPD 2021-04-24_15:39:15 48410 FHEM/74_GardenaSmartDevice.pm +UPD 2021-04-26_09:37:22 46169 FHEM/73_GardenaSmartBridge.pm +UPD 2021-04-26_09:39:11 48386 FHEM/74_GardenaSmartDevice.pm From 48dc3af91518a04bc96c6848da13906b60709699 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Mon, 26 Apr 2021 14:39:55 +0200 Subject: [PATCH 08/17] test --- FHEM/74_GardenaSmartDevice.pm | 2 ++ controls_GardenaSmartDevice.txt | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/FHEM/74_GardenaSmartDevice.pm b/FHEM/74_GardenaSmartDevice.pm index bcfa790..812c37a 100644 --- a/FHEM/74_GardenaSmartDevice.pm +++ b/FHEM/74_GardenaSmartDevice.pm @@ -605,6 +605,7 @@ sub WriteReadings { #Log3 $name, 1, " - IST ARRAY" if ( ref( $decode_json->{settings}[$settings]{value} ) eq "ARRAY"); if ( defined($settings) + && exists($decode_json->{settings}) && ( $decode_json->{settings}[$settings]{name} eq 'schedules_paused_until' || $decode_json->{settings}[$settings]{name} eq 'eco_mode' ) ) @@ -616,6 +617,7 @@ sub WriteReadings { $decode_json->{settings}[$settings]{id}; } } + if ( ref( $decode_json->{settings}[$settings]{value} ) eq "ARRAY" && $decode_json->{settings}[$settings]{name} eq 'starting_points' ) { diff --git a/controls_GardenaSmartDevice.txt b/controls_GardenaSmartDevice.txt index 4484ca0..53e1128 100644 --- a/controls_GardenaSmartDevice.txt +++ b/controls_GardenaSmartDevice.txt @@ -1,2 +1,2 @@ UPD 2021-04-26_09:37:22 46169 FHEM/73_GardenaSmartBridge.pm -UPD 2021-04-26_09:39:11 48386 FHEM/74_GardenaSmartDevice.pm +UPD 2021-04-26_14:39:40 48444 FHEM/74_GardenaSmartDevice.pm From 4f48c4ff67299aff3e462e8789f280b8a2580553 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Mon, 26 Apr 2021 20:09:18 +0200 Subject: [PATCH 09/17] fix it now --- FHEM/74_GardenaSmartDevice.pm | 9 ++++----- controls_GardenaSmartDevice.txt | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/FHEM/74_GardenaSmartDevice.pm b/FHEM/74_GardenaSmartDevice.pm index 812c37a..42d678b 100644 --- a/FHEM/74_GardenaSmartDevice.pm +++ b/FHEM/74_GardenaSmartDevice.pm @@ -604,11 +604,10 @@ sub WriteReadings { #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 ( defined($settings) - && exists($decode_json->{settings}) - && ( $decode_json->{settings}[$settings]{name} eq 'schedules_paused_until' - || $decode_json->{settings}[$settings]{name} eq 'eco_mode' ) - ) + if ( exists($decode_json->{settings}[$settings]{name}) + && ( $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} ) diff --git a/controls_GardenaSmartDevice.txt b/controls_GardenaSmartDevice.txt index 53e1128..1178321 100644 --- a/controls_GardenaSmartDevice.txt +++ b/controls_GardenaSmartDevice.txt @@ -1,2 +1,2 @@ -UPD 2021-04-26_09:37:22 46169 FHEM/73_GardenaSmartBridge.pm -UPD 2021-04-26_14:39:40 48444 FHEM/74_GardenaSmartDevice.pm +UPD 2021-04-22_18:29:35 46169 FHEM/73_GardenaSmartBridge.pm +UPD 2021-04-26_20:00:59 48421 FHEM/74_GardenaSmartDevice.pm From c7e66be79b52f8191bb32e1245629254e024769b Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Mon, 26 Apr 2021 21:37:53 +0200 Subject: [PATCH 10/17] change version number --- FHEM/74_GardenaSmartDevice.pm | 2 +- controls_GardenaSmartDevice.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/FHEM/74_GardenaSmartDevice.pm b/FHEM/74_GardenaSmartDevice.pm index 42d678b..c3195e4 100644 --- a/FHEM/74_GardenaSmartDevice.pm +++ b/FHEM/74_GardenaSmartDevice.pm @@ -1257,7 +1257,7 @@ sub SetPredefinedStartPoints { ], "release_status": "stable", "license": "GPL_2", - "version": "v2.2.2", + "version": "v2.2.3", "author": [ "Marko Oldenburg " ], diff --git a/controls_GardenaSmartDevice.txt b/controls_GardenaSmartDevice.txt index 1178321..25cc020 100644 --- a/controls_GardenaSmartDevice.txt +++ b/controls_GardenaSmartDevice.txt @@ -1,2 +1,2 @@ UPD 2021-04-22_18:29:35 46169 FHEM/73_GardenaSmartBridge.pm -UPD 2021-04-26_20:00:59 48421 FHEM/74_GardenaSmartDevice.pm +UPD 2021-04-26_21:37:06 48421 FHEM/74_GardenaSmartDevice.pm From e7814b889432eb2b30a8ae83bbaafce84b21f9f2 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 4 May 2021 18:18:14 +0200 Subject: [PATCH 11/17] change state to 'offline' if device is offline. Sensor changed values to -1 --- FHEM/74_GardenaSmartDevice.pm | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/FHEM/74_GardenaSmartDevice.pm b/FHEM/74_GardenaSmartDevice.pm index c3195e4..38a0676 100644 --- a/FHEM/74_GardenaSmartDevice.pm +++ b/FHEM/74_GardenaSmartDevice.pm @@ -649,7 +649,9 @@ sub WriteReadings { } while ( $settings >= 0 ); readingsBulkUpdate( $hash, 'state', - ReadingsVal( $name, 'mower-status', 'readingsValError' ) ) + ReadingsVal($name , 'device_info-connection_status', 'unknown') eq 'online' ? + ReadingsVal( $name, 'mower-status', 'readingsValError') : 'offline' + ) if ( AttrVal( $name, 'model', 'unknown' ) eq 'mower' ); readingsBulkUpdate( $hash, 'state', @@ -661,16 +663,24 @@ sub WriteReadings { ) ) if ( AttrVal( $name, 'model', 'unknown' ) eq 'watering_computer' ); - readingsBulkUpdate( - $hash, 'state', - 'T: ' + + if ( AttrVal( $name, 'model', 'unknown' ) eq 'sensor' ) { + my $online_state = ReadingsVal($name , 'device_info-connection_status', 'unknown'); + my $state_string = 'T: ' . ReadingsVal( $name, 'ambient_temperature-temperature', 'readingsValError' ) . '°C, H: ' . ReadingsVal( $name, 'humidity-humidity', 'readingsValError' ) . '%, L: ' - . ReadingsVal( $name, 'light-light', 'readingsValError' ) . 'lux' - ) if ( AttrVal( $name, 'model', 'unknown' ) eq 'sensor' ); + . ReadingsVal( $name, 'light-light', 'readingsValError' ) . 'lux'; + + if ( $online_state eq 'offline') { + readingsBulkUpdate( $hash, 'ambient_temperature-temperature', '-1' ); + readingsBulkUpdate( $hash, 'humidity-humidity', '-1' ); + readingsBulkUpdate( $hash, 'light-light', '-1' ); + } + readingsBulkUpdate($hash, 'state', ReadingsVal($name , 'device_info-connection_status', 'unknown') eq 'online' ? $state_string : 'offline' ) + } readingsBulkUpdate( $hash, 'state', From fa698b56946e9699d4706284be6625d56fcd4f14 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sun, 9 May 2021 16:42:36 +0200 Subject: [PATCH 12/17] add Sensor2 --- FHEM/74_GardenaSmartDevice.pm | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/FHEM/74_GardenaSmartDevice.pm b/FHEM/74_GardenaSmartDevice.pm index 38a0676..18a16fc 100644 --- a/FHEM/74_GardenaSmartDevice.pm +++ b/FHEM/74_GardenaSmartDevice.pm @@ -419,7 +419,12 @@ sub Set { if ( AttrVal( $name, 'model', 'unknown' ) eq 'ic24' ); $list .= 'refresh:temperature,light,humidity' - if ( AttrVal( $name, 'model', 'unknown' ) eq 'sensor' ); + if ( AttrVal( $name, 'model', 'unknown' ) eq 'sensor' + && ReadingsVal($name, 'device_info-category', 'unknown') eq 'sensor'); + + $list .= 'refresh:humidity' + if ( AttrVal( $name, 'model', 'unknown' ) eq 'sensor' + && ReadingsVal($name, 'device_info-category', 'unknown') eq 'sensor2' ); $list .= 'on:noArg off:noArg on-for-timer:slider,0,1,60' if ( AttrVal( $name, 'model', 'unknown' ) eq 'power' ); @@ -666,18 +671,14 @@ sub WriteReadings { if ( AttrVal( $name, 'model', 'unknown' ) eq 'sensor' ) { my $online_state = ReadingsVal($name , 'device_info-connection_status', 'unknown'); - my $state_string = 'T: ' - . ReadingsVal( $name, 'ambient_temperature-temperature', - 'readingsValError' ) - . '°C, H: ' - . ReadingsVal( $name, 'humidity-humidity', 'readingsValError' ) - . '%, L: ' - . ReadingsVal( $name, 'light-light', 'readingsValError' ) . 'lux'; + my $state_string = 'T: ' . ReadingsVal( $name, 'ambient_temperature-temperature', 'readingsValError' ). '°C,' if (ReadingsVal($name, 'device_info-category', 'unknown') eq 'sensor'); + $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, 'ambient_temperature-temperature', '-1' ); readingsBulkUpdate( $hash, 'humidity-humidity', '-1' ); - readingsBulkUpdate( $hash, 'light-light', '-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', ReadingsVal($name , 'device_info-connection_status', 'unknown') eq 'online' ? $state_string : 'offline' ) } From 7a6ba453eda7e9756cc1afac50bb82b4a79a51cc Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 10 May 2021 19:15:34 +0200 Subject: [PATCH 13/17] add Sensor2 --- FHEM/74_GardenaSmartDevice.pm | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/FHEM/74_GardenaSmartDevice.pm b/FHEM/74_GardenaSmartDevice.pm index 18a16fc..74fdd51 100644 --- a/FHEM/74_GardenaSmartDevice.pm +++ b/FHEM/74_GardenaSmartDevice.pm @@ -388,9 +388,13 @@ sub Set { my $sensname = $aArg->[0]; if ( lc $sensname eq 'temperature' ) { - $payload = '"name":"measure_ambient_temperature"'; - $abilities = 'ambient_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' ) { $payload = '"name":"measure_light"'; @@ -401,6 +405,7 @@ sub Set { $payload = '"name":"measure_soil_humidity"'; $abilities = 'humidity'; } + } else { @@ -418,13 +423,12 @@ sub Set { 'manualDurationValve1:slider,1,1,59 manualDurationValve2:slider,1,1,59 manualDurationValve3:slider,1,1,59 manualDurationValve4:slider,1,1,59 manualDurationValve5:slider,1,1,59 manualDurationValve6:slider,1,1,59 cancelOverrideValve1:noArg cancelOverrideValve2:noArg cancelOverrideValve3:noArg cancelOverrideValve4:noArg cancelOverrideValve5:noArg cancelOverrideValve6:noArg' if ( AttrVal( $name, 'model', 'unknown' ) eq 'ic24' ); - $list .= 'refresh:temperature,light,humidity' + $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'); - - $list .= 'refresh:humidity' - if ( AttrVal( $name, 'model', 'unknown' ) eq 'sensor' - && ReadingsVal($name, 'device_info-category', 'unknown') eq 'sensor2' ); + && ReadingsVal($name, 'device_info-category', 'unknown') eq 'sensor' ); $list .= 'on:noArg off:noArg on-for-timer:slider,0,1,60' if ( AttrVal( $name, 'model', 'unknown' ) eq 'power' ); From ba4fbc44a7540af4f1d011ef5b78a8de5dbc3770 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 11 May 2021 20:11:22 +0200 Subject: [PATCH 14/17] fix state for sensor 2, cleanup code vor offline state, removed -1 values if offline --- FHEM/74_GardenaSmartDevice.pm | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/FHEM/74_GardenaSmartDevice.pm b/FHEM/74_GardenaSmartDevice.pm index 74fdd51..9debeb2 100644 --- a/FHEM/74_GardenaSmartDevice.pm +++ b/FHEM/74_GardenaSmartDevice.pm @@ -426,7 +426,7 @@ sub Set { $list .= 'refresh:temperature,humidity' if ( AttrVal( $name, 'model', 'unknown' ) eq 'sensor' ); # add light for old sensors - $list .= 'light' + $list .= ',light' if ( AttrVal( $name, 'model', 'unknown' ) eq 'sensor' && ReadingsVal($name, 'device_info-category', 'unknown') eq 'sensor' ); @@ -545,7 +545,7 @@ sub WriteReadings { . $propertie->{name} ne 'light-light' && ref( $propertie->{value} ) ne "HASH" ); - readingsBulkUpdate( + readingsBulkUpdateIfChanged( $hash, $decode_json->{abilities}[$abilities]{name} . '-' . $propertie->{name}, @@ -657,8 +657,11 @@ sub WriteReadings { $settings--; } while ( $settings >= 0 ); + + my $online_state = ReadingsVal($name , 'device_info-connection_status', 'unknown'); + readingsBulkUpdate( $hash, 'state', - ReadingsVal($name , 'device_info-connection_status', 'unknown') eq 'online' ? + $online_state eq 'online' ? ReadingsVal( $name, 'mower-status', 'readingsValError') : 'offline' ) if ( AttrVal( $name, 'model', 'unknown' ) eq 'mower' ); @@ -674,17 +677,17 @@ sub WriteReadings { if ( AttrVal( $name, 'model', 'unknown' ) eq 'sensor' ) { - my $online_state = ReadingsVal($name , 'device_info-connection_status', 'unknown'); - my $state_string = 'T: ' . ReadingsVal( $name, 'ambient_temperature-temperature', 'readingsValError' ). '°C,' if (ReadingsVal($name, 'device_info-category', 'unknown') eq 'sensor'); + my $state_string = ''; + $state_string = 'T: ' . ReadingsVal( $name, 'ambient_temperature-temperature', 'readingsValError' ). '°C,' if (ReadingsVal($name, 'device_info-category', 'unknown') eq 'sensor'); $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', ReadingsVal($name , 'device_info-connection_status', 'unknown') eq 'online' ? $state_string : 'offline' ) + # 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( From cbbd3e929fd7517b1e3484381d70ca57466bf9a5 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 11 May 2021 20:21:45 +0200 Subject: [PATCH 15/17] add Soil-Temperatur to state for sensor2 --- FHEM/74_GardenaSmartDevice.pm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/FHEM/74_GardenaSmartDevice.pm b/FHEM/74_GardenaSmartDevice.pm index 9debeb2..de42c1e 100644 --- a/FHEM/74_GardenaSmartDevice.pm +++ b/FHEM/74_GardenaSmartDevice.pm @@ -677,8 +677,7 @@ sub WriteReadings { if ( AttrVal( $name, 'model', 'unknown' ) eq 'sensor' ) { - my $state_string = ''; - $state_string = 'T: ' . ReadingsVal( $name, 'ambient_temperature-temperature', 'readingsValError' ). '°C,' if (ReadingsVal($name, 'device_info-category', 'unknown') eq 'sensor'); + my $state_string = 'T: ' . ( ReadingsVal($name, 'device_info-category', 'unknown') eq 'sensor') ? ReadingsVal( $name, 'ambient_temperature-temperature', 'readingsValError' ) : 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'); From 6b544bb0b5b8d916c8d1687b457d060291d8c10b Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 11 May 2021 20:29:15 +0200 Subject: [PATCH 16/17] fix missing "T:" in State --- FHEM/74_GardenaSmartDevice.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FHEM/74_GardenaSmartDevice.pm b/FHEM/74_GardenaSmartDevice.pm index de42c1e..3356467 100644 --- a/FHEM/74_GardenaSmartDevice.pm +++ b/FHEM/74_GardenaSmartDevice.pm @@ -677,7 +677,7 @@ sub WriteReadings { if ( AttrVal( $name, 'model', 'unknown' ) eq 'sensor' ) { - my $state_string = 'T: ' . ( ReadingsVal($name, 'device_info-category', 'unknown') eq 'sensor') ? ReadingsVal( $name, 'ambient_temperature-temperature', 'readingsValError' ) : ReadingsVal( $name, 'soil_temperature-temperature', 'readingsValError' ) . '°C,' ; + 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'); @@ -686,7 +686,7 @@ sub WriteReadings { # 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($hash, 'state', $online_state eq 'offline' ? $state_string : 'offline' ) } readingsBulkUpdate( From cb2a925556ea8609bb7a4b50e18da7b5b11cda31 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 11 May 2021 20:29:49 +0200 Subject: [PATCH 17/17] D'OH --- FHEM/74_GardenaSmartDevice.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FHEM/74_GardenaSmartDevice.pm b/FHEM/74_GardenaSmartDevice.pm index 3356467..58f4ea9 100644 --- a/FHEM/74_GardenaSmartDevice.pm +++ b/FHEM/74_GardenaSmartDevice.pm @@ -686,7 +686,7 @@ sub WriteReadings { # 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 'offline' ? $state_string : 'offline' ) + readingsBulkUpdate($hash, 'state', $online_state eq 'online' ? $state_string : 'offline' ) } readingsBulkUpdate(