RESIDENTS: also send global notification after module has finished initialization

git-svn-id: https://svn.fhem.de/fhem/trunk@14064 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jpawlowski 2017-04-21 21:30:54 +00:00
parent 8c79cfbc45
commit 5ce53d7f0a
4 changed files with 45 additions and 19 deletions

View File

@ -18,7 +18,7 @@ sub RESIDENTS_Initialize($) {
$hash->{AttrFn} = "RESIDENTStk_Attr"; $hash->{AttrFn} = "RESIDENTStk_Attr";
$hash->{NotifyFn} = "RESIDENTStk_Notify"; $hash->{NotifyFn} = "RESIDENTStk_Notify";
$hash->{'.READY'} = 0; $hash->{READY} = 0;
$hash->{NotifyOrderPrefix} = "45-"; $hash->{NotifyOrderPrefix} = "45-";
$hash->{AttrList} = $hash->{AttrList} =
"disable:1,0 disabledForIntervals do_not_notify:1,0 " "disable:1,0 disabledForIntervals do_not_notify:1,0 "

View File

@ -19,7 +19,7 @@ sub GUEST_Initialize($) {
$hash->{AttrFn} = "RESIDENTStk_Attr"; $hash->{AttrFn} = "RESIDENTStk_Attr";
$hash->{NotifyFn} = "RESIDENTStk_Notify"; $hash->{NotifyFn} = "RESIDENTStk_Notify";
$hash->{'.READY'} = 0; $hash->{READY} = 0;
$hash->{NotifyOrderPrefix} = "35-"; $hash->{NotifyOrderPrefix} = "35-";
$hash->{AttrList} = $hash->{AttrList} =
"disable:1,0 disabledForIntervals do_not_notify:1,0 " "disable:1,0 disabledForIntervals do_not_notify:1,0 "

View File

@ -19,7 +19,7 @@ sub ROOMMATE_Initialize($) {
$hash->{AttrFn} = "RESIDENTStk_Attr"; $hash->{AttrFn} = "RESIDENTStk_Attr";
$hash->{NotifyFn} = "RESIDENTStk_Notify"; $hash->{NotifyFn} = "RESIDENTStk_Notify";
$hash->{'.READY'} = 0; $hash->{READY} = 0;
$hash->{NotifyOrderPrefix} = "40-"; $hash->{NotifyOrderPrefix} = "40-";
$hash->{AttrList} = $hash->{AttrList} =
"disable:1,0 disabledForIntervals do_not_notify:1,0 " "disable:1,0 disabledForIntervals do_not_notify:1,0 "

View File

@ -54,7 +54,8 @@ sub RESIDENTStk_Define($$) {
|| $a[2] =~ /^[A-Za-z\d._]+(?:,[A-Za-z\d._]*)*$/ ); || $a[2] =~ /^[A-Za-z\d._]+(?:,[A-Za-z\d._]*)*$/ );
$modules{$TYPE}{defptr}{$name} = \$hash; $modules{$TYPE}{defptr}{$name} = \$hash;
$hash->{NOTIFYDEV} = "global"; $hash->{'.READY'} = 0;
$hash->{NOTIFYDEV} = "global";
$hash->{RESIDENTGROUPS} = $a[2] if ( defined( $a[2] ) ); $hash->{RESIDENTGROUPS} = $a[2] if ( defined( $a[2] ) );
# set default settings on first define # set default settings on first define
@ -114,6 +115,7 @@ sub RESIDENTStk_Undefine($$) {
my ( $hash, $name ) = @_; my ( $hash, $name ) = @_;
RESIDENTStk_StopInternalTimers($hash); RESIDENTStk_StopInternalTimers($hash);
return undef unless ($init_done);
# update parent residents # update parent residents
if ( defined( $hash->{RESIDENTGROUPS} ) ) { if ( defined( $hash->{RESIDENTGROUPS} ) ) {
@ -1077,20 +1079,41 @@ sub RESIDENTStk_Notify($$) {
my $devType = GetType($devName); my $devType = GetType($devName);
if ( $devName eq "global" ) { if ( $devName eq "global" ) {
delete $dev->{CHANGEDWITHSTATE};
my $events = deviceEvents( $dev, 0 ); my $events = deviceEvents( $dev, 0 );
return "" unless ($events); return "" unless ($events);
foreach ( @{$events} ) { foreach ( @{$events} ) {
# module internal notifications
if ( $_ =~ m/^$TYPE(?:\s+(.*))?$/ ) {
# internal init completed by all defined devices
if ( $1 && $1 eq "INITIALIZED" && !$hash->{'.READY'} ) {
$hash->{'.READY'} = 1;
DoTrigger( "global", "INITIALIZED $name", 1 );
}
}
# init RESIDENTS, ROOMMATE or GUEST devices after boot # init RESIDENTS, ROOMMATE or GUEST devices after boot
if ( $_ =~ elsif ( $_ =~
m/^(INITIALIZED|REREADCFG|DEFINED|MODIFIED|RENAMED|DELETED)(?:\s+(.*))?$/ m/^(INITIALIZED|REREADCFG|DEFINED|MODIFIED|RENAMED|DELETED)(?:\s+(.*))?$/
) )
{ {
RESIDENTStk_findResidentSlaves($hash) next if ( $1 eq "INITIALIZED" && $2 );
if ( $TYPE eq "RESIDENTS" ); next if ( $2 && $2 eq $name );
RESIDENTStk_findDummySlaves($name)
if ( $TYPE ne "RESIDENTS" && $TYPE ne "dummy" ); if ( $1 eq "REREADCFG" ) {
next unless ( $modules{$TYPE}{READY} );
$modules{$TYPE}{READY} = 0;
}
if ( $TYPE eq "RESIDENTS" ) {
RESIDENTStk_findResidentSlaves($hash);
}
else {
RESIDENTStk_findDummySlaves($name);
}
} }
# only process attribute events # only process attribute events
@ -3454,8 +3477,8 @@ sub RESIDENTStk_StopInternalTimers($) {
RESIDENTStk_RemoveInternalTimer( "DurationTimer", $hash ); RESIDENTStk_RemoveInternalTimer( "DurationTimer", $hash );
} }
sub RESIDENTStk_findResidentSlaves($;$) { sub RESIDENTStk_findResidentSlaves($) {
my ( $hash, $rgr_wakeupDevice ) = @_; my ($hash) = @_;
return return
unless ( ref($hash) eq "HASH" && defined( $hash->{NAME} ) ); unless ( ref($hash) eq "HASH" && defined( $hash->{NAME} ) );
@ -3497,8 +3520,6 @@ sub RESIDENTStk_findDummySlaves($) {
my $TYPE = GetType($name); my $TYPE = GetType($name);
my $prefix = RESIDENTStk_GetPrefixFromType($name); my $prefix = RESIDENTStk_GetPrefixFromType($name);
return undef unless ($init_done);
my $wakeupDevice = AttrVal( $name, $prefix . "wakeupDevice", undef ); my $wakeupDevice = AttrVal( $name, $prefix . "wakeupDevice", undef );
my $presenceDevices = AttrVal( $name, $prefix . "presenceDevices", undef ); my $presenceDevices = AttrVal( $name, $prefix . "presenceDevices", undef );
@ -3530,14 +3551,19 @@ sub RESIDENTStk_findDummySlaves($) {
} }
} }
# finish initialization # finish module initialization
if ( $hash->{'.READY'} ) { if ( $modules{$TYPE}{READY} == 0 ) {
DoTrigger( "global", "MODIFIED $name", 1 ); Log 1, "DEBUG+++ module $TYPE INITIALIZED";
$modules{$TYPE}{READY} = 1;
DoTrigger( "global", "$TYPE INITIALIZED", 1 );
} }
else {
$hash->{'.READY'} = 1; # internal modification
DoTrigger( "global", "INITIALIZED $name", 1 ); elsif ( $hash->{'.READY'} ) {
Log 1, "DEBUG+++ $name CHANGED_CONFIG";
DoTrigger( "global", "CHANGED_CONFIG $name", 1 );
} }
return ""; return "";
} }