From 345ae468ee13ce1e70c9b12933164191bf07a0aa Mon Sep 17 00:00:00 2001 From: joachim09876 Date: Thu, 27 Mar 2014 18:09:46 +0000 Subject: [PATCH] git-svn-id: svn://svn.code.sf.net/p/fhem/code/trunk@5341 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/98_cloneDummy.pm | 128 ++++++++++++++++++++++--------------- 1 file changed, 76 insertions(+), 52 deletions(-) diff --git a/fhem/FHEM/98_cloneDummy.pm b/fhem/FHEM/98_cloneDummy.pm index 83f86fd54..858666044 100644 --- a/fhem/FHEM/98_cloneDummy.pm +++ b/fhem/FHEM/98_cloneDummy.pm @@ -1,7 +1,7 @@ # $Id$ ############################################## # 98_cloneDummy -# +# Von Joachim Herold # FHEM Modul um aus Events von FHEM2FHEM clone-Devices zu erstellen # cloneDummy ist "readonly" # Grundlage ist 98_dummy.pm von Rudolf Koenig @@ -10,8 +10,8 @@ # Um die Änderung zu nutzen, einfach einen cloneDummy anlegen # # Eintrag in der fhem.cfg: -# define cloneDummy -# +# define cloneDummy [reading] +# attr cloneIgnore # ############################################# @@ -25,16 +25,18 @@ sub cloneDummy_Initialize($) { $hash->{DefFn} = "cloneDummy_Define"; $hash->{NotifyFn} = "cloneDummy_Notify"; - $hash->{AttrList} = $readingFnAttributes; + $hash->{AttrList} = "cloneIgnore ".$readingFnAttributes; } sub cloneDummy_Define($$) { my ($hash, $def) = @_; my @a = split("[ \t][ \t]*", $def); - return "Wrong syntax: use define cloneDummy " if((int(@a) != 3)) ; - return "Wrong syntax: must different to " if($a[0] eq $a[2]) ; - + return "Wrong syntax: use define cloneDummy [reading]" if((int(@a) < 3 || int(@a) > 4)) ; + return "Error: cloneDummy and sourceDevice must not have the same name!" if($a[0] eq $a[2]); + my $hn = $hash->{NAME}; $hash->{NOTIFYDEV} = $a[2]; + $hash->{NOTIFYSTATE} = $a[3] if(defined($a[3])); + $attr{$hn}{stateFormat} = "_state" if(defined($a[3])); readingsSingleUpdate($hash,'state','defined',1); Log3($hash,4,"cloneDummy: $a[0] defined for source $a[2]"); return undef; @@ -43,17 +45,26 @@ sub cloneDummy_Define($$) { sub cloneDummy_Notify($$) { my ($hash, $dev) = @_; my $dn = $dev->{NAME}; - my $hn = $hash->{NAME}; + my $hn = $hash->{NAME}; + my $hs = ""; + if(defined($hash->{NOTIFYSTATE})) { + $hs = $hash->{NOTIFYSTATE}; + } my $reading = $dev->{CHANGED}[0]; $reading = "" if(!defined($reading)); - Log3($hash,3, "cloneDummy: $hn D: $dn R: $reading"); - + Log3($hash,4, "cloneDummy: $hash D: $dn R: $reading"); my ($rname,$rval) = split(/ /,$reading,2); $rname = substr($rname,0,length($rname)-1); + my %check = map { $_ => 1 } split(/,/,AttrVal($hn,'cloneIgnore','')); readingsBeginUpdate($hash); - readingsBulkUpdate($hash, $rname, $rval); - readingsBulkUpdate($hash,'state','active'); + if (($hs ne "") && ($rname eq $hs) ){ + readingsBulkUpdate($hash,"_state", $reading); + } + readingsBulkUpdate($hash,"state", "active"); + unless (exists ($check{$rname})) { + readingsBulkUpdate($hash, $rname, $rval); + } readingsEndUpdate($hash, 1); return; @@ -67,37 +78,45 @@ sub cloneDummy_Notify($$) {

cloneDummy

    + This module provides a cloneDummy which will receive readings from any other device sending data to fhem.
    + E.g. may be used in an FHEM2FHEM environment
    +
    - Defines a clone of a device or transferred by FHEM2FHEM in log mode devices and is taking its readings. - It makes sense to call remote FHEM installations involve reading , testing or programming. -

    + + Define +
      + define <cloneDevice> cloneDummy <sourceDevice> [reading] +
      +
      + Example:
      +
      +
        define clone_OWX_26_09FF26010000 cloneDummy OWX_26_09FF26010000
      +
      + Optional parameter [reading] will be written to STATE if provided.
      +
      + Example:
      +
      +
        define clone_OWX_26_09FF26010000 cloneDummy OWX_26_09FF26010000 temperature
      +
    +
    - - Define -
      - define <name> cloneDummy <sourcedevice> -

      + + Set
        N/A
      +
      - Example: -
        - define clone_OWX_26_09FF26010000 cloneDummy OWX_26_09FF26010000
        -
      -
    -
    - - - Set
      N/A

    - - - Get
      N/A

    - - - Attributes - -
    + + Get
      N/A
    +
    + + Attributes +
      +
    • readingFnAttributes
    • +
    • cloneIgnore - comma separated list of readingnames that will NOT be generated.
      + Usefull to prevent truncated readingnames coming from state events.
    • +
    +
    + Important: You MUST use different names for cloneDevice and sourceDevice!
=end html @@ -107,34 +126,39 @@ sub cloneDummy_Notify($$) {

cloneDummy

    - - Definiert einen Clon eines Devices oder von FHEM2FHEM im Logmodus uebergebenen Devices und uebernimmt dessen Readings. - Sinnvoll um entfernte FHEM-Installationen lesend einzubinden,zum Testen oder Programmieren. + Definiert einen Clon eines Devices oder von FHEM2FHEM im Logmodus uebergebenen Devices und uebernimmt dessen Readings. + Sinnvoll um entfernte FHEM-Installationen lesend einzubinden, zum Testen oder Programmieren.

    Define
      - define <name> cloneDummy <Quelldevice> + define <name> cloneDummy <Quelldevice> [reading]

      - - Example: -
        - define clone_OWX_26_09FF26010000 cloneDummy OWX_26_09FF26010000
        -
      + Aktiviert den cloneDummy, der dann an das Device <Quelldevice> gebunden ist. Mit dem optionalen Parameter reading + wird bestimmt, welches reading im STATE angezeigt wird, stateFormat ist auch weiterhin möglich. +
        + Beispiel: Der cloneDummy wird lesend an den Sensor OWX_26_09FF26010000 gebunden und zeigt im State temperature an. +
      + +
        + define Feuchte cloneDummy OWX_26_09FF26010000 temperature
        +

    - + Set
      N/A

    - + Get
      N/A

    - + Attributes
      - +
    • clonIgnore
      + Eine durch Kommata getrennte Liste der readings, die cloneDummy nicht in eigene readings umwandelt +

    • readingFnAttributes