mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-16 16:56:04 +00:00
AttrTemplate.pm: add farewell, fix \DEVICE in par (Forum #97989)
git-svn-id: https://svn.fhem.de/fhem/trunk@19002 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
86d5d68de8
commit
19f7847b01
@ -52,6 +52,9 @@ AttrTemplate_Initialize()
|
||||
} elsif($line =~ m/^desc:(.*)/) {
|
||||
$templates{$name}{desc} = $1;
|
||||
|
||||
} elsif($line =~ m/^farewell:(.*)/) {
|
||||
$templates{$name}{farewell} = $1;
|
||||
|
||||
} else {
|
||||
push(@{$templates{$name}{cmds}}, $line);
|
||||
|
||||
@ -128,7 +131,8 @@ AttrTemplate_Set($$@)
|
||||
}
|
||||
|
||||
if($perl_code) {
|
||||
$perl_code =~ s/DEVICE/$name/g;
|
||||
$perl_code =~ s/(?<!\\)DEVICE/$name/g;
|
||||
$perl_code =~ s/\\DEVICE/DEVICE/g;
|
||||
my $ret = eval $perl_code;
|
||||
return "Error checking template regexp: $@" if($@);
|
||||
if($ret) {
|
||||
@ -186,7 +190,20 @@ AttrTemplate_Set($$@)
|
||||
$cmd = "";
|
||||
}
|
||||
} split("\n", $cmdlist);
|
||||
return @ret ? join("\n", @ret) : undef;
|
||||
|
||||
return join("\n", @ret) if(@ret);
|
||||
|
||||
if($h->{farewell}) {
|
||||
my $fw = $h->{farewell};
|
||||
if(!$cl || $cl->{TYPE} ne "FHEMWEB") {
|
||||
$fw =~ s/<br>/\n/gi;
|
||||
$fw =~ s/<[^>]+>//g; # remove html tags
|
||||
}
|
||||
return $fw if(!$cl);
|
||||
InternalTimer(gettimeofday()+1, sub{asyncOutput($cl, $fw)}, undef, 0);
|
||||
}
|
||||
return undef;
|
||||
|
||||
}
|
||||
|
||||
1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user