From 28975d8ce004f7f256c1341b0a6e63d2e19e7cd3 Mon Sep 17 00:00:00 2001
From: StefanStrobel <>
Date: Sat, 13 Mar 2021 10:14:34 +0000
Subject: [PATCH] 98_HTTPMOD: small fixes
git-svn-id: https://svn.fhem.de/fhem/trunk@23943 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/FHEM/98_HTTPMOD.pm | 27 +++++-----
fhem/lib/FHEM/HTTPMOD/Utils.pm | 95 ++++++++++++++++++++++------------
2 files changed, 77 insertions(+), 45 deletions(-)
diff --git a/fhem/FHEM/98_HTTPMOD.pm b/fhem/FHEM/98_HTTPMOD.pm
index 8a3b390ec..3d5012360 100755
--- a/fhem/FHEM/98_HTTPMOD.pm
+++ b/fhem/FHEM/98_HTTPMOD.pm
@@ -141,7 +141,7 @@ BEGIN {
));
};
-my $Module_Version = '4.1.02 - 4.2.2021';
+my $Module_Version = '4.1.05 - 6.3.2021';
my $AttrList = join (' ',
'(reading|get|set)[0-9]+(-[0-9]+)?Name',
@@ -189,7 +189,7 @@ my $AttrList = join (' ',
'preProcessRegex',
'parseFunction1',
'parseFunction2',
- 'set[0-9]+Temp',
+ 'set[0-9]+Local', # don't create a request and just set a reading
'[gs]et[0-9]*URL',
'[gs]et[0-9]*Data.*',
'[gs]et[0-9]*NoData.*', # make sure it is an HTTP GET without data - even if a more generic data is defined
@@ -434,7 +434,7 @@ sub AttrFn {
my $cmd = shift; # 'set' or 'del'
my $name = shift; # the Fhem device name
my $aName = shift; # attribute name
- my $aVal = shift; # attribute value
+ my $aVal = shift // ''; # attribute value
my $hash = $defs{$name}; # reference to the Fhem device hash
Log3 $name, 5, "$name: attr $name $aName $aVal";
@@ -942,8 +942,8 @@ sub PrepareRequest {
}
#Log3 $name, 5, "$name: PrepareRequest got url $url, header $header and data $data";
$header = EvalExpr($hash, {expr => GetFAttr($name, $context, $num, "HdrExpr"), val => $header, action => 'HdrExpr'});
- $data = EvalExpr($hash, {expr => GetFAttr($name, $context, $num, "DatExpr"), val => $data, action => 'DatExpr'});
- $url = EvalExpr($hash, {expr => GetFAttr($name, $context, $num, "URLExpr"), val => $url, action => 'URLExpr'});
+ $data = EvalExpr($hash, {expr => GetFAttr($name, $context, $num, "DatExpr"), val => $data, action => 'DatExpr'});
+ $url = EvalExpr($hash, {expr => GetFAttr($name, $context, $num, "URLExpr"), val => $url, action => 'URLExpr'});
my $type;
if ($context eq 'reading') {
@@ -1254,7 +1254,7 @@ sub SetFn {
$rawVal = 0;
Log3 $name, 4, "$name: set will now set $setName";
}
- if (!AttrVal($name, "set${setNum}Temp", undef)) { # soll überhaupt ein Request erzeugt werden?
+ if (!AttrVal($name, "set${setNum}Local", undef)) { # soll überhaupt ein Request erzeugt werden?
my $request = PrepareRequest($hash, "set", $setNum);
if ($request->{'url'}) {
DoAuth $hash if (AttrVal($name, "reAuthAlways", 0));
@@ -1479,10 +1479,11 @@ sub FormatReading {
$expr = GetFAttr($name, $context, $num, "Expr", $expr) if ($context ne "set"); # not for set!
$expr = GetFAttr($name, $context, $num, "OExpr", $expr); # new syntax
- # if no encode is specified and bodyDecode did decode, then encode as utf8 by default
- #my $fDefault = ($featurelevel > 5.9 ? 'auto' : '');
- my $bodyDecode = AttrVal($name, 'bodyDecode', '');
- $encode = 'utf8' if (!$encode && $bodyDecode ne 'none');
+ # encode as utf8 by default if no encode is specified and body was decoded or no charset was seen in the header
+ if (!$encode && (!$hash->{'.bodyCharset'} || $hash->{'.bodyCharset'} eq 'internal' )) { # body was decoded and encode not sepcified
+ $encode = 'utf8';
+ Log3 $name, 5, "$name: FormatReading is encoding the reading value as utf-8 because no encoding was specified and the response body charset was unknown or decoded";
+ }
$val = decode($decode, $val) if ($decode && $decode ne 'none');
$val = encode($encode, $val) if ($encode && $encode ne 'none');
@@ -2276,7 +2277,7 @@ sub DumpBuffer {
my $fh;
$hash->{BufCounter} = 0 if (!$hash->{BufCounter});
$hash->{BufCounter} ++;
- my $path = AttrVal($name, "dumpBuffers", 0);
+ my $path = AttrVal($name, "dumpBuffers", '.');
Log3 $name, 3, "$name: dump buffer to $path/buffer$hash->{BufCounter}.txt";
open($fh, '>', "$path/buffer$hash->{BufCounter}.txt"); ## no critic
if ($header) {
@@ -2737,7 +2738,7 @@ sub AddToSendQueue {
attr PM reading02Name CL
attr PM reading02Regex 34.4008.value":[ \t]+"([\d\.]+)"
- attr PM reading03Name3TEMP
+ attr PM reading03Name TEMP
attr PM reading03Regex 34.4033.value":[ \t]+"([\d\.]+)"
attr PM requestData {"get" :["34.4001.value" ,"34.4008.value" ,"34.4033.value", "14.16601.value", "14.16602.value"]}
@@ -3469,6 +3470,8 @@ sub AddToSendQueue {
Defines that this set option doesn't require arguments. It allows sets like "on" or "off" without further values.