mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
fhem.pl: reorder EvalSpecials (Forum #44412)
git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@9965 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
c8db0e743a
commit
3e248eadf2
34
fhem.pl
34
fhem.pl
@ -959,7 +959,7 @@ AnalyzePerlCommand($$;$)
|
|||||||
$year+=1900;
|
$year+=1900;
|
||||||
|
|
||||||
if($evalSpecials) {
|
if($evalSpecials) {
|
||||||
$cmd = join("", map { my $n = substr($_,1);
|
$cmd = join("", map { my $n = substr($_,1); # ignore the %
|
||||||
my $v = $evalSpecials->{$_};
|
my $v = $evalSpecials->{$_};
|
||||||
$v =~ s/(['\\])/\\$1/g;
|
$v =~ s/(['\\])/\\$1/g;
|
||||||
"my \$$n='$v';";
|
"my \$$n='$v';";
|
||||||
@ -2878,18 +2878,12 @@ SemicolonEscape($)
|
|||||||
sub
|
sub
|
||||||
EvalSpecials($%)
|
EvalSpecials($%)
|
||||||
{
|
{
|
||||||
# The character % will be replaced with the received event,
|
# $NAME will be replaced with the device name which generated the event
|
||||||
# e.g. with on or off or measured-temp: 21.7 (Celsius)
|
# $EVENT will be replaced with the whole event string
|
||||||
# The character @ will be replaced with the device name.
|
# $EVTPART<N> will be replaced with single words of an event
|
||||||
# To use % or @ in the text itself, use the double mode (%% or @@).
|
|
||||||
# Instead of % and @, the parameters %EVENT (same as %),
|
|
||||||
# %NAME (same as @) and %TYPE (contains the device type, e.g. FHT)
|
|
||||||
# can be used. A single % looses its special meaning if any of these
|
|
||||||
# parameters appears in the definition.
|
|
||||||
my ($exec, %specials)= @_;
|
my ($exec, %specials)= @_;
|
||||||
$exec = SemicolonEscape($exec);
|
$exec = SemicolonEscape($exec);
|
||||||
|
|
||||||
# %EVTPART due to HM remote logic
|
|
||||||
my $idx = 0;
|
my $idx = 0;
|
||||||
if(defined($specials{"%EVENT"})) {
|
if(defined($specials{"%EVENT"})) {
|
||||||
foreach my $part (split(" ", $specials{"%EVENT"})) {
|
foreach my $part (split(" ", $specials{"%EVENT"})) {
|
||||||
@ -2898,15 +2892,25 @@ EvalSpecials($%)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
my $re = join("|", keys %specials);
|
if($featurelevel > 5.6) {
|
||||||
|
$evalSpecials = \%specials;
|
||||||
|
return $exec;
|
||||||
|
}
|
||||||
|
|
||||||
|
# featurelevel <= 5.6 only:
|
||||||
|
# The character % will be replaced with the received event,
|
||||||
|
# e.g. with on or off or measured-temp: 21.7 (Celsius)
|
||||||
|
# The character @ will be replaced with the device name.
|
||||||
|
# To use % or @ in the text itself, use the double mode (%% or @@).
|
||||||
|
|
||||||
|
my $re = join("|", keys %specials); # Found the $syntax, skip the rest
|
||||||
$re =~ s/%//g;
|
$re =~ s/%//g;
|
||||||
if($exec =~ m/\$($re)\b/) {
|
if($exec =~ m/\$($re)\b/) {
|
||||||
$evalSpecials = \%specials;
|
$evalSpecials = \%specials;
|
||||||
return $exec;
|
return $exec;
|
||||||
}
|
}
|
||||||
|
|
||||||
$exec =~ s/%%/____/g if($featurelevel <= 5.6);
|
$exec =~ s/%%/____/g;
|
||||||
|
|
||||||
|
|
||||||
# perform macro substitution
|
# perform macro substitution
|
||||||
my $extsyntax= 0;
|
my $extsyntax= 0;
|
||||||
@ -2914,18 +2918,14 @@ EvalSpecials($%)
|
|||||||
$extsyntax+= ($exec =~ s/$special/$specials{$special}/g);
|
$extsyntax+= ($exec =~ s/$special/$specials{$special}/g);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($featurelevel <= 5.6) {
|
|
||||||
if(!$extsyntax) {
|
if(!$extsyntax) {
|
||||||
$exec =~ s/%/$specials{"%EVENT"}/g;
|
$exec =~ s/%/$specials{"%EVENT"}/g;
|
||||||
}
|
}
|
||||||
$exec =~ s/____/%/g;
|
$exec =~ s/____/%/g;
|
||||||
}
|
|
||||||
|
|
||||||
if($featurelevel <= 5.6) {
|
|
||||||
$exec =~ s/@@/____/g;
|
$exec =~ s/@@/____/g;
|
||||||
$exec =~ s/@/$specials{"%NAME"}/g;
|
$exec =~ s/@/$specials{"%NAME"}/g;
|
||||||
$exec =~ s/____/@/g;
|
$exec =~ s/____/@/g;
|
||||||
}
|
|
||||||
|
|
||||||
return $exec;
|
return $exec;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user