patch-async_run_parseJson #48
@@ -366,6 +366,7 @@ sub Notify {
 | 
				
			|||||||
                @{$events}
 | 
					                @{$events}
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					      && $init_done
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    getDevices($hash)
 | 
					    getDevices($hash)
 | 
				
			||||||
@@ -483,6 +484,7 @@ sub Write {
 | 
				
			|||||||
        {
 | 
					        {
 | 
				
			||||||
            url       => $hash->{URL} . $uri,
 | 
					            url       => $hash->{URL} . $uri,
 | 
				
			||||||
            timeout   => 15,
 | 
					            timeout   => 15,
 | 
				
			||||||
 | 
					            incrementalTimeout => 1,
 | 
				
			||||||
            hash      => $hash,
 | 
					            hash      => $hash,
 | 
				
			||||||
            device_id => $deviceId,
 | 
					            device_id => $deviceId,
 | 
				
			||||||
            data      => $payload,
 | 
					            data      => $payload,
 | 
				
			||||||
@@ -520,7 +522,7 @@ sub ErrorHandling {
 | 
				
			|||||||
    
 | 
					    
 | 
				
			||||||
    Log3 $name, 4, "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 ( length($data) > 0 );
 | 
				
			||||||
    if ($@) {
 | 
					    if ($@) {
 | 
				
			||||||
        Log3 $name, 3, "GardenaSmartBridge ($name) - JSON error while request";
 | 
					        Log3 $name, 3, "GardenaSmartBridge ($name) - JSON error while request";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -981,7 +983,6 @@ sub getDevices {
 | 
				
			|||||||
    my $hash = shift;
 | 
					    my $hash = shift;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    my $name = $hash->{NAME};
 | 
					    my $name = $hash->{NAME};
 | 
				
			||||||
 | 
					 | 
				
			||||||
    RemoveInternalTimer($hash);
 | 
					    RemoveInternalTimer($hash);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if ( not IsDisabled($name) ) {
 | 
					    if ( not IsDisabled($name) ) {
 | 
				
			||||||
@@ -992,12 +993,17 @@ sub getDevices {
 | 
				
			|||||||
        for my $gardenaDev (@list){
 | 
					        for my $gardenaDev (@list){
 | 
				
			||||||
          push( @{ $hash->{helper}{deviceList} }, $gardenaDev );
 | 
					          push( @{ $hash->{helper}{deviceList} }, $gardenaDev );
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        if ( AttrVal( $name, 'gardenaAccountEmail', 'none' ) ne 'none' 
 | 
				
			||||||
 | 
					          && (
 | 
				
			||||||
 | 
					            defined( ReadPassword( $hash, $name ) ) 
 | 
				
			||||||
 | 
					          )) 
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
          Write( $hash, undef, undef, undef );
 | 
					          Write( $hash, undef, undef, undef );
 | 
				
			||||||
          Log3 $name, 4,
 | 
					          Log3 $name, 4,
 | 
				
			||||||
            "GardenaSmartBridge ($name) - fetch device list and device states";
 | 
					            "GardenaSmartBridge ($name) - fetch device list and device states";
 | 
				
			||||||
 | 
					        } # fi gardenaAccountEmail
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else {
 | 
					    else {
 | 
				
			||||||
 | 
					 | 
				
			||||||
        readingsSingleUpdate( $hash, 'state', 'disabled', 1 );
 | 
					        readingsSingleUpdate( $hash, 'state', 'disabled', 1 );
 | 
				
			||||||
        Log3 $name, 3, "GardenaSmartBridge ($name) - device is disabled";
 | 
					        Log3 $name, 3, "GardenaSmartBridge ($name) - device is disabled";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -1027,16 +1033,6 @@ sub getToken {
 | 
				
			|||||||
      if ( defined( $hash->{helper}{locations_id} )
 | 
					      if ( defined( $hash->{helper}{locations_id} )
 | 
				
			||||||
        && $hash->{helper}{locations_id} );
 | 
					        && $hash->{helper}{locations_id} );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Write(
 | 
					 | 
				
			||||||
    #     $hash,
 | 
					 | 
				
			||||||
    #     '"sessions": {"email": "'
 | 
					 | 
				
			||||||
    #       . AttrVal( $name, 'gardenaAccountEmail', 'none' )
 | 
					 | 
				
			||||||
    #       . '","password": "'
 | 
					 | 
				
			||||||
    #       . ReadPassword( $hash, $name ) . '"}',
 | 
					 | 
				
			||||||
    #     undef,
 | 
					 | 
				
			||||||
    #     undef
 | 
					 | 
				
			||||||
    # );
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    Write(
 | 
					    Write(
 | 
				
			||||||
         $hash,
 | 
					         $hash,
 | 
				
			||||||
         '"data": {"type":"token", "attributes":{"username": "' 
 | 
					         '"data": {"type":"token", "attributes":{"username": "' 
 | 
				
			||||||
@@ -1047,8 +1043,9 @@ sub getToken {
 | 
				
			|||||||
         undef
 | 
					         undef
 | 
				
			||||||
     );
 | 
					     );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Log3 $name, 4, '"data": {"type":"token", "attributes":{"username": "'      . AttrVal( $name, 'gardenaAccountEmail', 'none' )      . '","password": "'
 | 
					    Log3 $name, 4, '"data": {"type":"token", "attributes":{"username": "'     
 | 
				
			||||||
          . ReadPassword( $hash, $name ) . '", "client_id":"smartgarden-jwt-client"}}';
 | 
					               .AttrVal( $name, 'gardenaAccountEmail', 'none' ) . '","password": "'
 | 
				
			||||||
 | 
					               .ReadPassword( $hash, $name ) . '", "client_id":"smartgarden-jwt-client"}}';
 | 
				
			||||||
    Log3 $name, 3,
 | 
					    Log3 $name, 3,
 | 
				
			||||||
"GardenaSmartBridge ($name) - send credentials to fetch Token and locationId";
 | 
					"GardenaSmartBridge ($name) - send credentials to fetch Token and locationId";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1214,13 +1211,14 @@ sub createHttpValueStrings {
 | 
				
			|||||||
    $payload = '{}' if ( !defined($payload) );
 | 
					    $payload = '{}' if ( !defined($payload) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if ( $payload eq '{}' ) {
 | 
					    if ( $payload eq '{}' ) {
 | 
				
			||||||
        $method = 'GET';
 | 
					        $method = 'GET' if (defined( $hash->{helper}{session_id} ) );
 | 
				
			||||||
        $payload = '';
 | 
					        $payload = '';
 | 
				
			||||||
        $uri .= '/locations?locatioId=null&user_id=' . $hash->{helper}{user_id}
 | 
					        $uri .= '/locations?locatioId=null&user_id=' . $hash->{helper}{user_id}
 | 
				
			||||||
          if ( exists( $hash->{helper}{user_id} )
 | 
					          if ( exists( $hash->{helper}{user_id} )
 | 
				
			||||||
            && !defined( $hash->{helper}{locations_id} ) );
 | 
					            && !defined( $hash->{helper}{locations_id} ) );
 | 
				
			||||||
        readingsSingleUpdate( $hash, 'state', 'fetch locationId', 1 )
 | 
					        readingsSingleUpdate( $hash, 'state', 'fetch locationId', 1 )
 | 
				
			||||||
          if ( !defined( $hash->{helper}{locations_id} ) );
 | 
					          if ( exists( $hash->{helper}{user_id} )
 | 
				
			||||||
 | 
					            && !defined( $hash->{helper}{locations_id} ) );
 | 
				
			||||||
        $uri .= '/devices'
 | 
					        $uri .= '/devices'
 | 
				
			||||||
          if (!defined($abilities)
 | 
					          if (!defined($abilities)
 | 
				
			||||||
            && defined( $hash->{helper}{locations_id} ) );
 | 
					            && defined( $hash->{helper}{locations_id} ) );
 | 
				
			||||||
@@ -1228,6 +1226,7 @@ sub createHttpValueStrings {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    $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 ( exists ($hash->{helper}{debug_device}));
 | 
				
			||||||
    $uri = '/auth/token' if ( !defined( $hash->{helper}{session_id} ) );
 | 
					    $uri = '/auth/token' if ( !defined( $hash->{helper}{session_id} ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if ( defined( $hash->{helper}{locations_id} ) ) {
 | 
					    if ( defined( $hash->{helper}{locations_id} ) ) {
 | 
				
			||||||
        if ( defined($abilities) && $abilities =~ /.*_settings/ ) {
 | 
					        if ( defined($abilities) && $abilities =~ /.*_settings/ ) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1488,7 +1487,7 @@ sub DeletePassword {
 | 
				
			|||||||
  ],
 | 
					  ],
 | 
				
			||||||
  "release_status": "stable",
 | 
					  "release_status": "stable",
 | 
				
			||||||
  "license": "GPL_2",
 | 
					  "license": "GPL_2",
 | 
				
			||||||
  "version": "v2.4.2",
 | 
					  "version": "v2.4.4",
 | 
				
			||||||
  "author": [
 | 
					  "author": [
 | 
				
			||||||
    "Marko Oldenburg <leongaultier@gmail.com>"
 | 
					    "Marko Oldenburg <leongaultier@gmail.com>"
 | 
				
			||||||
  ],
 | 
					  ],
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -407,12 +407,12 @@ sub Set {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    elsif ( lc $cmd eq 'on' || lc $cmd eq 'off' || lc $cmd eq 'on-for-timer' ) {
 | 
					    elsif ( lc $cmd eq 'on' || lc $cmd eq 'off' || lc $cmd eq 'on-for-timer' ) {
 | 
				
			||||||
        my $val = (
 | 
					        my $val = (
 | 
				
			||||||
            defined($aArg) && ref($aArg) eq 'ARRAY'
 | 
					            scalar(!@$aArg == 0) && ref($aArg) eq 'ARRAY'
 | 
				
			||||||
            ? $aArg->[0] * 60
 | 
					            ? $aArg->[0] * 60
 | 
				
			||||||
            : lc $cmd
 | 
					            : lc $cmd
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $payload = '"properties":{"value":"' . $val . '"}';
 | 
					        $payload = '"properties":{"name":"power_timer", "value":"' . $val . '"}';
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    ### Watering ic24
 | 
					    ### Watering ic24
 | 
				
			||||||
    elsif ( $cmd =~ m{\AmanualDurationValve\d\z}xms ) {
 | 
					    elsif ( $cmd =~ m{\AmanualDurationValve\d\z}xms ) {
 | 
				
			||||||
@@ -502,7 +502,7 @@ sub Set {
 | 
				
			|||||||
          if ( AttrVal( $name, 'model', 'unknown' ) eq 'sensor' 
 | 
					          if ( AttrVal( $name, 'model', 'unknown' ) eq 'sensor' 
 | 
				
			||||||
            && ReadingsVal($name, 'device_info-category', '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' );
 | 
					          if ( AttrVal( $name, 'model', 'unknown' ) eq 'power' );
 | 
				
			||||||
        # all devices has abilitie to fall a sleep
 | 
					        # all devices has abilitie to fall a sleep
 | 
				
			||||||
        $list .= ' winter_mode:awake,hibernate';
 | 
					        $list .= ' winter_mode:awake,hibernate';
 | 
				
			||||||
@@ -654,6 +654,21 @@ sub WriteReadings {
 | 
				
			|||||||
                        . $propertie->{name} eq 'light-light' )
 | 
					                        . $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(
 | 
					                readingsBulkUpdateIfChanged(
 | 
				
			||||||
                    $hash,
 | 
					                    $hash,
 | 
				
			||||||
                    $decode_json->{abilities}[$abilities]{name} . '-'
 | 
					                    $decode_json->{abilities}[$abilities]{name} . '-'
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,2 +1,2 @@
 | 
				
			|||||||
UPD 2021-06-05_18:47:30 46871 FHEM/73_GardenaSmartBridge.pm
 | 
					UPD 2021-06-28_15:56:58 47009 FHEM/73_GardenaSmartBridge.pm
 | 
				
			||||||
UPD 2021-06-05_09:32:03 55505 FHEM/74_GardenaSmartDevice.pm
 | 
					UPD 2021-07-16_20:26:01 56217 FHEM/74_GardenaSmartDevice.pm
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user