From c7a8b7927ee860a9bd8f5bcc797b19748bf16f3a Mon Sep 17 00:00:00 2001 From: markusbloch Date: Mon, 14 Jul 2014 20:58:50 +0000 Subject: [PATCH] PRESENCE: using AnalyzeCommandChain for new "power" set command instead of perl eval git-svn-id: svn://svn.code.sf.net/p/fhem/code/trunk@6255 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 4 +-- fhem/FHEM/73_PRESENCE.pm | 64 ++++++++++++++++++++++++---------------- 2 files changed, 40 insertions(+), 28 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 8cdece604..bdf91c5eb 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -2,8 +2,8 @@ # Do not insert empty lines here, update check depends on it. - feature: mailcheck: allow user and pssword as perl expression - feature: netatmo: support for public stations - - feature: PRESENCE: new set command "powerOn" to execute a Perl function - which power on the checked device (given via attribute) + - feature: PRESENCE: new set command "power" to execute a FHEM command + which can power on or off the checked device (given via attribute) - feature: readingsGroup: added valueColumn attribute - feature: readingsGroup: added ...,@,... argument format - feature: 52_I2C_PCF8574.pm: added attribute OnStartup diff --git a/fhem/FHEM/73_PRESENCE.pm b/fhem/FHEM/73_PRESENCE.pm index c4701f5a9..1fda641ef 100755 --- a/fhem/FHEM/73_PRESENCE.pm +++ b/fhem/FHEM/73_PRESENCE.pm @@ -51,7 +51,7 @@ PRESENCE_Initialize($) $hash->{DefFn} = "PRESENCE_Define"; $hash->{UndefFn} = "PRESENCE_Undef"; $hash->{AttrFn} = "PRESENCE_Attr"; - $hash->{AttrList}= "do_not_notify:0,1 disable:0,1 fritzbox_repeater:0,1 ping_count:1,2,3,4,5,6,7,8,9,10 powerOnFn ".$readingFnAttributes; + $hash->{AttrList}= "do_not_notify:0,1 disable:0,1 fritzbox_repeater:0,1 ping_count:1,2,3,4,5,6,7,8,9,10 powerCmd ".$readingFnAttributes; } @@ -260,8 +260,8 @@ PRESENCE_Set($@) my $usage = "Unknown argument ".$a[1].", choose one of statusRequest"; - my $powerOnFn = AttrVal($name, "powerOnFn", undef); - $usage .= " powerOn" if(defined($powerOnFn)); + my $powerCmd = AttrVal($name, "powerCmd", undef); + $usage .= " power" if(defined($powerCmd)); if($a[1] eq "statusRequest") { @@ -283,7 +283,7 @@ PRESENCE_Set($@) } } } - elsif(defined($powerOnFn) && $a[1] eq "powerOn") + elsif(defined($powerCmd) && $a[1] eq "power") { my %specials= ( "%NAME" => $name, @@ -291,20 +291,20 @@ PRESENCE_Set($@) "%ARGUMENT" => $a[2] ); - $powerOnFn= EvalSpecials($powerOnFn, %specials); + $powerCmd= EvalSpecials($powerCmd, %specials); - Log3 $name, 5, "PRESENCE ($name) - executing powerOnFn: $powerOnFn"; - eval $powerOnFn; + Log3 $name, 5, "PRESENCE ($name) - executing powerCmd: $powerCmd"; + my $return = AnalyzeCommandChain(undef, $powerCmd); - if($@) + if($return) { - Log3 $name, 3, "PRESENCE ($name) - executed powerOnFn failed: ".$@; - readingsSingleUpdate($hash, "powerOnFn", "failed",1); - return "executed powerOnFn failed: ".$@; + Log3 $name, 3, "PRESENCE ($name) - executed powerCmd failed: ".$return; + readingsSingleUpdate($hash, "powerCmd", "failed",1); + return "executed powerCmd failed: ".$return; } else { - readingsSingleUpdate($hash, "powerOnFn", "executed",1); + readingsSingleUpdate($hash, "powerCmd", "executed",1); } return undef; @@ -1133,7 +1133,7 @@ Options: Set
  • statusRequest - Schedules an immediatly check.
  • -
  • powerOn - Executes the given power on function set as attribute to power on the device (only when attribute "powerOnFn" is set)
  • +
  • power - Executes the given power command which is set as attribute to power (on or off) the device (only when attribute "powerCmd" is set)

@@ -1165,18 +1165,24 @@ Options: Possible values: 0 => Use default recognition, 1 => Use repeater-supported recognition
Default Value is 0 (Use default recognition)

-
  • powerOnFn

  • - Define a Perl statement, which powers on the device.

    +
  • powerCmd

  • + Define a FHEM command, which powers on or off the device.

    - When executing the powerOnFn (set command: powerOn) following placeholders will be replaced by there corresponding values:

    + When executing the powerCmd (set command: power) following placeholders will be replaced by there corresponding values:

    • %NAME - name of the PRESENCE definition
    • %ADDRESS - the address of the PRESENCE definition as given in the define statement
    • -
    • %ARGUMENT - the argument given to the powerOn set command
    • +
    • %ARGUMENT - the argument given to the power set command (e.g. "on" or "off)

    - Example: powerOn("%ADDRESS", "username", "password") + Example FHEM commands:

    +
      +
    • set PowerSwitch_1 on
    • +
    • set PowerSwitch_1 %ARGUMENT
    • +
    • "/opt/power_on.sh %ADDRESS"
    • +
    • {powerOn("%ADDRESS", "username", "password")}
    +
    @@ -1185,7 +1191,7 @@ Options: General Events:

    • state: $state (absent|present|disabled) - The state of the device or "disabled" when the disable attribute is enabled
    • -
    • powerOnFn: (executed|failed) - powerOn was executed or has failed
    • +
    • powerCmd: (executed|failed) - power command was executed or has failed


    Bluetooth specific events:

      @@ -1372,7 +1378,7 @@ Options:
      • statusRequest - Startet einen sofortigen Check.
      • -
      • powerOn - Startet die powerOn-Funktion welche durch den Parameter powerOnFn angegeben ist (Nur wenn das Attribut "powerOnFn" definiert ist)
      • +
      • power - Startet den powerCmd-Befehl welche durch den Parameter powerCmd angegeben ist (Nur wenn das Attribut "powerCmd" definiert ist)

      @@ -1407,17 +1413,23 @@ Options: Standardwert ist 0 (Standarderkennung verwenden)

      -
    • powerOnFn

    • - Eine Perlfunktion oder -ausdruck, welcher das Gerät einschaltet.

      +
    • powerCmd

    • + Ein FHEM-Befehl, welcher das Gerät schalten kann.

      - Wenn die powerOn-Funktion ausgeführt wird (set-Befehl: powerOn) werden folgende Platzhalter durch ihre entsprechenden Werte ersetzt:

      + Wenn der power-Befehl ausgeführt wird (set-Befehl: power) werden folgende Platzhalter durch ihre entsprechenden Werte ersetzt:

      • %NAME - Name der PRESENCE-Definition
      • %ADDRESS - Die überwachte Addresse der PRESENCE Definition, wie sie im define-Befehl angegeben wurde.
      • -
      • %ARGUMENT - Das Argument, was dem Set-Befehl "powerOn" übergeben wurde.
      • +
      • %ARGUMENT - Das Argument, was dem Set-Befehl "power" übergeben wurde. (z.B. "on" oder "off")

      - Beispiel: powerOn("%ADDRESS", "username", "passwort") + Beispielhafte FHEM-Befehle:

      +
        +
      • set PowerSwitch_1 on
      • +
      • set PowerSwitch_1 %ARGUMENT
      • +
      • "/opt/power_on.sh %ADDRESS"
      • +
      • {powerOn("%ADDRESS", "username", "password")}
      • +

    @@ -1427,7 +1439,7 @@ Options: Generelle Events:

    • state: $state (absent|present|disabled) - Der Anwesenheitsstatus eine Gerätes (absent = abwesend; present = anwesend) oder "disabled" wenn das disable-Attribut aktiviert ist
    • -
    • powerOnFn: (executed|failed) - Ausführung des powerOn-Befehls war erfolgreich.
    • +
    • powerCmd: (executed|failed) - Ausführung des power-Befehls war erfolgreich.


    Bluetooth-spezifische Events: