2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-21 01:46:08 +00:00

98_WeekdayTimer: fix timer management when deleted

git-svn-id: https://svn.fhem.de/fhem/trunk@24476 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
Beta-User 2021-05-20 03:06:58 +00:00
parent 15b7027b8e
commit 416c8dbca9

View File

@ -97,6 +97,7 @@ sub Initialize {
$hash->{SetFn} = \&Set; $hash->{SetFn} = \&Set;
$hash->{DefFn} = \&Define; $hash->{DefFn} = \&Define;
$hash->{UndefFn} = \&Undef; $hash->{UndefFn} = \&Undef;
$hash->{DeleteFn} = \&Delete;
$hash->{GetFn} = \&Get; $hash->{GetFn} = \&Get;
$hash->{AttrFn} = \&Attr; $hash->{AttrFn} = \&Attr;
$hash->{UpdFn} = \&WeekdayTimer_Update; $hash->{UpdFn} = \&WeekdayTimer_Update;
@ -156,13 +157,14 @@ sub Undef {
my $hash = shift; my $hash = shift;
my $arg = shift // return; my $arg = shift // return;
for my $idx (keys %{$hash->{profil}}) { #for my $idx (keys %{$hash->{profil}}) {
deleteSingleRegisteredInternalTimer($idx, $hash); # deleteSingleRegisteredInternalTimer($idx, $hash);
} #}
deleteAllRegisteredInternalTimer($hash);
deleteSingleRegisteredInternalTimer($hash->{VERZOEGRUNG_IDX},$hash) if defined $hash->{VERZOEGRUNG_IDX}; deleteSingleRegisteredInternalTimer($hash->{VERZOEGRUNG_IDX},$hash) if defined $hash->{VERZOEGRUNG_IDX};
delete $modules{$hash->{TYPE}}{defptr}{$hash->{NAME}}; #delete $modules{$hash->{TYPE}}{defptr}{$hash->{NAME}};
return deleteSingleRegisteredInternalTimer("SetTimerOfDay", $hash); return deleteSingleRegisteredInternalTimer('SetTimerOfDay', $hash);
} }
################################################################################ ################################################################################
@ -196,7 +198,7 @@ sub WDT_Start {
$attr{$name}{verbose} = 5 if !defined $attr{$name}{verbose} && $name =~ m{\Atst.*}xms; $attr{$name}{verbose} = 5 if !defined $attr{$name}{verbose} && $name =~ m{\Atst.*}xms;
$defs{$device}{STILLDONETIME} = 0 if $defs{$device}; $defs{$device}{STILLDONETIME} = 0 if $defs{$device};
$modules{$hash->{TYPE}}{defptr}{$hash->{NAME}} = $hash; #$modules{$hash->{TYPE}}{defptr}{$hash->{NAME}} = $hash;
if ( $conditionOrCommand =~ m{\A\(.*\)\z}xms ) { #condition (*) if ( $conditionOrCommand =~ m{\A\(.*\)\z}xms ) { #condition (*)
$hash->{CONDITION} = $conditionOrCommand; $hash->{CONDITION} = $conditionOrCommand;
@ -224,6 +226,15 @@ sub WDT_Start {
return; return;
} }
sub Delete {
my $hash = shift // return;
deleteAllRegisteredInternalTimer($hash);
RemoveInternalTimer($hash);
deleteSingleRegisteredInternalTimer($hash->{VERZOEGRUNG_IDX},$hash) if defined $hash->{VERZOEGRUNG_IDX};
return;
}
################################################################################ ################################################################################
sub Set { sub Set {
my ($hash,@arr) = @_; my ($hash,@arr) = @_;
@ -546,7 +557,6 @@ sub _daylistAsArray {
} }
#replace all text in $daylist by numbers #replace all text in $daylist by numbers
$daylist = join q{}, sort keys %hdays; $daylist = join q{}, sort keys %hdays;
} }
# Angaben der Tage verarbeiten # Angaben der Tage verarbeiten
@ -769,9 +779,9 @@ sub _SetTimerForMidnightUpdate {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($now); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($now);
my $midnightPlus5Seconds = getSwitchtimeEpoch ($now, 0, 0, 5, 1); my $midnightPlus5Seconds = getSwitchtimeEpoch ($now, 0, 0, 5, 1);
RemoveInternalTimer($hash,\&WeekdayTimer_SetTimerOfDay); deleteSingleRegisteredInternalTimer('midnight', $hash,\&WeekdayTimer_SetTimerOfDay);
InternalTimer($midnightPlus5Seconds, \&WeekdayTimer_SetTimerOfDay, $hash, 0) if !AttrVal($hash->{NAME},'disable',0); $fnHash = setRegisteredInternalTimer('midnight', $midnightPlus5Seconds, \&WeekdayTimer_SetTimerOfDay, $hash, 0) if !AttrVal($hash->{NAME},'disable',0);
$hash->{SETTIMERATMIDNIGHT} = 1; $fnHash->{SETTIMERATMIDNIGHT} = 1;
return; return;
} }
@ -780,7 +790,7 @@ sub _SetTimerForMidnightUpdate {
sub WeekdayTimer_SetTimerOfDay { sub WeekdayTimer_SetTimerOfDay {
my $fnHash = shift // return; my $fnHash = shift // return;
my $hash = $fnHash->{HASH} // $fnHash; my $hash = $fnHash->{HASH} // $fnHash;
return if (!defined($hash)); return if !defined $hash;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
my $secSinceMidnight = 3600*$hour + 60*$min + $sec; my $secSinceMidnight = 3600*$hour + 60*$min + $sec;
@ -845,7 +855,7 @@ sub _SetTimer {
my @switches = sort keys %{$hash->{profil}}; my @switches = sort keys %{$hash->{profil}};
return Log3( $hash, 3, "[$name] no switches to send, due to possible errors." ) if !@switches; return Log3( $hash, 3, "[$name] no switches to send, due to possible errors." ) if !@switches;
readingsSingleUpdate ($hash, 'state', 'inactive', 1) if (!defined $hash->{SETTIMERATMIDNIGHT}); readingsSingleUpdate ($hash, 'state', 'inactive', 1) if !defined $hash->{SETTIMERATMIDNIGHT};
for(my $i=0; $i<=$#switches; $i++) { for(my $i=0; $i<=$#switches; $i++) {
my $idx = $switches[$i]; my $idx = $switches[$i];
@ -858,7 +868,7 @@ sub _SetTimer {
my $isActiveTimer = isAnActiveTimer ($hash, $tage, $para, $overrulewday); my $isActiveTimer = isAnActiveTimer ($hash, $tage, $para, $overrulewday);
readingsSingleUpdate ($hash, 'state', 'active', 1) readingsSingleUpdate ($hash, 'state', 'active', 1)
if (!defined $hash->{SETTIMERATMIDNIGHT} && $isActiveTimer); if !defined $hash->{SETTIMERATMIDNIGHT} && $isActiveTimer;
if ( $timToSwitch - $now > -5 || defined $hash->{SETTIMERATMIDNIGHT} ) { if ( $timToSwitch - $now > -5 || defined $hash->{SETTIMERATMIDNIGHT} ) {
if($isActiveTimer) { if($isActiveTimer) {