From 774bea905df6d398e1ba796c3f70846d08d3ef55 Mon Sep 17 00:00:00 2001 From: StefanStrobel <> Date: Thu, 8 Apr 2021 10:59:25 +0000 Subject: [PATCH] 98_HTTPMOD: change userattr handling and fix doku git-svn-id: https://svn.fhem.de/fhem/trunk@24185 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/98_HTTPMOD.pm | 7 +++++-- fhem/lib/FHEM/HTTPMOD/Utils.pm | 20 +++++++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/fhem/FHEM/98_HTTPMOD.pm b/fhem/FHEM/98_HTTPMOD.pm index fdd051313..8840b0caf 100755 --- a/fhem/FHEM/98_HTTPMOD.pm +++ b/fhem/FHEM/98_HTTPMOD.pm @@ -660,7 +660,7 @@ sub UpgradeAttributes { if ($aName =~ /(.+)IDRegex$/) { my $new = $1 . "IdRegex"; my $val = $attr{$name}{$aName}; - CommandAttr(undef, "$name $new $val"); # also adds new attr to userattr list through _Attr function + CommandAttr(undef, "$name $new $val"); CommandDeleteAttr(undef, "$name $aName"); $dHash{$aName} = 1; Log3 $name, 3, "$name: upgraded attribute name $aName to new sytax $new"; @@ -3645,7 +3645,10 @@ sub AddToSendQueue { restricts the effect of errorLogLevel to such error messages that match this regex.
  • Remarks regarding the automatically created userattr entries
  • - Fhemweb allows attributes to be edited by clicking on them. However this does not work for attributes that match to a wildcard attribute. To circumvent this restriction HTTPMOD automatically adds an entry for each instance of a defined wildcard attribute to the device userattr list. E.g. if you define a reading[0-9]Name attribute as reading01Name, HTTPMOD will add reading01Name to the device userattr list. These entries only have the purpose of making editing in Fhemweb easier. + Fhemweb allows attributes to be edited by clicking on them. However this did not work for attributes that match to a wildcard attribute in earlier versions. + To circumvent this restriction HTTPMOD automatically added an entry for each instance of a defined wildcard attribute to the device userattr list. + E.g. if you define a reading[0-9]Name attribute as reading01Name, HTTPMOD added reading01Name to the device userattr list. + These entries only had the purpose of making editing in Fhemweb easier. In newer versions this has become obsolete.
    Author's notes

    diff --git a/fhem/lib/FHEM/HTTPMOD/Utils.pm b/fhem/lib/FHEM/HTTPMOD/Utils.pm index b025476d5..43f410bb5 100644 --- a/fhem/lib/FHEM/HTTPMOD/Utils.pm +++ b/fhem/lib/FHEM/HTTPMOD/Utils.pm @@ -474,8 +474,13 @@ sub SwapByteOrder { } -######################################################################### +############################################################################ # set userAttr-Attribute for Regex-Attrs +# with recent version of fhem userattrs are no longer needed +# to edit them or match hints. +# so remove all userattr entries for regex attrs +# unless their hint is different from the one in the modules list +# # pass device hash and new attr based on a regex attr sub ManageUserAttr { my $hash = shift; @@ -509,13 +514,13 @@ sub ManageUserAttr { UALOOP: foreach my $userAttr (split(" ", $uaList)) { # for every userAttr my ($userAttrName, $userAttrHint) - = $userAttr =~ m{ \A ([^:]+) (:?.*) }xms; # split module attr list entry in name and optional hint + = $userAttr =~ m{ \A ([^:]+) (:?.*) }xms; # split user attr list entry in name and optional hint #Log3 $name, 5, "$name: ManageUserAttr compares userattr name $userAttrName with passed attr name $aName"; if ($userAttrName eq $aName) { #Log3 $name, 5, "$name: ManageUserAttr compares hints from userattr $userAttrHint with hint from list $listAttrHint"; $found = 1; if ($userAttrHint && $userAttrHint ne ($listAttrHint // '')) { - $uaHash{$userAttr} = 1; # keep $userAttr with hint if module attr has no hint + $uaHash{$userAttr} = 1; # keep $userAttr with hint if module attr has different or no hint #Log3 $name, 5, "$name: ManageUserAttr keeps userattr $userAttr with different hint"; } } else { @@ -523,10 +528,11 @@ sub ManageUserAttr { #Log3 $name, 5, "$name: ManageUserAttr keeps other existing userattr $userAttr"; } } - if (!$found && $listAttrHint) { # add userAttr with attr from module list - $uaHash{$aName . $listAttrHint} = 1; - #Log3 $name, 5, "$name: ManageUserAttr adds $aName$listAttrHint"; - } + # this code is no longer necessary - fhem recognizes hints from regex attrs by itself now + #if (!$found && $listAttrHint) { # add userAttr with attr from module list + # $uaHash{$aName . $listAttrHint} = 1; + # #Log3 $name, 5, "$name: ManageUserAttr adds $aName$listAttrHint"; + #} my $aString = join(" ", sort keys %uaHash); # reconstruct userAttr list string if ($aString) { $attr{$name}{userattr} = $aString;