From 3da1f2ee3f3ff4bbe0f1b47101bc18ec340ddc48 Mon Sep 17 00:00:00 2001 From: jpawlowski Date: Sun, 21 Aug 2016 12:05:21 +0000 Subject: [PATCH] RESIDENTStk wakeuptimer: use new at-device attribute computeAfterInit git-svn-id: https://svn.fhem.de/fhem/trunk@12026 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/20_GUEST.pm | 24 +++++++++++++++--------- fhem/FHEM/20_ROOMMATE.pm | 28 ++++++++++------------------ fhem/FHEM/RESIDENTStk.pm | 6 ++++++ 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/fhem/FHEM/20_GUEST.pm b/fhem/FHEM/20_GUEST.pm index 8dd757a06..8ff431549 100644 --- a/fhem/FHEM/20_GUEST.pm +++ b/fhem/FHEM/20_GUEST.pm @@ -218,13 +218,17 @@ sub GUEST_Notify($$) { foreach my $wakeupDev (@registeredWakeupdevs) { my $wakeupAtdevice = AttrVal( $wakeupDev, "wakeupAtdevice", 0 ); - # as a replacement for missing NotifyFn in 90_at.pm: - # trigger recalculation of at device internal timer - if ( defined( $defs{$wakeupAtdevice} ) - && $defs{$wakeupAtdevice}{TYPE} eq "at" ) + # make sure computeAfterInit is set at at-device + # and re-calculate on our own this time + if ( defined( $defs{$wakeupAtdevice} ) + && $defs{$wakeupAtdevice}{TYPE} eq "at" + && AttrVal( $wakeupAtdevice, "computeAfterInit", 0 ) ne + "1" ) { - Log3 $wakeupDev, 4, -"$wakeupDev: Triggered recalculation via Perl function after reboot"; + Log3 $wakeupDev, 3, +"RESIDENTStk $wakeupDev: Correcting '$wakeupAtdevice' attribute computeAfterInit required for correct recalculation after reboot"; + fhem "attr $wakeupAtdevice computeAfterInit 1"; + my $command; ( $command, undef ) = split( "[ \t]+", $defs{$wakeupAtdevice}{DEF}, 2 ); @@ -495,7 +499,7 @@ sub GUEST_Set($@) { # stop any running wakeup-timers in case state changed my $wakeupState = ReadingsVal( $name, "wakeup", 0 ); - if ($wakeupState > 0) { + if ( $wakeupState > 0 ) { my $wakeupDeviceList = AttrVal( $name, "rg_wakeupDevice", 0 ); for my $wakeupDevice ( split /,/, $wakeupDeviceList ) { @@ -506,11 +510,13 @@ sub GUEST_Set($@) { { # forced-stop only if resident is not present anymore if ( $newpresence eq "present" ) { - Log3 $name, 4, "ROOMMATE $name: ending wakeup-timer $wakeupDevice"; + Log3 $name, 4, +"ROOMMATE $name: ending wakeup-timer $wakeupDevice"; fhem "set $wakeupDevice:FILTER=running!=0 end"; } else { - Log3 $name, 4, "ROOMMATE $name: stopping wakeup-timer $wakeupDevice"; + Log3 $name, 4, +"ROOMMATE $name: stopping wakeup-timer $wakeupDevice"; fhem "set $wakeupDevice:FILTER=running!=0 stop"; } } diff --git a/fhem/FHEM/20_ROOMMATE.pm b/fhem/FHEM/20_ROOMMATE.pm index e5741999e..71bc72dcf 100644 --- a/fhem/FHEM/20_ROOMMATE.pm +++ b/fhem/FHEM/20_ROOMMATE.pm @@ -170,18 +170,6 @@ sub ROOMMATE_Define($$) { . "). Some attribute based functions like auto-creations will not be available."; } -# Injecting NotifyFn for use with RESIDENTS Toolkit -# if ( !defined( $modules{at}{NotifyFn} ) ) { -# Log3 $name, 1, "RESIDENTStk $name: DEBUG - INJECTED AT"; -# $modules{at}{NotifyFn} = "RESIDENTStk_NotifyFnAt"; -# } -# elsif ( $modules{at}{NotifyFn} ne "RESIDENTStk_NotifyFnAt" ) { -# Log3 $name, 4, -#"RESIDENTStk $name: concurrent NotifyFn already defined for at module (" -# . $modules{at}{NotifyFn} -# . "). This might lead to issues for restoring wakeuptimer after FHEM reboot!"; -# } - return undef; } @@ -235,13 +223,17 @@ sub ROOMMATE_Notify($$) { foreach my $wakeupDev (@registeredWakeupdevs) { my $wakeupAtdevice = AttrVal( $wakeupDev, "wakeupAtdevice", 0 ); - # as a replacement for missing NotifyFn in 90_at.pm: - # trigger recalculation of at device internal timer - if ( defined( $defs{$wakeupAtdevice} ) - && $defs{$wakeupAtdevice}{TYPE} eq "at" ) + # make sure computeAfterInit is set at at-device + # and re-calculate on our own this time + if ( defined( $defs{$wakeupAtdevice} ) + && $defs{$wakeupAtdevice}{TYPE} eq "at" + && AttrVal( $wakeupAtdevice, "computeAfterInit", 0 ) ne + "1" ) { - Log3 $wakeupDev, 4, -"$wakeupDev: Triggered recalculation via Perl function after reboot"; + Log3 $wakeupDev, 3, +"RESIDENTStk $wakeupDev: Correcting '$wakeupAtdevice' attribute computeAfterInit required for correct recalculation after reboot"; + fhem "attr $wakeupAtdevice computeAfterInit 1"; + my $command; ( $command, undef ) = split( "[ \t]+", $defs{$wakeupAtdevice}{DEF}, 2 ); diff --git a/fhem/FHEM/RESIDENTStk.pm b/fhem/FHEM/RESIDENTStk.pm index 6b7bd537b..828f26754 100644 --- a/fhem/FHEM/RESIDENTStk.pm +++ b/fhem/FHEM/RESIDENTStk.pm @@ -254,6 +254,7 @@ if (\$EVTPART0 eq \"stop\") {\ "define $wakeupAtdevice at *{RESIDENTStk_wakeupGetBegin(\"$NAME\",\"$wakeupAtdevice\")} set $NAME trigger"; fhem "attr $wakeupAtdevice comment Auto-created by RESIDENTS Toolkit: trigger wake-up timer at specific time"; + fhem "attr $wakeupAtdevice computeAfterInit 1"; fhem "attr $wakeupAtdevice room $room" if ($room); @@ -684,6 +685,11 @@ if (\$EVTPART0 eq \"stop\") {\ Log3 $NAME, 3, "RESIDENTStk $NAME: WARNING - defined at-device '$wakeupAtdevice' is not an at-device!"; } + elsif ( AttrVal( $wakeupAtdevice, "computeAfterInit", 0 ) ne "1" ) { + Log3 $NAME, 3, +"RESIDENTStk $NAME: Correcting '$wakeupAtdevice' attribute computeAfterInit required for correct recalculation after reboot"; + fhem "attr $wakeupAtdevice computeAfterInit 1"; + } # verify holiday2we attribute if ($wakeupHolidays) {