From d0303acb811666b9b36c33900b6638d7415a09c5 Mon Sep 17 00:00:00 2001 From: rudolfkoenig Date: Wed, 31 Jul 2013 18:33:57 +0000 Subject: [PATCH] structure changes by Tobias (http://forum.fhem.de/index.php?t=msg&goto=88049) git-svn-id: svn://svn.code.sf.net/p/fhem/code/trunk@3562 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/98_structure.pm | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/fhem/FHEM/98_structure.pm b/fhem/FHEM/98_structure.pm index 5037a39b6..00b48852d 100755 --- a/fhem/FHEM/98_structure.pm +++ b/fhem/FHEM/98_structure.pm @@ -27,6 +27,8 @@ use strict; use warnings; #use Data::Dumper; +sub structure_getChangedDevice($); + ##################################### sub @@ -101,13 +103,29 @@ structure_Undef($$) # returns the unique keys of the given array # @my_array = ("one","two","three","two","three"); # print join(" ", @my_array), "\n"; -# print join(" ", uniq(@my_array)), "\n"; +# print join(" ", structure_uniq(@my_array)), "\n"; -sub uniq { - return keys %{{ map { $_ => 1 } @_ }}; +sub +structure_uniq +{ + return keys %{{ map { $_ => 1 } @_ }}; } +############################# +# returns the really changed Device +############################# + +sub +structure_getChangedDevice($) +{ + my ($dev) = @_; + my $lastDevice = ReadingsVal($dev, "LastDevice", undef); + $dev = structure_getChangedDevice($lastDevice) + if($lastDevice && $defs{$dev}->{TYPE} eq "structure"); + return $dev; +} + ############################# sub structure_Notify($$) { @@ -266,7 +284,7 @@ sub structure_Notify($$) last if($minprio == 1); } #foreach - @clientstate = uniq(@clientstate);# eleminiere alle Dubletten + @clientstate = structure_uniq(@clientstate);# eleminiere alle Dubletten #ermittle Endstatus my $newState = "undefined"; @@ -285,7 +303,11 @@ sub structure_Notify($$) Log GetLogLevel($me,5), "Update structure '$me' to $newState" . " because device $dev->{NAME} has changed"; - readingsSingleUpdate($hash, "state", $newState, 1); + readingsBeginUpdate($hash); + readingsBulkUpdate($hash, "LastDevice", $dev->{NAME}); + readingsBulkUpdate($hash, "LastDevice_Abs", structure_getChangedDevice($dev->{NAME})); + readingsBulkUpdate($hash, "state", $newState); + readingsEndUpdate($hash, 1); delete($hash->{INNTFY}); undef;