98_HTTPMOD: small bug fixes

git-svn-id: https://svn.fhem.de/fhem/trunk@23330 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
StefanStrobel
2020-12-12 10:56:29 +00:00
parent ae61f8824c
commit ff68f50257

View File

@@ -76,6 +76,7 @@ our %EXPORT_TAGS = (all => [@EXPORT_OK]);
BEGIN { BEGIN {
GP_Import( qw( GP_Import( qw(
fhem
CommandAttr CommandAttr
CommandDeleteAttr CommandDeleteAttr
addToDevAttrList addToDevAttrList
@@ -140,7 +141,7 @@ BEGIN {
)); ));
}; };
my $Module_Version = '4.0.12 - 24.10.2020'; my $Module_Version = '4.0.16 - 5.12.2020';
my $AttrList = join (' ', my $AttrList = join (' ',
'(reading|get|set)[0-9]+(-[0-9]+)?Name', '(reading|get|set)[0-9]+(-[0-9]+)?Name',
@@ -827,17 +828,25 @@ sub DoReplacement {
next if (!$regex); next if (!$regex);
my $value = ""; # value can be specific for a get / set / auth step (with a number in $type) my $value = ""; # value can be specific for a get / set / auth step (with a number in $type)
#Log3 $name, 5, "$name: Replace: check value as ${type}Replacement${rNum}Value";
if ($context && defined ($attr{$name}{"${type}Replacement${rNum}Value"})) { if ($context && defined ($attr{$name}{"${type}Replacement${rNum}Value"})) {
# get / set / auth mit individuellem Replacement für z.B. get01 # get / set / auth mit individuellem Replacement für z.B. get01
$value = $attr{$name}{"${type}Replacement${rNum}Value"}; $value = $attr{$name}{"${type}Replacement${rNum}Value"};
} } else {
elsif ($context && defined ($attr{$name}{"${context}Replacement${rNum}Value"})) { #Log3 $name, 5, "$name: Replace: check value as ${context}Replacement${rNum}Value";
# get / set / auth mit generischem Replacement für alle gets / sets (without the number) if ($context && defined ($attr{$name}{"${context}Replacement${rNum}Value"})) {
$value = $attr{$name}{"${context}Replacement${rNum}Value"}; # get / set / auth mit generischem Replacement für alle gets / sets (without the number)
} $value = $attr{$name}{"${context}Replacement${rNum}Value"};
elsif (defined ($attr{$name}{"replacement${rNum}Value"})) { } else {
# ganz generisches Replacement #Log3 $name, 5, "$name: Replace: check value as replacement${rNum}Value";
$value = $attr{$name}{"replacement${rNum}Value"}; if (defined ($attr{$name}{"replacement${rNum}Value"})) {
# ganz generisches Replacement
$value = $attr{$name}{"replacement${rNum}Value"};
} else {
#Log3 $name, 5, "$name: Replace: no matching value attribute found";
}
}
} }
Log3 $name, 5, "$name: Replace called for type $type, regex $regex, mode $mode, " . Log3 $name, 5, "$name: Replace called for type $type, regex $regex, mode $mode, " .
($value ? "value $value" : "empty value") . " input: $string"; ($value ? "value $value" : "empty value") . " input: $string";
@@ -873,7 +882,9 @@ sub DoReplacement {
} }
} }
elsif ($mode eq 'expression') { elsif ($mode eq 'expression') {
local $SIG{__WARN__} = sub { Log3 $name, 3, "$name: Replacement $rNum with expression $value (s/$regex/$value/gee) created warning: @_"; }; $value = 'package main; ' . ($value // '');
local $SIG{__WARN__} = sub { Log3 $name, 3, "$name: Replacement $rNum with expression $value and regex $regex created warning: @_"; };
# if expression calls other fhem functions, creates readings or other, then the warning handler will create misleading messages!
$match = eval { $string =~ s/$regex/$value/gee }; $match = eval { $string =~ s/$regex/$value/gee };
if ($@) { if ($@) {
Log3 $name, 3, "$name: Replace: invalid regex / expression: /$regex/$value/gee - $@"; Log3 $name, 3, "$name: Replace: invalid regex / expression: /$regex/$value/gee - $@";
@@ -2262,7 +2273,7 @@ sub ReadCallback {
my $type = $request->{'type'}; # type of request that was sent (like get01, update or auth01) my $type = $request->{'type'}; # type of request that was sent (like get01, update or auth01)
my $header = $huHash->{httpheader} // ''; # HTTP headers received my $header = $huHash->{httpheader} // ''; # HTTP headers received
delete $huHash->{DEVHASH}; delete $huHash->{DEVHASH};
$hash->{HttpUtils} = $huHash; # make the httpUtils hash available in case anyone wants tu use variables $hash->{HttpUtils} = $huHash; # make the httpUtils hash available in case anyone wants to use variables
$hash->{BUSY} = 0; $hash->{BUSY} = 0;
Log3 $name, 5, "$name: ReadCallback called from " . FhemCaller(); Log3 $name, 5, "$name: ReadCallback called from " . FhemCaller();