2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-02-08 05:15:10 +00:00

98_DOIF.pm: fixed: attribute was not set when defmod is redefined if no def was set, collect data for card are no longer deleted when defmod is redefined

git-svn-id: https://svn.fhem.de/fhem/trunk@25711 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
Damian 2022-02-20 09:18:05 +00:00
parent 9630724460
commit b9eecaae20

View File

@ -77,7 +77,7 @@ sub DOIF_delAll($)
delete ($hash->{perlblock}); delete ($hash->{perlblock});
delete ($hash->{var}); delete ($hash->{var});
delete ($hash->{accu}); delete ($hash->{accu});
delete ($hash->{collect}); #delete ($hash->{collect});
delete ($hash->{Regex}); delete ($hash->{Regex});
delete ($hash->{defs}); delete ($hash->{defs});
@ -3624,78 +3624,76 @@ CmdDoIf($$)
$hash->{helper}{sleeptimer}=-1; $hash->{helper}{sleeptimer}=-1;
return("","") if ($tail =~ /^ *$/); if ($tail !~ /^ *$/) {
$tail =~ s/\n/ /g;
$tail =~ s/\n/ /g; while ($tail ne "") {
return($tail, "no left bracket of condition") if ($tail !~ /^ *\(/);
while ($tail ne "") { #condition
return($tail, "no left bracket of condition") if ($tail !~ /^ *\(/); ($beginning,$cond,$err,$tail)=GetBlockDoIf($tail,'[\(\)]');
#condition return ($cond,$err) if ($err);
($beginning,$cond,$err,$tail)=GetBlockDoIf($tail,'[\(\)]'); ($cond,$err)=ReplaceAllReadingsDoIf($hash,$cond,$i,0);
return ($cond,$err) if ($err); return ($cond,$err) if ($err);
($cond,$err)=ReplaceAllReadingsDoIf($hash,$cond,$i,0); return ($tail,"no condition") if ($cond eq "");
return ($cond,$err) if ($err); $hash->{condition}{$i}=$cond;
return ($tail,"no condition") if ($cond eq ""); #DOIF
$hash->{condition}{$i}=$cond; $if_cmd_ori="";
#DOIF $j=0;
$if_cmd_ori=""; while ($tail =~ /^\s*(\(|\{)/) {
$j=0; if ($tail =~ /^\s*\(/) {
while ($tail =~ /^\s*(\(|\{)/) { ($beginning,$if_cmd_ori,$err,$tail)=GetBlockDoIf($tail,'[\(\)]');
if ($tail =~ /^\s*\(/) { return ($if_cmd_ori,$err) if ($err);
($beginning,$if_cmd_ori,$err,$tail)=GetBlockDoIf($tail,'[\(\)]'); } elsif ($tail =~ /^\s*\{/) {
return ($if_cmd_ori,$err) if ($err); ($beginning,$if_cmd_ori,$err,$tail)=GetBlockDoIf($tail,'[\{\}]');
} elsif ($tail =~ /^\s*\{/) { return ($if_cmd_ori,$err) if ($err);
($beginning,$if_cmd_ori,$err,$tail)=GetBlockDoIf($tail,'[\{\}]'); $if_cmd_ori="{".$if_cmd_ori."}";
return ($if_cmd_ori,$err) if ($err); }
$if_cmd_ori="{".$if_cmd_ori."}"; ($if_cmd,$err)=ParseCommandsDoIf($hash,$if_cmd_ori,0);
} return ($if_cmd,$err) if ($err);
($if_cmd,$err)=ParseCommandsDoIf($hash,$if_cmd_ori,0); #return ($tail,"no commands") if ($if_cmd eq "");
return ($if_cmd,$err) if ($err); $hash->{do}{$i}{$j++}=$if_cmd_ori;
#return ($tail,"no commands") if ($if_cmd eq ""); }
$hash->{do}{$i}{$j++}=$if_cmd_ori; $hash->{do}{$i}{0}=$if_cmd_ori if ($j==0); #do without brackets
$last_do=$i;
$tail =~ s/^\s*$//g;
if (length($tail)) {
$tail =~ /^\s*DOELSEIF/g;
if (pos($tail)) {
$tail=substr($tail,pos($tail));
if (!length($tail)) {
return ($tail,"no DOELSEIF block");
}
} else {
last if ($tail =~ /^\s*DOELSE/);
return ($tail,"expected DOELSEIF or DOELSE");
}
}
$i++;
} }
$hash->{do}{$i}{0}=$if_cmd_ori if ($j==0); #do without brackets #DOELSE
$last_do=$i;
$tail =~ s/^\s*$//g;
if (length($tail)) { if (length($tail)) {
$tail =~ /^\s*DOELSEIF/g; $tail =~ /^\s*DOELSE/g;
if (pos($tail)) { if (pos($tail)) {
$tail=substr($tail,pos($tail)); $tail=substr($tail,pos($tail));
if (!length($tail)) {
return ($tail,"no DOELSEIF block");
}
} else { } else {
last if ($tail =~ /^\s*DOELSE/); return ($tail,"expected DOELSE");
return ($tail,"expected DOELSEIF or DOELSE");
} }
$j=0;
while ($tail =~ /^\s*(\(|\{)/) {
if ($tail =~ /^\s*\(/) {
($beginning,$else_cmd_ori,$err,$tail)=GetBlockDoIf($tail,'[\(\)]');
return ($else_cmd_ori,$err) if ($err);
} elsif ($tail =~ /^\s*\{/) {
($beginning,$else_cmd_ori,$err,$tail)=GetBlockDoIf($tail,'[\{\}]');
return ($else_cmd_ori,$err) if ($err);
$else_cmd_ori="{".$else_cmd_ori."}";
}
($else_cmd,$err)=ParseCommandsDoIf($hash,$else_cmd_ori,0);
return ($else_cmd,$err) if ($err);
$hash->{do}{$last_do+1}{$j++}=$else_cmd_ori;
}
$hash->{do}{$last_do+1}{0}=$else_cmd_ori if ($j==0); #doelse without brackets
} }
$i++;
} }
#DOELSE
if (length($tail)) {
$tail =~ /^\s*DOELSE/g;
if (pos($tail)) {
$tail=substr($tail,pos($tail));
} else {
return ($tail,"expected DOELSE");
}
$j=0;
while ($tail =~ /^\s*(\(|\{)/) {
if ($tail =~ /^\s*\(/) {
($beginning,$else_cmd_ori,$err,$tail)=GetBlockDoIf($tail,'[\(\)]');
return ($else_cmd_ori,$err) if ($err);
} elsif ($tail =~ /^\s*\{/) {
($beginning,$else_cmd_ori,$err,$tail)=GetBlockDoIf($tail,'[\{\}]');
return ($else_cmd_ori,$err) if ($err);
$else_cmd_ori="{".$else_cmd_ori."}";
}
($else_cmd,$err)=ParseCommandsDoIf($hash,$else_cmd_ori,0);
return ($else_cmd,$err) if ($err);
$hash->{do}{$last_do+1}{$j++}=$else_cmd_ori;
}
$hash->{do}{$last_do+1}{0}=$else_cmd_ori if ($j==0); #doelse without brackets
}
if ($init_done) { if ($init_done) {
foreach my $key (keys %{$attr{$hash->{NAME}}}) { foreach my $key (keys %{$attr{$hash->{NAME}}}) {
if ($key ne "disable" and AttrVal($hash->{NAME},$key,"")) { if ($key ne "disable" and AttrVal($hash->{NAME},$key,"")) {