From 33fdfa16534ca55778a8d9564ab9296ada30b808 Mon Sep 17 00:00:00 2001 From: fhemzap Date: Thu, 17 Dec 2015 13:15:22 +0000 Subject: [PATCH] HMCCU: bug fixes and formatting of STATE git-svn-id: https://svn.fhem.de/fhem/trunk@10191 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/contrib/HMCCU/88_HMCCU.pm | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/fhem/contrib/HMCCU/88_HMCCU.pm b/fhem/contrib/HMCCU/88_HMCCU.pm index 0b340ccf9..25e72d0db 100644 --- a/fhem/contrib/HMCCU/88_HMCCU.pm +++ b/fhem/contrib/HMCCU/88_HMCCU.pm @@ -128,6 +128,7 @@ sub HMCCU_SetVariable ($$$); sub HMCCU_GetChannel ($$); sub HMCCU_RPCGetConfig ($$$); sub HMCCU_RPCSetConfig ($$$); +sub HMCCU_State ($); ##################################### @@ -1007,7 +1008,7 @@ sub HMCCU_CheckProcess ($) { my ($hash) = @_; - my $pdump = `ps -ef | grep ccurpcd | grep -v grep`; + my $pdump = `ps -ef | grep ccurpcd\.pl | grep -v grep`; my @plist = split "\n", $pdump; foreach my $proc (@plist) { @@ -1837,6 +1838,33 @@ sub HMCCU_RPCSetConfig ($$$) return 0; } +#################################################### +# Return string for internal STATE. This function +# can be used in attribute stateFormat. +#################################################### + +sub HMCCU_State ($) +{ + my ($name) = @_; + + my $hash = $defs{$name}; + my $sf = AttrVal ($name, 'ccustate', ''); + + return ReadingsVal ($name, 'state', '') if ($sf eq ''); + + my $st = $sf; + my $r = $hash->{READINGS}; + + if ($r->{state}{VAL} ne "Error") { + $st =~ s/\b([A-Za-z\d_\.\:-]+)\b/($r->{$1} ? $r->{$1}{VAL} : $1)/ge; + } + else { + $st = "Error"; + } + + return $st; +} + 1;