change Code PBP conform

This commit is contained in:
Marko Oldenburg 2020-04-28 11:16:22 +02:00
parent ca21aabac8
commit c27b8ff1e7
2 changed files with 115 additions and 121 deletions

View File

@ -62,6 +62,7 @@ use strict;
use warnings; use warnings;
use POSIX; use POSIX;
use FHEM::Meta; use FHEM::Meta;
use Data::Dumper;
use HttpUtils; use HttpUtils;
@ -69,7 +70,7 @@ my $missingModul = '';
eval "use Encode qw(encode encode_utf8 decode_utf8);1" eval "use Encode qw(encode encode_utf8 decode_utf8);1"
or $missingModul .= "Encode "; or $missingModul .= "Encode ";
# eval "use JSON;1" or $missingModul .= 'JSON '; # eval "use JSON;1" || $missingModul .= 'JSON ';
eval "use IO::Socket::SSL;1" or $missingModul .= 'IO::Socket::SSL '; eval "use IO::Socket::SSL;1" or $missingModul .= 'IO::Socket::SSL ';
# try to use JSON::MaybeXS wrapper # try to use JSON::MaybeXS wrapper
@ -275,7 +276,7 @@ sub Attr {
my $hash = $defs{$name}; my $hash = $defs{$name};
if ( $attrName eq 'disable' ) { if ( $attrName eq 'disable' ) {
if ( $cmd eq 'set' and $attrVal eq '1' ) { if ( $cmd eq 'set' && $attrVal eq '1' ) {
RemoveInternalTimer($hash); RemoveInternalTimer($hash);
readingsSingleUpdate( $hash, 'state', 'inactive', 1 ); readingsSingleUpdate( $hash, 'state', 'inactive', 1 );
Log3 $name, 3, "GardenaSmartBridge ($name) - disabled"; Log3 $name, 3, "GardenaSmartBridge ($name) - disabled";
@ -289,7 +290,7 @@ sub Attr {
if ( $cmd eq 'set' ) { if ( $cmd eq 'set' ) {
return return
"check disabledForIntervals Syntax HH:MM-HH:MM or 'HH:MM-HH:MM HH:MM-HH:MM ...'" "check disabledForIntervals Syntax HH:MM-HH:MM or 'HH:MM-HH:MM HH:MM-HH:MM ...'"
unless ( $attrVal =~ /^((\d{2}:\d{2})-(\d{2}:\d{2})\s?)+$/ ); if ( $attrVal !~ /^((\d{2}:\d{2})-(\d{2}:\d{2})\s?)+$/ );
Log3 $name, 3, "GardenaSmartBridge ($name) - disabledForIntervals"; Log3 $name, 3, "GardenaSmartBridge ($name) - disabledForIntervals";
} }
elsif ( $cmd eq 'del' ) { elsif ( $cmd eq 'del' ) {
@ -301,7 +302,7 @@ sub Attr {
if ( $cmd eq 'set' ) { if ( $cmd eq 'set' ) {
RemoveInternalTimer($hash); RemoveInternalTimer($hash);
return 'Interval must be greater than 0' return 'Interval must be greater than 0'
unless ( $attrVal > 0 ); if ( $attrVal == 0 );
$hash->{INTERVAL} = $attrVal; $hash->{INTERVAL} = $attrVal;
Log3 $name, 3, Log3 $name, 3,
"GardenaSmartBridge ($name) - set interval: $attrVal"; "GardenaSmartBridge ($name) - set interval: $attrVal";
@ -343,7 +344,7 @@ sub Notify {
if ( if (
( (
$devtype eq 'Global' $devtype eq 'Global'
and ( && (
grep /^INITIALIZED$/, grep /^INITIALIZED$/,
@{$events} or grep /^REREADCFG$/, @{$events} or grep /^REREADCFG$/,
@{$events} or grep /^DEFINED.$name$/, @{$events} or grep /^DEFINED.$name$/,
@ -353,11 +354,11 @@ sub Notify {
) )
) )
or ( || (
$devtype eq 'GardenaSmartBridge' $devtype eq 'GardenaSmartBridge'
and ( && (
grep /^gardenaAccountPassword.+/, grep /^gardenaAccountPassword.+/,
@{$events} or ReadingsVal( '$devname', 'token', '' ) eq 'none' @{$events} || ReadingsVal( '$devname', 'token', '' ) eq 'none'
) )
) )
); );
@ -365,19 +366,19 @@ sub Notify {
getDevices($hash) getDevices($hash)
if ( if (
$devtype eq 'Global' $devtype eq 'Global'
and ( && (
grep /^DELETEATTR.$name.disable$/, grep /^DELETEATTR.$name.disable$/,
@{$events} or grep /^ATTR.$name.disable.0$/, @{$events} or grep /^ATTR.$name.disable.0$/,
@{$events} or grep /^DELETEATTR.$name.interval$/, @{$events} or grep /^DELETEATTR.$name.interval$/,
@{$events} or grep /^ATTR.$name.interval.[0-9]+/, @{$events} or grep /^ATTR.$name.interval.[0-9]+/,
@{$events} @{$events}
) )
and $init_done && $init_done
); );
if ( if (
$devtype eq 'GardenaSmartBridge' $devtype eq 'GardenaSmartBridge'
and ( && (
grep /^state:.Connected$/, grep /^state:.Connected$/,
@{$events} or grep /^lastRequestState:.request_error$/, @{$events} or grep /^lastRequestState:.request_error$/,
@{$events} @{$events}
@ -484,7 +485,7 @@ sub ErrorHandling {
my $dhash = $hash; my $dhash = $hash;
$dhash = $modules{GardenaSmartDevice}{defptr}{ $param->{'device_id'} } $dhash = $modules{GardenaSmartDevice}{defptr}{ $param->{'device_id'} }
unless ( not defined( $param->{'device_id'} ) ); if ( defined( $param->{'device_id'} ) );
my $dname = $dhash->{NAME}; my $dname = $dhash->{NAME};
@ -510,7 +511,7 @@ sub ErrorHandling {
} }
elsif ($err =~ /Keine Route zum Zielrechner/ elsif ($err =~ /Keine Route zum Zielrechner/
or $err =~ /no route to target/ ) || $err =~ /no route to target/ )
{ {
Log3 $dname, 5, Log3 $dname, 5,
@ -535,7 +536,7 @@ sub ErrorHandling {
} }
} }
if ( $data eq "" and exists( $param->{code} ) and $param->{code} != 200 ) { if ( $data eq "" && exists( $param->{code} ) && $param->{code} != 200 ) {
readingsBeginUpdate($dhash); readingsBeginUpdate($dhash);
readingsBulkUpdate( $dhash, "state", $param->{code}, 1 ) readingsBulkUpdate( $dhash, "state", $param->{code}, 1 )
@ -544,7 +545,7 @@ sub ErrorHandling {
readingsBulkUpdateIfChanged( $dhash, "lastRequestState", readingsBulkUpdateIfChanged( $dhash, "lastRequestState",
"request_error", 1 ); "request_error", 1 );
if ( $param->{code} == 401 and $hash eq $dhash ) { if ( $param->{code} == 401 && $hash eq $dhash ) {
if ( ReadingsVal( $dname, 'token', 'none' ) eq 'none' ) { if ( ReadingsVal( $dname, 'token', 'none' ) eq 'none' ) {
readingsBulkUpdate( $dhash, "state", "no token available", 1 ); readingsBulkUpdate( $dhash, "state", "no token available", 1 );
@ -557,8 +558,8 @@ sub ErrorHandling {
} }
elsif ($param->{code} == 204 elsif ($param->{code} == 204
and $dhash ne $hash && $dhash ne $hash
and defined( $dhash->{helper}{deviceAction} ) ) && defined( $dhash->{helper}{deviceAction} ) )
{ {
readingsBulkUpdate( $dhash, "state", "the command is processed", readingsBulkUpdate( $dhash, "state", "the command is processed",
@ -591,9 +592,9 @@ sub ErrorHandling {
if ( if (
$data =~ /Error/ $data =~ /Error/
or ( defined($decode_json) || ( defined($decode_json)
and ref($decode_json) eq 'HASH' && ref($decode_json) eq 'HASH'
and defined( $decode_json->{errors} ) ) && defined( $decode_json->{errors} ) )
) )
{ {
readingsBeginUpdate($dhash); readingsBeginUpdate($dhash);
@ -605,7 +606,7 @@ sub ErrorHandling {
if ( $param->{code} == 400 ) { if ( $param->{code} == 400 ) {
if ($decode_json) { if ($decode_json) {
if ( ref( $decode_json->{errors} ) eq "ARRAY" if ( ref( $decode_json->{errors} ) eq "ARRAY"
and defined( $decode_json->{errors} ) ) && defined( $decode_json->{errors} ) )
{ {
readingsBulkUpdate( readingsBulkUpdate(
$dhash, $dhash,
@ -644,7 +645,7 @@ sub ErrorHandling {
} }
elsif ( $param->{code} == 404 ) { elsif ( $param->{code} == 404 ) {
if ( defined( $dhash->{helper}{deviceAction} ) and $dhash ne $hash ) if ( defined( $dhash->{helper}{deviceAction} ) && $dhash ne $hash )
{ {
readingsBulkUpdate( $dhash, "state", "device Id not found", 1 ); readingsBulkUpdate( $dhash, "state", "device Id not found", 1 );
readingsBulkUpdate( $dhash, "lastRequestState", readingsBulkUpdate( $dhash, "lastRequestState",
@ -708,7 +709,9 @@ sub ResponseProcessing {
} }
} }
if ( defined( $decode_json->{sessions} ) and $decode_json->{sessions} ) { # print Dumper $decode_json;
if ( defined( $decode_json->{sessions} ) && $decode_json->{sessions} ) {
$hash->{helper}{session_id} = $decode_json->{sessions}{token}; $hash->{helper}{session_id} = $decode_json->{sessions}{token};
$hash->{helper}{user_id} = $decode_json->{sessions}{user_id}; $hash->{helper}{user_id} = $decode_json->{sessions}{user_id};
@ -720,13 +723,12 @@ sub ResponseProcessing {
return; return;
} }
elsif ( not defined( $hash->{helper}{locations_id} ) elsif ( !defined( $hash->{helper}{locations_id} )
and defined( $decode_json->{locations} ) && defined( $decode_json->{locations} )
and ref( $decode_json->{locations} ) eq "ARRAY" && ref( $decode_json->{locations} ) eq 'ARRAY'
and scalar( @{ $decode_json->{locations} } ) > 0 ) && scalar( @{ $decode_json->{locations} } ) > 0 )
{ {
for my $location ( @{ $decode_json->{locations} } ) {
foreach my $location ( @{ $decode_json->{locations} } ) {
$hash->{helper}{locations_id} = $location->{id}; $hash->{helper}{locations_id} = $location->{id};
@ -739,11 +741,10 @@ sub ResponseProcessing {
Write( $hash, undef, undef, undef ); Write( $hash, undef, undef, undef );
return; return;
} }
elsif (defined( $decode_json->{devices} ) elsif (defined( $decode_json->{devices} )
and ref( $decode_json->{devices} ) eq "ARRAY" && ref( $decode_json->{devices} ) eq 'ARRAY'
and scalar( @{ $decode_json->{devices} } ) > 0 ) && scalar( @{ $decode_json->{devices} } ) > 0 )
{ {
my @buffer = split( '"devices":\[', $json ); my @buffer = split( '"devices":\[', $json );
@ -765,19 +766,18 @@ sub ResponseProcessing {
. " Tail: " . " Tail: "
. $tail; . $tail;
unless ( not defined($tail) and not($tail) ) { if ( defined($tail) and $tail ) {
$decode_json = eval { decode_json($json) }; $decode_json = eval { decode_json($json) };
if ($@) { if ($@) {
Log3 $name, 3, Log3 $name, 5,
"GardenaSmartBridge ($name) - JSON error while request: $@"; "GardenaSmartBridge ($name) - JSON error while request: $@";
} }
Dispatch( $hash, $json, undef ) Dispatch( $hash, $json, undef )
unless ( $decode_json->{category} eq 'gateway' ); if ( $decode_json->{category} ne 'gateway' );
WriteReadings( $hash, $decode_json ) WriteReadings( $hash, $decode_json )
if ( defined( $decode_json->{category} ) if ( defined( $decode_json->{category} )
and $decode_json->{category} eq 'gateway' ); && $decode_json->{category} eq 'gateway' );
} }
( $json, $tail ) = ParseJSON( $hash, $tail ); ( $json, $tail ) = ParseJSON( $hash, $tail );
@ -808,9 +808,9 @@ sub WriteReadings {
my $name = $hash->{NAME}; my $name = $hash->{NAME};
if ( defined( $decode_json->{id} ) if ( defined( $decode_json->{id} )
and $decode_json->{id} && $decode_json->{id}
and defined( $decode_json->{name} ) && defined( $decode_json->{name} )
and $decode_json->{name} ) && $decode_json->{name} )
{ {
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
if ( $decode_json->{id} eq $hash->{helper}{locations_id} ) { if ( $decode_json->{id} eq $hash->{helper}{locations_id} ) {
@ -831,8 +831,8 @@ sub WriteReadings {
scalar( @{ $decode_json->{zones} } ) ); scalar( @{ $decode_json->{zones} } ) );
} }
elsif ($decode_json->{id} ne $hash->{helper}{locations_id} elsif ($decode_json->{id} ne $hash->{helper}{locations_id}
and ref( $decode_json->{abilities} ) eq 'ARRAY' && ref( $decode_json->{abilities} ) eq 'ARRAY'
and ref( $decode_json->{abilities}[0]{properties} ) eq 'ARRAY' ) && ref( $decode_json->{abilities}[0]{properties} ) eq 'ARRAY' )
{ {
my $properties = my $properties =
scalar( @{ $decode_json->{abilities}[0]{properties} } ); scalar( @{ $decode_json->{abilities}[0]{properties} } );
@ -852,20 +852,20 @@ sub WriteReadings {
{name} . '-' . $t, {name} . '-' . $t,
$v $v
) )
unless ( if (
$decode_json->{abilities}[0]{properties}[$properties] $decode_json->{abilities}[0]{properties}[$properties]
{name} eq 'ethernet_status' {name} ne 'ethernet_status'
or $decode_json->{abilities}[0]{properties}[$properties] || $decode_json->{abilities}[0]{properties}
{name} eq 'wifi_status' ); [$properties]{name} ne 'wifi_status' );
if ( if (
( (
$decode_json->{abilities}[0]{properties} $decode_json->{abilities}[0]{properties}
[$properties]{name} eq 'ethernet_status' [$properties]{name} eq 'ethernet_status'
or $decode_json->{abilities}[0]{properties} || $decode_json->{abilities}[0]{properties}
[$properties]{name} eq 'wifi_status' [$properties]{name} eq 'wifi_status'
) )
and ref($v) eq 'HASH' && ref($v) eq 'HASH'
) )
{ {
if ( $decode_json->{abilities}[0]{properties} if ( $decode_json->{abilities}[0]{properties}
@ -945,17 +945,17 @@ sub getToken {
if ( AttrVal( $name, 'gardenaAccountEmail', 'none' ) eq 'none' ); if ( AttrVal( $name, 'gardenaAccountEmail', 'none' ) eq 'none' );
return readingsSingleUpdate( $hash, 'state', return readingsSingleUpdate( $hash, 'state',
'please set gardena account password first', 1 ) 'please set gardena account password first', 1 )
if ( not defined( ReadPassword( $hash, $name ) ) ); if ( !defined( ReadPassword( $hash, $name ) ) );
readingsSingleUpdate( $hash, 'state', 'get token', 1 ); readingsSingleUpdate( $hash, 'state', 'get token', 1 );
delete $hash->{helper}{session_id} delete $hash->{helper}{session_id}
if ( defined( $hash->{helper}{session_id} ) if ( defined( $hash->{helper}{session_id} )
and $hash->{helper}{session_id} ); && $hash->{helper}{session_id} );
delete $hash->{helper}{user_id} delete $hash->{helper}{user_id}
if ( defined( $hash->{helper}{user_id} ) and $hash->{helper}{user_id} ); if ( defined( $hash->{helper}{user_id} ) && $hash->{helper}{user_id} );
delete $hash->{helper}{locations_id} delete $hash->{helper}{locations_id}
if ( defined( $hash->{helper}{locations_id} ) if ( defined( $hash->{helper}{locations_id} )
and $hash->{helper}{locations_id} ); && $hash->{helper}{locations_id} );
Write( Write(
$hash, $hash,
@ -1072,14 +1072,14 @@ sub ParseJSON {
my $tail = ''; my $tail = '';
if ($buffer) { if ($buffer) {
foreach my $c ( split //, $buffer ) { for my $c ( split //, $buffer ) {
if ( $open == $close and $open > 0 ) { if ( $open == $close && $open > 0 ) {
$tail .= $c; $tail .= $c;
Log3 $name, 5, Log3 $name, 5,
"GardenaSmartBridge ($name) - $open == $close and $open > 0"; "GardenaSmartBridge ($name) - $open == $close and $open > 0";
} }
elsif ( ( $open == $close ) and ( $c ne '{' ) ) { elsif ( ( $open == $close ) && ( $c ne '{' ) ) {
Log3 $name, 5, Log3 $name, 5,
"GardenaSmartBridge ($name) - Garbage character before message: " "GardenaSmartBridge ($name) - Garbage character before message: "
@ -1124,25 +1124,25 @@ sub createHttpValueStrings {
$header .= "\r\nX-Session: $session_id" $header .= "\r\nX-Session: $session_id"
if ( defined( $hash->{helper}{session_id} ) ); if ( defined( $hash->{helper}{session_id} ) );
$payload = '{' . $payload . '}' if ( defined($payload) ); $payload = '{' . $payload . '}' if ( defined($payload) );
$payload = '{}' if ( not defined($payload) ); $payload = '{}' if ( !defined($payload) );
if ( $payload eq '{}' ) { if ( $payload eq '{}' ) {
$method = 'GET'; $method = 'GET';
$uri .= '/locations/?user_id=' . $hash->{helper}{user_id} $uri .= '/locations/?user_id=' . $hash->{helper}{user_id}
if ( exists( $hash->{helper}{user_id} ) if ( exists( $hash->{helper}{user_id} )
and not defined( $hash->{helper}{locations_id} ) ); && !defined( $hash->{helper}{locations_id} ) );
readingsSingleUpdate( $hash, 'state', 'fetch locationId', 1 ) readingsSingleUpdate( $hash, 'state', 'fetch locationId', 1 )
if ( not defined( $hash->{helper}{locations_id} ) ); if ( !defined( $hash->{helper}{locations_id} ) );
$uri .= '/sessions' if ( not defined( $hash->{helper}{session_id} ) ); $uri .= '/sessions' if ( !defined( $hash->{helper}{session_id} ) );
$uri .= '/devices' $uri .= '/devices'
if ( not defined($abilities) if (!defined($abilities)
and defined( $hash->{helper}{locations_id} ) ); && defined( $hash->{helper}{locations_id} ) );
} }
$uri .= '/sessions' if ( not defined( $hash->{helper}{session_id} ) ); $uri .= '/sessions' if ( !defined( $hash->{helper}{session_id} ) );
if ( defined( $hash->{helper}{locations_id} ) ) { if ( defined( $hash->{helper}{locations_id} ) ) {
if ( defined($abilities) and $abilities eq 'mower_settings' ) { if ( defined($abilities) && $abilities eq 'mower_settings' ) {
$method = 'PUT'; $method = 'PUT';
my $dhash = $modules{GardenaSmartDevice}{defptr}{$deviceId}; my $dhash = $modules{GardenaSmartDevice}{defptr}{$deviceId};
@ -1152,13 +1152,13 @@ sub createHttpValueStrings {
. '/settings/' . '/settings/'
. $dhash->{helper}{STARTINGPOINTID} . $dhash->{helper}{STARTINGPOINTID}
if ( defined($abilities) if ( defined($abilities)
and defined($payload) && defined($payload)
and $abilities eq 'mower_settings' ); && $abilities eq 'mower_settings' );
} }
elsif (defined($abilities) elsif (defined($abilities)
and defined($payload) && defined($payload)
and $abilities eq 'watering' ) && $abilities eq 'watering' )
{ {
my $valve_id; my $valve_id;
$method = 'PUT'; $method = 'PUT';
@ -1176,8 +1176,8 @@ sub createHttpValueStrings {
} }
elsif (defined($abilities) elsif (defined($abilities)
and defined($payload) && defined($payload)
and $abilities eq 'manual_watering' ) && $abilities eq 'manual_watering' )
{ {
my $valve_id; my $valve_id;
$method = 'PUT'; $method = 'PUT';
@ -1191,8 +1191,8 @@ sub createHttpValueStrings {
} }
elsif (defined($abilities) elsif (defined($abilities)
and defined($payload) && defined($payload)
and $abilities eq 'power' ) && $abilities eq 'power' )
{ {
my $valve_id; my $valve_id;
$method = 'PUT'; $method = 'PUT';
@ -1208,7 +1208,7 @@ sub createHttpValueStrings {
else { else {
$uri .= $uri .=
'/devices/' . $deviceId . '/abilities/' . $abilities . '/command' '/devices/' . $deviceId . '/abilities/' . $abilities . '/command'
if ( defined($abilities) and defined($payload) ); if ( defined($abilities) && defined($payload) );
} }
$uri .= '?locationId=' . $hash->{helper}{locations_id}; $uri .= '?locationId=' . $hash->{helper}{locations_id};

View File

@ -57,8 +57,6 @@
package FHEM::GardenaSmartDevice; package FHEM::GardenaSmartDevice;
use GPUtils qw(GP_Import GP_Export); use GPUtils qw(GP_Import GP_Export);
my $missingModul = "";
use strict; use strict;
use warnings; use warnings;
use POSIX; use POSIX;
@ -198,9 +196,6 @@ sub Define {
return return
"too few parameters: define <NAME> GardenaSmartDevice <device_Id> <model>" "too few parameters: define <NAME> GardenaSmartDevice <device_Id> <model>"
if ( scalar( @{$a} ) < 3 ); if ( scalar( @{$a} ) < 3 );
return
"Cannot define Gardena Bridge device. Perl modul $missingModul is missing."
if ($missingModul);
my $name = $a->[0]; my $name = $a->[0];
my $deviceId = $a->[2]; my $deviceId = $a->[2];
@ -233,8 +228,8 @@ sub Define {
return return
"GardenaSmartDevice device $name on GardenaSmartBridge $iodev already defined." "GardenaSmartDevice device $name on GardenaSmartBridge $iodev already defined."
if ( defined($d) if ( defined($d)
and $d->{IODev} == $hash->{IODev} && $d->{IODev} == $hash->{IODev}
and $d->{NAME} ne $name ); && $d->{NAME} ne $name );
CommandAttr( undef, $name . ' room GardenaSmart' ) CommandAttr( undef, $name . ' room GardenaSmart' )
if ( AttrVal( $name, 'room', 'none' ) eq 'none' ); if ( AttrVal( $name, 'room', 'none' ) eq 'none' );
@ -335,9 +330,9 @@ sub Set {
. ',"valve_id":' . ',"valve_id":'
. $valve_id . '}}'; . $valve_id . '}}';
} }
elsif ( lc $cmd eq 'on' or lc $cmd eq 'off' or 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($a) and ref($a) eq 'ARRAY' defined($a) && ref($a) eq 'ARRAY'
? $a->[0] * 60 ? $a->[0] * 60
: lc $cmd : lc $cmd
); );
@ -402,7 +397,7 @@ sub Set {
$abilities = 'mower' $abilities = 'mower'
if ( AttrVal( $name, 'model', 'unknown' ) eq 'mower' ) if ( AttrVal( $name, 'model', 'unknown' ) eq 'mower' )
and $abilities ne 'mower_settings'; && $abilities ne 'mower_settings';
$abilities = 'watering' $abilities = 'watering'
if ( AttrVal( $name, 'model', 'unknown' ) eq 'ic24' if ( AttrVal( $name, 'model', 'unknown' ) eq 'ic24'
|| AttrVal( $name, 'model', 'unknown' ) eq 'watering_computer' ); || AttrVal( $name, 'model', 'unknown' ) eq 'watering_computer' );
@ -480,11 +475,10 @@ sub WriteReadings {
if ( if (
ref( $decode_json->{abilities}[$abilities]{properties} ) eq "ARRAY" ref( $decode_json->{abilities}[$abilities]{properties} ) eq "ARRAY"
and && scalar( @{ $decode_json->{abilities}[$abilities]{properties} } )
scalar( @{ $decode_json->{abilities}[$abilities]{properties} } ) > > 0 )
0 )
{ {
foreach my $propertie ( for my $propertie (
@{ $decode_json->{abilities}[$abilities]{properties} } ) @{ $decode_json->{abilities}[$abilities]{properties} } )
{ {
readingsBulkUpdateIfChanged( readingsBulkUpdateIfChanged(
@ -494,21 +488,21 @@ sub WriteReadings {
RigRadingsValue( $hash, $propertie->{value} ) RigRadingsValue( $hash, $propertie->{value} )
) )
if ( defined( $propertie->{value} ) if ( defined( $propertie->{value} )
and $decode_json->{abilities}[$abilities]{name} . '-' && $decode_json->{abilities}[$abilities]{name} . '-'
. $propertie->{name} ne 'radio-quality' . $propertie->{name} ne 'radio-quality'
and $decode_json->{abilities}[$abilities]{name} . '-' && $decode_json->{abilities}[$abilities]{name} . '-'
. $propertie->{name} ne 'battery-level' . $propertie->{name} ne 'battery-level'
and $decode_json->{abilities}[$abilities]{name} . '-' && $decode_json->{abilities}[$abilities]{name} . '-'
. $propertie->{name} ne 'internal_temperature-temperature' . $propertie->{name} ne 'internal_temperature-temperature'
and $decode_json->{abilities}[$abilities]{name} . '-' && $decode_json->{abilities}[$abilities]{name} . '-'
. $propertie->{name} ne 'ambient_temperature-temperature' . $propertie->{name} ne 'ambient_temperature-temperature'
and $decode_json->{abilities}[$abilities]{name} . '-' && $decode_json->{abilities}[$abilities]{name} . '-'
. $propertie->{name} ne 'soil_temperature-temperature' . $propertie->{name} ne 'soil_temperature-temperature'
and $decode_json->{abilities}[$abilities]{name} . '-' && $decode_json->{abilities}[$abilities]{name} . '-'
. $propertie->{name} ne 'humidity-humidity' . $propertie->{name} ne 'humidity-humidity'
and $decode_json->{abilities}[$abilities]{name} . '-' && $decode_json->{abilities}[$abilities]{name} . '-'
. $propertie->{name} ne 'light-light' . $propertie->{name} ne 'light-light'
and ref( $propertie->{value} ) ne "HASH" ); && ref( $propertie->{value} ) ne "HASH" );
readingsBulkUpdate( readingsBulkUpdate(
$hash, $hash,
@ -518,21 +512,21 @@ sub WriteReadings {
) )
if ( if (
defined( $propertie->{value} ) defined( $propertie->{value} )
and ( $decode_json->{abilities}[$abilities]{name} . '-' && ( $decode_json->{abilities}[$abilities]{name} . '-'
. $propertie->{name} eq 'radio-quality' . $propertie->{name} eq 'radio-quality'
or $decode_json->{abilities}[$abilities]{name} . '-' || $decode_json->{abilities}[$abilities]{name} . '-'
. $propertie->{name} eq 'battery-level' . $propertie->{name} eq 'battery-level'
or $decode_json->{abilities}[$abilities]{name} . '-' || $decode_json->{abilities}[$abilities]{name} . '-'
. $propertie->{name} eq . $propertie->{name} eq
'internal_temperature-temperature' 'internal_temperature-temperature'
or $decode_json->{abilities}[$abilities]{name} . '-' || $decode_json->{abilities}[$abilities]{name} . '-'
. $propertie->{name} eq . $propertie->{name} eq
'ambient_temperature-temperature' 'ambient_temperature-temperature'
or $decode_json->{abilities}[$abilities]{name} . '-' || $decode_json->{abilities}[$abilities]{name} . '-'
. $propertie->{name} eq 'soil_temperature-temperature' . $propertie->{name} eq 'soil_temperature-temperature'
or $decode_json->{abilities}[$abilities]{name} . '-' || $decode_json->{abilities}[$abilities]{name} . '-'
. $propertie->{name} eq 'humidity-humidity' . $propertie->{name} eq 'humidity-humidity'
or $decode_json->{abilities}[$abilities]{name} . '-' || $decode_json->{abilities}[$abilities]{name} . '-'
. $propertie->{name} eq 'light-light' ) . $propertie->{name} eq 'light-light' )
); );
@ -543,7 +537,7 @@ sub WriteReadings {
join( ',', @{ $propertie->{value} } ) join( ',', @{ $propertie->{value} } )
) )
if ( defined( $propertie->{value} ) if ( defined( $propertie->{value} )
and $decode_json->{abilities}[$abilities]{name} . '-' && $decode_json->{abilities}[$abilities]{name} . '-'
. $propertie->{name} eq 'ic24-valves_connected' ); . $propertie->{name} eq 'ic24-valves_connected' );
readingsBulkUpdateIfChanged( readingsBulkUpdateIfChanged(
@ -553,7 +547,7 @@ sub WriteReadings {
join( ',', @{ $propertie->{value} } ) join( ',', @{ $propertie->{value} } )
) )
if ( defined( $propertie->{value} ) if ( defined( $propertie->{value} )
and $decode_json->{abilities}[$abilities]{name} . '-' && $decode_json->{abilities}[$abilities]{name} . '-'
. $propertie->{name} eq 'ic24-valves_master_config' ); . $propertie->{name} eq 'ic24-valves_master_config' );
if ( ref( $propertie->{value} ) eq "HASH" ) { if ( ref( $propertie->{value} ) eq "HASH" ) {
@ -576,7 +570,7 @@ sub WriteReadings {
do { do {
if ( ref( $decode_json->{settings}[$settings]{value} ) eq "ARRAY" if ( ref( $decode_json->{settings}[$settings]{value} ) eq "ARRAY"
and $decode_json->{settings}[$settings]{name} eq 'starting_points' ) && $decode_json->{settings}[$settings]{name} eq 'starting_points' )
{ {
#save the startingpointid needed to update the startingpoints #save the startingpointid needed to update the startingpoints
if ( $hash->{helper}{STARTINGPOINTID} ne if ( $hash->{helper}{STARTINGPOINTID} ne
@ -591,7 +585,7 @@ sub WriteReadings {
. encode_json( $decode_json->{settings}[$settings]{value} ) . '}'; . encode_json( $decode_json->{settings}[$settings]{value} ) . '}';
my $startpoint_cnt = 0; my $startpoint_cnt = 0;
foreach my $startingpoint ( for my $startingpoint (
@{ $decode_json->{settings}[$settings]{value} } ) @{ $decode_json->{settings}[$settings]{value} } )
{ {
$startpoint_cnt++; $startpoint_cnt++;
@ -762,9 +756,9 @@ sub ReadingLangGerman {
if ( if (
defined( $langGermanMapp{$readingValue} ) defined( $langGermanMapp{$readingValue} )
and ( AttrVal( 'global', 'language', 'none' ) eq 'DE' && ( AttrVal( 'global', 'language', 'none' ) eq 'DE'
or AttrVal( $name, 'readingValueLanguage', 'none' ) eq 'de' ) || AttrVal( $name, 'readingValueLanguage', 'none' ) eq 'de' )
and AttrVal( $name, 'readingValueLanguage', 'none' ) ne 'en' && AttrVal( $name, 'readingValueLanguage', 'none' ) ne 'en'
) )
{ {
return $langGermanMapp{$readingValue}; return $langGermanMapp{$readingValue};
@ -841,9 +835,9 @@ sub SetPredefinedStartPoints {
my $payload; my $payload;
my $abilities; my $abilities;
if ( defined($startpoint_state) and defined($startpoint_num) ) { if ( defined($startpoint_state) && defined($startpoint_num) ) {
if ( defined( $hash->{helper}{STARTINGPOINTS} ) if ( defined( $hash->{helper}{STARTINGPOINTS} )
and $hash->{helper}{STARTINGPOINTS} ne '' ) && $hash->{helper}{STARTINGPOINTS} ne '' )
{ {
# add needed parameters to saved settings config and change the value in request # add needed parameters to saved settings config and change the value in request
my $decode_json_settings = my $decode_json_settings =
@ -861,8 +855,8 @@ sub SetPredefinedStartPoints {
#set more startpoints #set more startpoints
if ( if (
defined scalar(@morestartpoints) defined scalar(@morestartpoints)
and ( scalar(@morestartpoints) == 2 && ( scalar(@morestartpoints) == 2
or scalar(@morestartpoints) == 4 ) || scalar(@morestartpoints) == 4 )
) )
{ {
if ( scalar(@morestartpoints) == 2 ) { if ( scalar(@morestartpoints) == 2 ) {