From d5669e402a71b5412717551a7cbd5d1cf25c3545 Mon Sep 17 00:00:00 2001 From: jamesgo <> Date: Fri, 7 Feb 2020 07:42:19 +0000 Subject: [PATCH] 98_GAEBUS.pm : substitute tilde as delimiter in attribute names by underscore git-svn-id: https://svn.fhem.de/fhem/trunk@21134 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/98_GAEBUS.pm | 77 +++++++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 28 deletions(-) diff --git a/fhem/FHEM/98_GAEBUS.pm b/fhem/FHEM/98_GAEBUS.pm index ae0062c3f..98d5a1104 100644 --- a/fhem/FHEM/98_GAEBUS.pm +++ b/fhem/FHEM/98_GAEBUS.pm @@ -53,6 +53,7 @@ # 09.01.2020 : A.Goebel : fix to skip readings named "dummy" # 09.01.2020 : A.Goebel : fix handling for valueFormat, give exact number of parameters to sprintf and shift all of them # 16.01.2020 : A.Goebel : add ignore error messages returned by ebusd +# 05.02.2020 : A.Goebel : change substitute tilde by slash in attribute names (delimiter) package main; @@ -94,7 +95,7 @@ my $allSetParams = ""; my $allSetParamsForWriting = ""; my $allGetParams = ""; my $allGetParamsForWriting = ""; -my $delimiter = "~"; +my $delimiter = "_"; my $attrsDefault = "do_not_notify:1,0 disable:1,0 dummy:1,0 showtime:1,0 loglevel:0,1,2,3,4,5,6 ebusWritesEnabled:0,1 valueFormat:textField-long $readingFnAttributes"; my %ebusCmd = (); @@ -267,8 +268,8 @@ GAEBUS_Set($@) my $type = shift @a; my $arg = join(" ", @a); - $type =~ s/\xe2\x88\xbc/~/g; - $arg =~ s/\xe2\x88\xbc/~/g; + $type =~ s,\xe2\x88\xbc,$delimiter,g; + $arg =~ s,\xe2\x88\xbc,$delimiter,g; #return "No $a[1] for dummies" if(IsDummy($name)); @@ -398,7 +399,7 @@ GAEBUS_Set($@) } - $actSetParams =~ s/~/∼/g; + #$actSetParams =~ s,$delimiter,∼,g; return "Unknown argument $type, choose one of " . $actSetParams if(!defined($sets{$type})); @@ -546,8 +547,8 @@ GAEBUS_Get($@) # other read commands - if (defined($a[1])) { $a[1] =~ s/\xe2\x88\xbc/~/g }; - if (defined($a[2])) { $a[2] =~ s/\xe2\x88\xbc/~/g }; + if (defined($a[1])) { $a[1] =~ s,\xe2\x88\xbc,$delimiter,g }; + if (defined($a[2])) { $a[2] =~ s,\xe2\x88\xbc,$delimiter,g }; if ($a[1] =~ /^[ru]$delimiter/ ) { @@ -565,7 +566,7 @@ GAEBUS_Get($@) # handle commands from %gets and show result from ebusd - $actGetParams =~ s/~/∼/g; + #$actGetParams =~ s,$delimiter,∼,g; return "Unknown argument $a[1], choose one of " . $actGetParams if(!defined($gets{$a[1]})); @@ -721,7 +722,7 @@ GAEBUS_Attr(@) { #Log3 ($hash, 2, "match"); # " a" or "^a$" - $userattr =~ s/ *$attrname//; + $userattr =~ s, *$attrname,,; if ($userattr eq "") { delete($attr{$name}{userattr}); @@ -737,8 +738,8 @@ GAEBUS_Attr(@) if ($attrname =~ /^.*$delimiter/) { my $reading = $attr{$name}{$attrname}; - $reading =~ s/ .*//; - $reading =~ s/:.*//; + $reading =~ s, .*,,; + $reading =~ s,:.*,,; foreach my $r (split /;/, $reading) { Log3 ($name, 3, "$name: delete reading: $r"); @@ -777,6 +778,25 @@ GAEBUS_Attr(@) return undef; } + if ($attrname =~ /~/) { + # migration process after restart (processing statements from fhem.cfg) + # migrate attribute names containing tilde as delimiter to $delimiter + # migrate values from tilde as delimiter to $delimiter + # modify userattr to contain the new attribute name + + my $oattrname = $attrname; + $attrval =~ s,~,$delimiter,g; + $attrname =~ s,~,$delimiter,g; + Log3 ($hash, 2, ">$oattrname<>$attrname<>$attrval<"); + + # adjust userattr + $attr{$name}{userattr} =~ s,$oattrname,$attrname,; + + # set attribute with modified name and return an error + $attr{$name}{$attrname} = $attrval; + return "attribute containing invalid char migrated to $attrname ($attrval)"; + } + if ( " $userattr " =~ / $attrname / ) { # this is an attribute form "userattr" @@ -795,16 +815,16 @@ GAEBUS_Attr(@) if (defined $attr{$name}{$attrname}) { my $oldreading = $attr{$name}{$attrname}; - $oldreading =~ s/ .*//; - $oldreading =~ s/:.*//; + $oldreading =~ s, .*,,; + $oldreading =~ s,:.*,,; my $newreading = $attrval; - $newreading =~ s/ .*//; - $newreading =~ s/:.*//; + $newreading =~ s, .*,,; + $newreading =~ s,:.*,,; my @or = split /;/, $oldreading; my @nr = split /;/, $newreading; - for (my $i; $i <= $#or; $i++) + for (my $i=0; $i <= $#or; $i++) { if ($or[$i] ne $nr[$i]) { @@ -1019,6 +1039,7 @@ GAEBUS_doEbusCmd($$$$$$$) if ($action eq "f") { + #Log3 ($name, 3, "$name find process answer."); %sets = ( "reopen" => [] ); %gets = ( "ebusd_find" => [], "ebusd_info" => [] ); @@ -1029,10 +1050,10 @@ GAEBUS_doEbusCmd($$$$$$$) foreach my $line (split /\n/, $actMessage) { $cnt++; - $line =~ s/ /_/g; # no blanks in names and comments - $line =~ s/$delimiter/_/g; # clean up the delimiter within the text + $line =~ s/ /./g; # no blanks in names and comments + $line =~ s,$delimiter,.,g; # clean up the delimiter within the text - Log3 ($name, 4, "$name $line"); + #Log3 ($name, 5, "$name $line"); #my ($io,$class,$var) = split (",", $line, 3); my ($io, $class, $var, $comment, @params) = split (",", $line, 5); @@ -1354,16 +1375,16 @@ GAEBUS_valueFormat(@)
[r]~<class>~<variable-name>
[r]_<class>_<variable-name>
[w]~<class>~<variable-name>
[w]_<class>_<variable-name>