73_GardenaSmartBridge: bugfixes, expand Bridge readings
git-svn-id: https://svn.fhem.de/fhem/trunk@19440 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
@@ -59,7 +59,7 @@ use strict;
|
||||
use warnings;
|
||||
use FHEM::Meta;
|
||||
|
||||
my $version = "1.6.2";
|
||||
my $version = "1.6.3";
|
||||
|
||||
|
||||
sub GardenaSmartBridge_Initialize($) {
|
||||
@@ -386,10 +386,10 @@ sub Write($@) {
|
||||
}
|
||||
);
|
||||
|
||||
Log3 $name, 4,
|
||||
"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, 4,
|
||||
# "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");
|
||||
}
|
||||
|
||||
sub ErrorHandling($$$) {
|
||||
@@ -404,6 +404,12 @@ sub ErrorHandling($$$) {
|
||||
unless ( not defined( $param->{'device_id'} ) );
|
||||
|
||||
my $dname = $dhash->{NAME};
|
||||
|
||||
my $decode_json = eval { decode_json($data) };
|
||||
if ($@) {
|
||||
Log3 $name, 3,
|
||||
"GardenaSmartBridge ($name) - JSON error while request";
|
||||
}
|
||||
|
||||
if ( defined($err) ) {
|
||||
if ( $err ne "" ) {
|
||||
@@ -497,13 +503,10 @@ sub ErrorHandling($$$) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( defined($data)
|
||||
and $data
|
||||
and
|
||||
(
|
||||
( $data =~ /Error/ )
|
||||
or defined( eval { decode_json($data) }->{errors} )
|
||||
)
|
||||
if ( $data =~ /Error/
|
||||
or ( defined( $decode_json )
|
||||
and ref($decode_json) eq 'HASH'
|
||||
and defined($decode_json->{errors}) )
|
||||
)
|
||||
{
|
||||
readingsBeginUpdate($dhash);
|
||||
@@ -513,28 +516,28 @@ sub ErrorHandling($$$) {
|
||||
readingsBulkUpdate( $dhash, "lastRequestState", "request_error", 1 );
|
||||
|
||||
if ( $param->{code} == 400 ) {
|
||||
if ( eval { decode_json($data) } ) {
|
||||
if ( ref( eval { decode_json($data) }->{errors} ) eq "ARRAY"
|
||||
and defined( eval { decode_json($data) }->{errors} ) )
|
||||
if ( $decode_json ) {
|
||||
if ( ref( $decode_json->{errors} ) eq "ARRAY"
|
||||
and defined( $decode_json->{errors} ) )
|
||||
{
|
||||
readingsBulkUpdate(
|
||||
$dhash,
|
||||
"state",
|
||||
eval { decode_json($data) }->{errors}[0]{error} . ' '
|
||||
. eval { decode_json($data) }->{errors}[0]{attribute},
|
||||
$decode_json->{errors}[0]{error} . ' '
|
||||
. $decode_json->{errors}[0]{attribute},
|
||||
1
|
||||
);
|
||||
readingsBulkUpdate(
|
||||
$dhash,
|
||||
"lastRequestState",
|
||||
eval { decode_json($data) }->{errors}[0]{error} . ' '
|
||||
. eval { decode_json($data) }->{errors}[0]{attribute},
|
||||
$decode_json->{errors}[0]{error} . ' '
|
||||
. $decode_json->{errors}[0]{attribute},
|
||||
1
|
||||
);
|
||||
Log3 $dname, 5,
|
||||
"GardenaSmartBridge ($dname) - RequestERROR: "
|
||||
. eval { decode_json($data) }->{errors}[0]{error} . " "
|
||||
. eval { decode_json($data) }->{errors}[0]{attribute};
|
||||
. $decode_json->{errors}[0]{error} . " "
|
||||
. $decode_json->{errors}[0]{attribute};
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -593,7 +596,8 @@ sub ErrorHandling($$$) {
|
||||
|
||||
readingsSingleUpdate( $hash, 'state', 'connected to cloud', 1 )
|
||||
if ( defined( $hash->{helper}{locations_id} ) );
|
||||
ResponseProcessing( $hash, $data );
|
||||
ResponseProcessing( $hash, $data )
|
||||
if ( ref($decode_json) eq 'HASH' );
|
||||
}
|
||||
|
||||
sub ResponseProcessing($$) {
|
||||
@@ -682,6 +686,9 @@ sub ResponseProcessing($$) {
|
||||
|
||||
Dispatch( $hash, $json, undef )
|
||||
unless ( $decode_json->{category} eq 'gateway' );
|
||||
WriteReadings($hash,$decode_json)
|
||||
if ( defined($decode_json->{category})
|
||||
and $decode_json->{category} eq 'gateway' );
|
||||
}
|
||||
|
||||
( $json, $tail ) = ParseJSON( $hash, $tail );
|
||||
@@ -711,25 +718,64 @@ sub WriteReadings($$) {
|
||||
and defined( $decode_json->{name} )
|
||||
and $decode_json->{name} )
|
||||
{
|
||||
|
||||
readingsBeginUpdate($hash);
|
||||
readingsBulkUpdateIfChanged( $hash, 'name', $decode_json->{name} );
|
||||
readingsBulkUpdateIfChanged( $hash, 'authorized_user_ids',
|
||||
scalar( @{ $decode_json->{authorized_user_ids} } ) );
|
||||
readingsBulkUpdateIfChanged( $hash, 'devices',
|
||||
scalar( @{ $decode_json->{devices} } ) );
|
||||
if ( $decode_json->{id} eq $hash->{helper}{locations_id} ) {
|
||||
|
||||
readingsBulkUpdateIfChanged( $hash, 'name', $decode_json->{name} );
|
||||
readingsBulkUpdateIfChanged( $hash, 'authorized_user_ids',
|
||||
scalar( @{ $decode_json->{authorized_user_ids} } ) );
|
||||
readingsBulkUpdateIfChanged( $hash, 'devices',
|
||||
scalar( @{ $decode_json->{devices} } ) );
|
||||
|
||||
while ( ( my ( $t, $v ) ) = each %{ $decode_json->{geo_position} } ) {
|
||||
$v = encode_utf8($v);
|
||||
readingsBulkUpdateIfChanged( $hash, $t, $v );
|
||||
while ( ( my ( $t, $v ) ) = each %{ $decode_json->{geo_position} } ) {
|
||||
$v = encode_utf8($v);
|
||||
readingsBulkUpdateIfChanged( $hash, $t, $v );
|
||||
}
|
||||
|
||||
readingsBulkUpdateIfChanged( $hash, 'zones',
|
||||
scalar( @{ $decode_json->{zones} } ) );
|
||||
}
|
||||
elsif ( $decode_json->{id} ne $hash->{helper}{locations_id} ) {
|
||||
my $properties = scalar( @{ $decode_json->{abilities}[0]{properties} } );
|
||||
|
||||
do {
|
||||
while ( ( my ( $t, $v ) ) = each %{ $decode_json->{abilities}[0]{properties}[$properties] } ) {
|
||||
next
|
||||
if ( ref($v) eq 'ARRAY');
|
||||
#$v = encode_utf8($v);
|
||||
readingsBulkUpdateIfChanged( $hash, $decode_json->{abilities}[0]{properties}[$properties]{name} . '-' . $t, $v )
|
||||
unless ( $decode_json->{abilities}[0]{properties}[$properties]{name} eq 'ethernet_status'
|
||||
or $decode_json->{abilities}[0]{properties}[$properties]{name} eq 'wifi_status' );
|
||||
|
||||
if ( ( $decode_json->{abilities}[0]{properties}[$properties]{name} eq 'ethernet_status'
|
||||
or $decode_json->{abilities}[0]{properties}[$properties]{name} eq 'wifi_status')
|
||||
and ref($v) eq 'HASH'
|
||||
)
|
||||
{
|
||||
if ( $decode_json->{abilities}[0]{properties}[$properties]{name} eq 'ethernet_status' ) {
|
||||
readingsBulkUpdateIfChanged( $hash, 'ethernet_status-mac', $v->{mac} );
|
||||
readingsBulkUpdateIfChanged( $hash, 'ethernet_status-ip', $v->{ip} )
|
||||
if ( ref($v->{ip}) ne 'HASH' );
|
||||
readingsBulkUpdateIfChanged( $hash, 'ethernet_status-isconnected', $v->{isconnected} );
|
||||
}
|
||||
elsif ( $decode_json->{abilities}[0]{properties}[$properties]{name} eq 'wifi_status') {
|
||||
readingsBulkUpdateIfChanged( $hash, 'wifi_status-ssid', $v->{ssid} );
|
||||
readingsBulkUpdateIfChanged( $hash, 'wifi_status-mac', $v->{mac} );
|
||||
readingsBulkUpdateIfChanged( $hash, 'wifi_status-ip', $v->{ip} )
|
||||
if ( ref($v->{ip}) ne 'HASH' );
|
||||
readingsBulkUpdateIfChanged( $hash, 'wifi_status-isconnected', $v->{isconnected} );
|
||||
readingsBulkUpdateIfChanged( $hash, 'wifi_status-signal', $v->{signal} );
|
||||
}
|
||||
}
|
||||
}
|
||||
$properties--;
|
||||
|
||||
} while ( $properties >= 0 );
|
||||
}
|
||||
|
||||
readingsBulkUpdateIfChanged( $hash, 'zones',
|
||||
scalar( @{ $decode_json->{zones} } ) );
|
||||
readingsEndUpdate( $hash, 1 );
|
||||
}
|
||||
|
||||
Log3 $name, 3, "GardenaSmartBridge ($name) - readings would be written";
|
||||
Log3 $name, 4, "GardenaSmartBridge ($name) - readings would be written";
|
||||
}
|
||||
|
||||
####################################
|
||||
@@ -987,6 +1033,21 @@ sub createHttpValueStrings($@) {
|
||||
. '/properties/watering_timer_'
|
||||
. $valve_id;
|
||||
|
||||
}
|
||||
elsif ( defined($abilities)
|
||||
and defined($payload)
|
||||
and $abilities eq 'manual_watering' )
|
||||
{
|
||||
my $valve_id;
|
||||
$method = 'PUT';
|
||||
|
||||
$uri .=
|
||||
'/devices/'
|
||||
. $deviceId
|
||||
. '/abilities/'
|
||||
. $abilities
|
||||
. '/properties/manual_watering_timer';
|
||||
|
||||
}
|
||||
elsif ( defined($abilities)
|
||||
and defined($payload)
|
||||
|
||||
@@ -59,7 +59,7 @@ use strict;
|
||||
use warnings;
|
||||
use FHEM::Meta;
|
||||
|
||||
my $version = "1.6.1";
|
||||
my $version = "1.6.2";
|
||||
|
||||
sub GardenaSmartDevice_Initialize($) {
|
||||
|
||||
@@ -75,7 +75,7 @@ sub GardenaSmartDevice_Initialize($) {
|
||||
$hash->{AttrFn} = "FHEM::GardenaSmartDevice::Attr";
|
||||
$hash->{AttrList} =
|
||||
"readingValueLanguage:de,en "
|
||||
. "model:watering_computer,sensor,mower,ic24,power "
|
||||
. "model:watering_computer,sensor,mower,ic24,power,electronic_pressure_pump "
|
||||
. "IODev "
|
||||
. $readingFnAttributes;
|
||||
|
||||
@@ -243,8 +243,16 @@ sub Set($@) {
|
||||
SetPredefinedStartPoints( $hash, @args );
|
||||
return $err if ( defined($err) );
|
||||
|
||||
### watering_computer
|
||||
}
|
||||
### electronic_pressure_pump
|
||||
elsif ( lc $cmd eq 'pumptimer' ) {
|
||||
|
||||
my $duration = join( " ", @args );
|
||||
|
||||
$payload = '"name":"pump_manual_watering_timer","parameters":{"duration":'
|
||||
. $duration . '}';
|
||||
}
|
||||
### watering_computer
|
||||
elsif ( lc $cmd eq 'manualoverride' ) {
|
||||
|
||||
my $duration = join( " ", @args );
|
||||
@@ -281,9 +289,8 @@ sub Set($@) {
|
||||
. $duration
|
||||
. ',"valve_id":'
|
||||
. $valve_id . '}}';
|
||||
|
||||
### Sensors
|
||||
}
|
||||
### Sensors
|
||||
elsif ( lc $cmd eq 'refresh' ) {
|
||||
|
||||
my $sensname = join( " ", @args );
|
||||
@@ -309,13 +316,20 @@ sub Set($@) {
|
||||
$list .=
|
||||
'parkUntilFurtherNotice:noArg parkUntilNextTimer:noArg startResumeSchedule:noArg startOverrideTimer:slider,0,60,1440 startpoint'
|
||||
if ( AttrVal( $name, 'model', 'unknown' ) eq 'mower' );
|
||||
|
||||
$list .= 'manualOverride:slider,0,1,59 cancelOverride:noArg'
|
||||
if ( AttrVal( $name, 'model', 'unknown' ) eq 'watering_computer' );
|
||||
|
||||
$list .= 'pumpTimer:slider,0,1,59'
|
||||
if ( AttrVal( $name, 'model', 'unknown' ) eq 'electronic_pressure_pump' );
|
||||
|
||||
$list .=
|
||||
'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'
|
||||
if ( AttrVal( $name, 'model', 'unknown' ) eq 'ic24' );
|
||||
|
||||
$list .= 'refresh:temperature,light,humidity'
|
||||
if ( AttrVal( $name, 'model', 'unknown' ) eq 'sensor' );
|
||||
|
||||
$list .= 'on:noArg off:noArg on-for-timer:slider,0,1,60'
|
||||
if ( AttrVal( $name, 'model', 'unknown' ) eq 'power' );
|
||||
|
||||
@@ -331,6 +345,8 @@ sub Set($@) {
|
||||
if ( AttrVal( $name, 'model', 'unknown' ) eq 'ic24' );
|
||||
$abilities = 'power'
|
||||
if ( AttrVal( $name, 'model', 'unknown' ) eq 'power' );
|
||||
$abilities = 'manual_watering'
|
||||
if ( AttrVal( $name, 'model', 'unknown' ) eq 'electronic_pressure_pump' );
|
||||
|
||||
$hash->{helper}{deviceAction} = $payload;
|
||||
readingsSingleUpdate( $hash, "state", "send command to gardena cloud", 1 );
|
||||
@@ -351,7 +367,7 @@ sub Parse($$) {
|
||||
my $decode_json = eval { decode_json($json) };
|
||||
if ($@) {
|
||||
Log3 $name, 3,
|
||||
"GardenaSmartBridge ($name) - JSON error while request: $@";
|
||||
"GardenaSmartDevice ($name) - JSON error while request: $@";
|
||||
}
|
||||
|
||||
Log3 $name, 4, "GardenaSmartDevice ($name) - ParseFn was called";
|
||||
|
||||
Reference in New Issue
Block a user