Übernahme in den Testing Zweig #22

Merged
marko merged 24 commits from devel into testing 2021-05-12 07:27:15 +00:00
3 changed files with 91 additions and 51 deletions

View File

@ -2,7 +2,7 @@
# #
# Developed with Kate # 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 # All rights reserved
# #
# Special thanks goes to comitters: # Special thanks goes to comitters:
@ -156,8 +156,11 @@ BEGIN {
readingsBeginUpdate readingsBeginUpdate
readingsEndUpdate readingsEndUpdate
Log3 Log3
devspec2array
asyncOutput
CommandAttr CommandAttr
AttrVal AttrVal
InternalVal
ReadingsVal ReadingsVal
CommandDefMod CommandDefMod
modules modules
@ -404,18 +407,17 @@ sub Get {
// return qq{"get $name" needs at least one argument}; // return qq{"get $name" needs at least one argument};
if ( lc $cmd eq 'debug_devices_list' ) { if ( lc $cmd eq 'debug_devices_list' ) {
$hash->{helper}{debug_device_list} = 'get'; my $device = shift @$aArg;
#Log3 $name, 2, Dumper($hash->{helper}); $hash->{helper}{debug_device} = $device;
#Write($hash, undef, undef, undef, undef); Write($hash, undef, undef, undef, undef);
return undef;
return 'coming soon';
} else { } else {
my $list = ""; my $list = "";
$list .= " debug_devices_list:noArg" $list .= " debug_devices_list:"
if ( AttrVal( $name, "debugJSON", "none") ne "none" ); .join( ',', @{ $hash->{helper}{deviceList} })
if ( AttrVal( $name, "debugJSON", "none") ne "none"
return "Unknown argument $cmd,choose one of $list"; && exists($hash->{helper}{deviceList}) );
return "Unknown argument $cmd,choose one of $list";
} }
} }
@ -487,6 +489,7 @@ sub Write {
method => $method, method => $method,
header => $header, header => $header,
doTrigger => 1, doTrigger => 1,
cl => $hash->{CL},
callback => \&ErrorHandling callback => \&ErrorHandling
} }
); );
@ -514,7 +517,7 @@ sub ErrorHandling {
if ( defined( $param->{'device_id'} ) ); if ( defined( $param->{'device_id'} ) );
my $dname = $dhash->{NAME}; my $dname = $dhash->{NAME};
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) };
@ -709,7 +712,31 @@ sub ErrorHandling {
return; 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 ) readingsSingleUpdate( $hash, 'state', 'Connected', 1 )
if ( defined( $hash->{helper}{locations_id} ) ); if ( defined( $hash->{helper}{locations_id} ) );
ResponseProcessing( $hash, $data ) ResponseProcessing( $hash, $data )
@ -773,19 +800,6 @@ sub ResponseProcessing {
return; 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} ) elsif (defined( $decode_json->{devices} )
&& ref( $decode_json->{devices} ) eq 'ARRAY' && ref( $decode_json->{devices} ) eq 'ARRAY'
&& scalar( @{ $decode_json->{devices} } ) > 0 ) && scalar( @{ $decode_json->{devices} } ) > 0 )
@ -960,6 +974,12 @@ sub getDevices {
if ( not IsDisabled($name) ) { 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 ); 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";
@ -1195,6 +1215,7 @@ sub createHttpValueStrings {
&& defined( $hash->{helper}{locations_id} ) ); && 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} ) ); $uri = '/auth/token' if ( !defined( $hash->{helper}{session_id} ) );
if ( defined( $hash->{helper}{locations_id} ) ) { if ( defined( $hash->{helper}{locations_id} ) ) {

View File

@ -2,7 +2,7 @@
# #
# Developed with Kate # 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 # All rights reserved
# #
# Special thanks goes to comitters: # Special thanks goes to comitters:
@ -388,9 +388,13 @@ sub Set {
my $sensname = $aArg->[0]; my $sensname = $aArg->[0];
if ( lc $sensname eq 'temperature' ) { if ( lc $sensname eq 'temperature' ) {
$payload = '"name":"measure_ambient_temperature"'; if ( ReadingsVal( $name, 'device_info-category', 'sensor' ) eq 'sensor') {
$abilities = 'ambient_temperature'; $payload = '"name":"measure_ambient_temperature"';
$abilities = 'ambient_temperature';
} else {
$payload = '"name":"measure_soil_temperature"';
$abilities = 'soil_temperature';
}
} }
elsif ( lc $sensname eq 'light' ) { elsif ( lc $sensname eq 'light' ) {
$payload = '"name":"measure_light"'; $payload = '"name":"measure_light"';
@ -401,6 +405,7 @@ sub Set {
$payload = '"name":"measure_soil_humidity"'; $payload = '"name":"measure_soil_humidity"';
$abilities = 'humidity'; $abilities = 'humidity';
} }
} }
else { else {
@ -418,8 +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' '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' ); if ( AttrVal( $name, 'model', 'unknown' ) eq 'ic24' );
$list .= 'refresh:temperature,light,humidity' $list .= 'refresh:temperature,humidity'
if ( AttrVal( $name, 'model', 'unknown' ) eq 'sensor' ); 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 .= 'on:noArg off:noArg on-for-timer:slider,0,1,60' $list .= 'on:noArg off:noArg on-for-timer:slider,0,1,60'
if ( AttrVal( $name, 'model', 'unknown' ) eq 'power' ); if ( AttrVal( $name, 'model', 'unknown' ) eq 'power' );
@ -536,7 +545,7 @@ sub WriteReadings {
. $propertie->{name} ne 'light-light' . $propertie->{name} ne 'light-light'
&& ref( $propertie->{value} ) ne "HASH" ); && ref( $propertie->{value} ) ne "HASH" );
readingsBulkUpdate( readingsBulkUpdateIfChanged(
$hash, $hash,
$decode_json->{abilities}[$abilities]{name} . '-' $decode_json->{abilities}[$abilities]{name} . '-'
. $propertie->{name}, . $propertie->{name},
@ -604,9 +613,10 @@ sub WriteReadings {
#Log3 $name, 1, " - KEIN ARRAY" if ( ref( $decode_json->{settings}[$settings]{value} ) ne "ARRAY"); #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"); #Log3 $name, 1, " - IST ARRAY" if ( ref( $decode_json->{settings}[$settings]{value} ) eq "ARRAY");
if ( $decode_json->{settings}[$settings]{name} eq 'schedules_paused_until' if ( exists($decode_json->{settings}[$settings]{name})
|| $decode_json->{settings}[$settings]{name} eq 'eco_mode' && ( $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 if ( $hash->{helper}{$decode_json->{settings}[$settings]{name}.'_id'} ne
$decode_json->{settings}[$settings]{id} ) $decode_json->{settings}[$settings]{id} )
@ -615,6 +625,7 @@ sub WriteReadings {
$decode_json->{settings}[$settings]{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' )
{ {
@ -646,8 +657,13 @@ sub WriteReadings {
$settings--; $settings--;
} while ( $settings >= 0 ); } while ( $settings >= 0 );
my $online_state = ReadingsVal($name , 'device_info-connection_status', 'unknown');
readingsBulkUpdate( $hash, 'state', readingsBulkUpdate( $hash, 'state',
ReadingsVal( $name, 'mower-status', 'readingsValError' ) ) $online_state eq 'online' ?
ReadingsVal( $name, 'mower-status', 'readingsValError') : 'offline'
)
if ( AttrVal( $name, 'model', 'unknown' ) eq 'mower' ); if ( AttrVal( $name, 'model', 'unknown' ) eq 'mower' );
readingsBulkUpdate( readingsBulkUpdate(
$hash, 'state', $hash, 'state',
@ -659,16 +675,19 @@ sub WriteReadings {
) )
) if ( AttrVal( $name, 'model', 'unknown' ) eq 'watering_computer' ); ) if ( AttrVal( $name, 'model', 'unknown' ) eq 'watering_computer' );
readingsBulkUpdate(
$hash, 'state', if ( AttrVal( $name, 'model', 'unknown' ) eq 'sensor' ) {
'T: ' 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, ' ;
. ReadingsVal( $name, 'ambient_temperature-temperature', $state_string .= 'H: '. ReadingsVal( $name, 'humidity-humidity', 'readingsValError' ). '%';
'readingsValError' ) $state_string .= ', L: ' . ReadingsVal( $name, 'light-light', 'readingsValError' ) . 'lux' if (ReadingsVal($name, 'device_info-category', 'unknown') eq 'sensor');
. '°C, H: '
. ReadingsVal( $name, 'humidity-humidity', 'readingsValError' ) # if ( $online_state eq 'offline') {
. '%, L: ' # readingsBulkUpdate( $hash, 'humidity-humidity', '-1' );
. ReadingsVal( $name, 'light-light', 'readingsValError' ) . 'lux' # readingsBulkUpdate( $hash, 'ambient_temperature-temperature', '-1' ) if (ReadingsVal($name, 'device_info-category', 'unknown') eq 'sensor');
) if ( AttrVal( $name, 'model', '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( readingsBulkUpdate(
$hash, 'state', $hash, 'state',
@ -687,7 +706,7 @@ sub WriteReadings {
readingsEndUpdate( $hash, 1 ); readingsEndUpdate( $hash, 1 );
Log3 $name, 4, "GardenaSmartDevice ($name) - readings was written}"; Log3 $name, 4, "GardenaSmartDevice ($name) - readings was written";
return; return;
} }
@ -1255,7 +1274,7 @@ sub SetPredefinedStartPoints {
], ],
"release_status": "stable", "release_status": "stable",
"license": "GPL_2", "license": "GPL_2",
"version": "v2.2.2", "version": "v2.2.3",
"author": [ "author": [
"Marko Oldenburg <leongaultier@gmail.com>" "Marko Oldenburg <leongaultier@gmail.com>"
], ],

View File

@ -1,2 +1,2 @@
UPD 2021-04-16_07:16:18 45056 FHEM/73_GardenaSmartBridge.pm UPD 2021-04-22_18:29:35 46169 FHEM/73_GardenaSmartBridge.pm
UPD 2021-04-16_07:16:18 48342 FHEM/74_GardenaSmartDevice.pm UPD 2021-04-26_21:37:06 48421 FHEM/74_GardenaSmartDevice.pm