From 3b5a12c32aad9529bded8298ca5ba2e34ebf993b Mon Sep 17 00:00:00 2001 From: risiko79 <> Date: Tue, 5 Jan 2016 20:30:29 +0000 Subject: [PATCH] 98_weekprofile: detect profile changes in master device git-svn-id: https://svn.fhem.de/fhem/trunk@10374 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/98_weekprofile.pm | 58 ++++++++++++++++++++++++++++++------- 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index b080cfd17..450457361 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - feature: 98_weekprofile: detect profile changes in master device - feature: 49_SSCam: Function "Get" for retrieval Camera-Readings added, Attributs pollcaminfoall, pollnologging added, Function for Polling Cam-Infos added. diff --git a/fhem/FHEM/98_weekprofile.pm b/fhem/FHEM/98_weekprofile.pm index 24fbbd081..683055721 100644 --- a/fhem/FHEM/98_weekprofile.pm +++ b/fhem/FHEM/98_weekprofile.pm @@ -16,6 +16,7 @@ use vars qw(%defs); use vars qw($FW_ME); use vars qw($FW_wname); use vars qw($FW_subdir); +use vars qw($init_done); my @shortDays = ("Mon","Tue","Wed","Thu","Fri","Sat","Sun"); @@ -536,20 +537,55 @@ sub weekprofile_Notify($$) my $me = $own->{NAME}; # own name / hash my $devName = $dev->{NAME}; # Device that created the events - return undef if ($devName ne "global"); - my $max = int(@{$dev->{CHANGED}}); # number of events / changes - for (my $i = 0; $i < $max; $i++) { - my $s = $dev->{CHANGED}[$i]; + + if ($devName eq "global"){ + for (my $i = 0; $i < $max; $i++) { + my $s = $dev->{CHANGED}[$i]; + + next if(!defined($s)); + my ($what,$who) = split(' ',$s); + + if ($what =~ m/INITIALIZED/) { + splice($own->{PROFILES}); + weekprofile_assignDev($own); + weekprofile_readProfilesFromFile($own); + weekprofile_updateReadings($own); + } + } + } + + if ($init_done && defined($own->{MASTERDEV}->{NAME}) && + ($own->{MASTERDEV}->{NAME} eq $devName) && + (@{$own->{PROFILES}} > 0) ) { - next if(!defined($s)); - my ($what,$who) = split(' ',$s); + my $readprf=0; - if ($what =~ m/INITIALIZED/) { - splice($own->{PROFILES}); - weekprofile_assignDev($own); - weekprofile_readProfilesFromFile($own); - weekprofile_updateReadings($own); + for (my $i = 0; $i < $max; $i++) { + my $s = $dev->{CHANGED}[$i]; + + next if(!defined($s)); + my ($what,$who) = split(' ',$s); + + Log3 $me, 5, "$me(Notify): $devName, $what"; + + if ($own->{MASTERDEV}->{NAME} eq 'MAX') { + $readprf =1 if ($what=~m/weekprofile/); #reading weekprofile + } else { + # toDo nur auf spezielle notify bei anderen typen reagieren!! + $readprf = 1; + } + + last if ($readprf); + } + + if ($readprf) { + Log3 $me, 4, "$me(Notify): reread master profile from $devName"; + my $prfDev = weekprofile_readDevProfile($own->{MASTERDEV}->{NAME},$own->{MASTERDEV}->{TYPE}, $me); + if(defined($prfDev)) { + $own->{PROFILES}[0]->{DATA} = $prfDev; + weekprofile_updateReadings($own); + } } } return undef;