diff --git a/fhem/FHEM/12_HProtocolGateway.pm b/fhem/FHEM/12_HProtocolGateway.pm index d0491207b..2ddaeea88 100644 --- a/fhem/FHEM/12_HProtocolGateway.pm +++ b/fhem/FHEM/12_HProtocolGateway.pm @@ -48,9 +48,8 @@ sub HProtocolGateway_Initialize($) { "baudrate:300,600,1200,2400,4800,9600 " . "parityBit:N,E,O " . "databitsLength:5,6,7,8 " . - "stopBit " . + "stopBit:0,1" . "pollIntervalMins " . - "mode:Filllevel,Volume,Ullage " . "path"; } @@ -108,10 +107,11 @@ sub HProtocolGateway_GetUpdate($) { foreach (@tankList) { my $tankHash = $_; + my $mode = AttrVal($tankHash->{NAME},"mode",""); my $command = "\$A"; - if ($attr{$name}{mode} eq "Volume") { + if ($mode eq "Volume") { $command = "\$B"; - } elsif ($attr{$name}{mode} eq "Ullage") { + } elsif ($mode eq "Ullage") { $command = "\$C"; } @@ -200,13 +200,14 @@ sub HProtocolGateway_ParseMessage($$) { return if($check ne $checksum); my ($filllevel,$volume,$ullage) = (0,0,0); + my $mode = AttrVal($tankHash->{NAME},"mode",""); - if ($attr{$name}{mode} eq "Filllevel") { + if ($mode eq "Filllevel") { $filllevel = $tankdata; $volume = HProtocolGateway_Tank($hash,$tankHash,$filllevel); - } elsif ($attr{$name}{mode} eq "Volume") { + } elsif ($mode eq "Volume") { $volume = $tankdata; - } elsif ($attr{$name}{mode} eq "Ullage") { + } elsif ($mode eq "Ullage") { $ullage = $tankdata; } @@ -305,8 +306,6 @@ sub HProtocolGateway_Attr (@) { } else { RemoveInternalTimer($hash); } - } elsif ($attr eq 'mode') { - $attr{$name}{mode} = $val; } elsif ($attr eq 'path') { $attr{$name}{path} = $val; } elsif ($attr eq 'baudrate') { @@ -351,9 +350,11 @@ sub HProtocolGateway_Poll($) { sub HProtocolGateway_Tank($$$) { my ($hash,$tankHash,$filllevel) = @_; my $name = $hash->{NAME}; + my $path = AttrVal($name,"path",""); + my $type = AttrVal($tankHash->{NAME},"type",""); my %TankChartHash; - open my $fh, '<', $attr{$name}{path}.'tank'.$tankHash->{READINGS}{hID}{VAL}.'.csv' or die "Cannot open: $!"; + open my $fh, '<', $path.$type or die "Cannot open: $!"; while (my $line = <$fh>) { $line =~ s/\s*\z//; my @array = split /,/, $line; @@ -393,7 +394,6 @@ sub HProtocolGateway_Tank($$$) {

diff --git a/fhem/FHEM/12_HProtocolTank.pm b/fhem/FHEM/12_HProtocolTank.pm index 8ccdebad8..b3aa6962c 100644 --- a/fhem/FHEM/12_HProtocolTank.pm +++ b/fhem/FHEM/12_HProtocolTank.pm @@ -31,8 +31,11 @@ sub HProtocolTank_Initialize($) { $hash->{DefFn} = "HProtocolTank_Define"; $hash->{ParseFn} = "HProtocolTank_Parse"; $hash->{FingerprintFn} = "HProtocolTank_Fingerprint"; + $hash->{AttrFn} = "HProtocolGateway_Attr"; $hash->{Match} = "^[a-zA-Z0-9_]+ [a-zA-Z0-9_]+ [+-]*[0-9]+([.][0-9]+)?"; - $hash->{AttrList} = $readingFnAttributes; + $hash->{AttrList} = "mode:Filllevel,Volume,Ullage " . + "type " . + $readingFnAttributes; } sub HProtocolTank_Define($$) { @@ -92,6 +95,18 @@ sub HProtocolTank_Fingerprint($$) { # this message is a duplicate message. Refer to FHEM Wiki. } +sub HProtocolTank_Attr (@) { + my ($command, $name, $attr, $val) = @_; + my $hash = $defs{$name}; + my $msg = ''; + + if ($attr eq 'type') { + $attr{$name}{type} = $val; + } elsif ($attr eq 'mode') { + $attr{$name}{mode} = $val; + } +} + 1; @@ -122,7 +137,7 @@ sub HProtocolTank_Fingerprint($$) { Readings
+ + Attributes +
+