diff --git a/fhem/CHANGED b/fhem/CHANGED index 8ca05a6a2..8e9cb56a5 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,4 +1,4 @@ -- CVS +- SVN - bugfix: applying smallscreen attributes to firefox/opera - feature: CUL_TX added (thanks to Peterp) - feature: TCM120/TCM310 + EnOcean parser added @@ -11,6 +11,7 @@ - feature: CUL directio mode (No Device::SerialPort needed) - feature: FritzBox 7270 ZIP file - buxgfix: prevent fhem from stalling if telnet times out in 66_ECMD.pm + - feature: added postproc ability to classdef in 66_ECMD.pm (Boris, Heinz) - feature: FHEMWEB longpoll mode, small fixes, tuned smallscreen mode - feature: average module added - change: moved the berliOS CVS repository to a sourceforge SVN repository diff --git a/fhem/FHEM/66_ECMD.pm b/fhem/FHEM/66_ECMD.pm index 7b4f7102a..c84e4fcf5 100644 --- a/fhem/FHEM/66_ECMD.pm +++ b/fhem/FHEM/66_ECMD.pm @@ -510,15 +510,29 @@ ECMD_EvalClassDef($$$) Log 1, "$name: command for $cmd $cmdname is not a perl command."; next; } - $arg =~ s/^(\\\n|[ \t])*//; # Strip space or \\n at the begginning + $arg =~ s/^(\\\n|[ \t])*//; # Strip space or \\n at the beginning $arg =~ s/[ \t]*$//; if($cmd eq "set") { - Log 5, "$name: set $cmdname defined as $arg"; + Log 5, "$name: set $cmdname command defined as $arg"; $hash->{fhem}{classDefs}{$classname}{sets}{$cmdname}{cmd}= $arg; } elsif($cmd eq "get") { - Log 5, "$name: get $cmdname defined as $arg"; + Log 5, "$name: get $cmdname command defined as $arg"; $hash->{fhem}{classDefs}{$classname}{gets}{$cmdname}{cmd}= $arg; } + } elsif($spec eq "postproc") { + if($arg !~ m/^{.*}$/s) { + Log 1, "$name: postproc command for $cmd $cmdname is not a perl command."; + next; + } + $arg =~ s/^(\\\n|[ \t])*//; # Strip space or \\n at the beginning + $arg =~ s/[ \t]*$//; + if($cmd eq "set") { + Log 5, "$name: set $cmdname postprocessor defined as $arg"; + $hash->{fhem}{classDefs}{$classname}{sets}{$cmdname}{postproc}= $arg; + } elsif($cmd eq "get") { + Log 5, "$name: get $cmdname postprocessor defined as $arg"; + $hash->{fhem}{classDefs}{$classname}{gets}{$cmdname}{postproc}= $arg; + } } } else { Log 1, "$name: illegal tag $cmd for class $classname in file $filename."; diff --git a/fhem/FHEM/67_ECMDDevice.pm b/fhem/FHEM/67_ECMDDevice.pm index 406fb8a3b..e0537c125 100644 --- a/fhem/FHEM/67_ECMDDevice.pm +++ b/fhem/FHEM/67_ECMDDevice.pm @@ -35,6 +35,7 @@ ECMDDevice_Initialize($) $hash->{AttrList} = "loglevel 0,1,2,3,4,5"; } +################################### sub ECMDDevice_AnalyzeCommand($) { @@ -95,6 +96,29 @@ ECMDDevice_Changed($$$) } ################################### +sub +ECMDDevice_PostProc($$$) +{ + my ($hash, $postproc, $value)= @_; + + # the following lines are commented out because we do not want specials to be evaluated + # this is mainly due to the unwanted substitution of single semicolons by double semicolons + #my %specials= ECMDDevice_DeviceParams2Specials($hash); + #my $command= EvalSpecials($postproc, %specials); + # we pass the command verbatim instead + my $command= $postproc; + + if($postproc) { + $_= $value; + Log 5, "Postprocessing $value with perl command $command."; + $value= AnalyzePerlCommand(undef, $command); + } + return $value; +} + + +################################### + sub ECMDDevice_Get($@) { @@ -113,6 +137,7 @@ ECMDDevice_Get($@) my $ecmd= $IOhash->{fhem}{classDefs}{$classname}{gets}{$cmdname}{cmd}; my $params= $IOhash->{fhem}{classDefs}{$classname}{gets}{$cmdname}{params}; + my $postproc= $IOhash->{fhem}{classDefs}{$classname}{gets}{$cmdname}{postproc}; my %specials= ECMDDevice_DeviceParams2Specials($hash); # add specials for command @@ -133,6 +158,8 @@ ECMDDevice_Get($@) my $v= IOWrite($hash, $r); + $v= ECMDDevice_PostProc($hash, $postproc, $v); + return ECMDDevice_Changed($hash, $cmdname, $v); } @@ -157,6 +184,7 @@ ECMDDevice_Set($@) my $ecmd= $IOhash->{fhem}{classDefs}{$classname}{sets}{$cmdname}{cmd}; my $params= $IOhash->{fhem}{classDefs}{$classname}{sets}{$cmdname}{params}; + my $postproc= $IOhash->{fhem}{classDefs}{$classname}{sets}{$cmdname}{postproc}; my %specials= ECMDDevice_DeviceParams2Specials($hash); # add specials for command @@ -175,7 +203,10 @@ ECMDDevice_Set($@) my $r = ECMDDevice_AnalyzeCommand($ecmd); my $v= IOWrite($hash, $r); - $v= join(" ", @a) if($params); + + $v= ECMDDevice_PostProc($hash, $postproc, $v); + +# $v= join(" ", @a) if($params); return ECMDDevice_Changed($hash, $cmdname, $v); diff --git a/fhem/docs/commandref.html b/fhem/docs/commandref.html index 9c2706336..d861810b7 100644 --- a/fhem/docs/commandref.html +++ b/fhem/docs/commandref.html @@ -4602,11 +4602,20 @@ Attributes:
  • - set <name> params <parameter1> [<parameter2> [<parameter3> ... ]]
    - get <name> params <parameter1> [<parameter2> [<parameter3> ... ]] + set <commandname> postproc { <perl command> }
    + get <commandname> postproc { <perl command> } +

    + Declares a postprocessor for the command <commandname>. +

    +
  • + + +
  • + set <commandname> params <parameter1> [<parameter2> [<parameter3> ... ]]
    + get <commandname> params <parameter1> [<parameter2> [<parameter3> ... ]]

    Declares the names of the named parameters that must be present in the - set or get command <name>. Be careful not to use a parameter name that + set or get command <commandname>. Be careful not to use a parameter name that is already used in the device definition (see params above).

  • @@ -4634,9 +4643,15 @@ Attributes:
  • If in doubt what happens, run the commands with loglevel 5 and observe the log file.
  • +

    - - + Neither apply the rules outlined in the documentation of perl specials + for the <perl command> in the postprocessor definitions nor can it contain macros. + This is to avoid undesired side effects from e.g. doubling of semicolons.

    + + The perl command acts on $_. The result of the perl command is the + final result of the get or set command. +

    ECMDDevice

    @@ -4731,7 +4746,7 @@ Attributes:
    Example 2

    -