From 8495792683543b1a116248f9f090d4430c0ae1d9 Mon Sep 17 00:00:00 2001 From: jamesgo <> Date: Tue, 15 Sep 2015 13:14:52 +0000 Subject: [PATCH] =?UTF-8?q?98=5FGAEBUS.pm:=20Unterst=C3=BCtzung=20f=C3=BCr?= =?UTF-8?q?=20den=20Parameter=20"[FIELD[.N]]"=20von=20ebusd=20hinzugef?= =?UTF-8?q?=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.fhem.de/fhem/trunk@9255 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/contrib/98_GAEBUS.pm | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/fhem/contrib/98_GAEBUS.pm b/fhem/contrib/98_GAEBUS.pm index e31d4a916..4b373d16e 100644 --- a/fhem/contrib/98_GAEBUS.pm +++ b/fhem/contrib/98_GAEBUS.pm @@ -12,6 +12,7 @@ # 11.09.2015 : A.Goebel : add set command to write to ebusd # 13.09.2015 : A.Goebel : increase timeout for reads from ebusd from 1.8 to 5.0 # 14.09.2015 : A.Goebel : use utf-8 coding to display values from ".csv" files +# 14.09.2015 : A.Goebel : add optional parameter [FIELD[.N]] of read from ebusd to reading name package main; @@ -30,7 +31,7 @@ sub GAEBUS_SimpleWrite(@); sub GAEBUS_Disconnected($); sub GAEBUS_Shutdown($); -sub GAEBUS_doEbusCmd($$$$$); +sub GAEBUS_doEbusCmd($$$$$$); sub GAEBUS_GetUpdates($); my %gets = ( # Name, Data to send to the GAEBUS, Regexp for the answer @@ -229,6 +230,7 @@ GAEBUS_Set($@) { my $readingname = $attr{$name}{$oneattr}; my $readingcmdname = $oneattr; + $readingname =~ s/ .*//; $readingname =~ s/:.*//; # only for "w" commands @@ -276,7 +278,7 @@ GAEBUS_Set($@) my $readingname = $attr{$name}{$oneattr}; next if ($readingname ne $type); - my $answer = GAEBUS_doEbusCmd ($hash, "w", $readingname, $oneattr, $arg); + my $answer = GAEBUS_doEbusCmd ($hash, "w", $readingname, $oneattr, $arg, ""); return "$answer"; } } @@ -316,11 +318,20 @@ GAEBUS_Get($@) # extend possible parameters by the readings defined in attributes my %readings = (); + my %readingsCmdaddon = (); my $actGetParams .= "$allGetParams reading:"; foreach my $oneattr (sort keys %{$attr{$name}}) { - my $readingname = $attr{$name}{$oneattr}; + my ($readingnameX, $cmdaddon) = split (" ", $attr{$name}{$oneattr}, 2); + $cmdaddon = "" unless (defined ($cmdaddon)); + + my ($readingname, $doCntNo) = split (":", $readingnameX, 2); # split name from cycle number + $doCntNo = 1 unless (defined ($doCntNo)); +Log3 ($name, 2, "$name <$readingnameX>"); + + #my $readingname = $attr{$name}{$oneattr}; my $readingcmdname = $oneattr; + $readingname =~ s/ .*//; $readingname =~ s/:.*//; # only for "r" commands @@ -329,6 +340,8 @@ GAEBUS_Get($@) unless ($readingname =~ /^\s*$/ or $readingname eq "1") { $readings{$readingname} = $readingcmdname; + $readingsCmdaddon{$readingname} = $cmdaddon; + #Log3 ($name, 2, "$name GetParams $readingname"); } } @@ -345,11 +358,12 @@ GAEBUS_Get($@) { my $readingname = $a[2]; my $readingcmdname = $readings{$readingname}; + my $cmdaddon = $readingsCmdaddon{$readingname}; Log3 ($name, 4, "$name Get name $readingname"); Log3 ($name, 4, "$name Get cmd r $readingcmdname"); - my $answer = GAEBUS_doEbusCmd ($hash, "r", $readingname, $readingcmdname, ""); + my $answer = GAEBUS_doEbusCmd ($hash, "r", $readingname, $readingcmdname, "", $cmdaddon); #return (defined($answer ? $answer : "")); return "$answer"; @@ -365,7 +379,7 @@ GAEBUS_Get($@) Log3 ($name, 3, "$name get cmd v $readingcmdname"); - my $answer = GAEBUS_doEbusCmd ($hash, "v", $readingname, $readingcmdname, ""); + my $answer = GAEBUS_doEbusCmd ($hash, "v", $readingname, $readingcmdname, "", ""); #return (defined($answer ? $answer : "")); return "$answer"; @@ -555,6 +569,7 @@ GAEBUS_Attr(@) if ($attrname =~ /^.*$delimiter/) { my $reading = $attr{$name}{$attrname}; + $reading =~ s/ .*//; $reading =~ s/:.*//; Log3 ($name, 3, "$name: delete reading: $reading"); @@ -569,8 +584,10 @@ GAEBUS_Attr(@) if (defined $attr{$name}{$attrname}) { my $oldreading = $attr{$name}{$attrname}; + $oldreading =~ s/ .*//; $oldreading =~ s/:.*//; my $newreading = $attrval; + $newreading =~ s/ .*//; $newreading =~ s/:.*//; if ($oldreading ne $newreading) @@ -743,13 +760,14 @@ GAEBUS_ReadCSV($) } sub -GAEBUS_doEbusCmd($$$$$) +GAEBUS_doEbusCmd($$$$$$) { my $hash = shift; my $action = shift; # "r" = set reading, "v" = verbose mode, "w" = write to ebus my $readingname = shift; my $readingcmdname = shift; my $writeValues = shift; + my $cmdaddon = shift; my $actMessage; my $name = $hash->{NAME}; @@ -782,6 +800,7 @@ GAEBUS_doEbusCmd($$$$$) $cmd = "$io -f "; $cmd .= "-v " if ($action eq "v"); $cmd .= "-c $class $var"; + $cmd .= " $cmdaddon" if ($action eq "r"); } Log3 ($name, 3, "$name execute $cmd"); @@ -847,7 +866,10 @@ GAEBUS_GetUpdates($) if ($oneattr =~ /^r.*$delimiter.*$delimiter.*$delimiter.*$/) { - my ($readingname, $doCntNo) = split (":", $attr{$name}{$oneattr}, 2); # split name from cycle number + my ($readingnameX, $cmdaddon) = split (" ", $attr{$name}{$oneattr}, 2); + $cmdaddon = "" unless (defined ($cmdaddon)); + + my ($readingname, $doCntNo) = split (":", $readingnameX, 2); # split name from cycle number $doCntNo = 1 unless (defined ($doCntNo)); Log3 ($name, 5, "$name GetUpdates: $readingname:$doCntNo"); @@ -858,7 +880,7 @@ GAEBUS_GetUpdates($) #Log3 ($name, 2, "$name check modulo ".$hash->{UpdateCnt}." mod $doCntNo -> ".($hash->{UpdateCnt} % $doCntNo)); if (($hash->{UpdateCnt} % $doCntNo) == 0) { - my $answer = GAEBUS_doEbusCmd ($hash, "r", $readingname, $oneattr, ""); + my $answer = GAEBUS_doEbusCmd ($hash, "r", $readingname, $oneattr, "", $cmdaddon); } # limit number of reopens if ebusd cannot be reached