98_Weekdaytimer:

added support for logProxy and repairing issue "inactive" state

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@8411 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
dietmar63 2015-04-09 19:54:46 +00:00
parent 969da05f6a
commit e23320ee2b

View File

@ -188,15 +188,17 @@ sub WeekdayTimer_Profile($) {
foreach my $d (@{$tage}) { foreach my $d (@{$tage}) {
my $dayOfEchteZeit = $d; my @listeDerTage = ($d);
if ($d==7) { # Weekend push (@listeDerTage, (0, 6) ) if ($d==7);
$dayOfEchteZeit = ($wday>=1&&$wday<=5) ? 6 : $wday; # ggf. Samstag $wday ~~ [1..5] push (@listeDerTage, (1..5) ) if ($d==8);
} elsif ($d==8) { # day of Week
$dayOfEchteZeit = ($wday==0||$wday==6) ? 1 : $wday; # ggf. Montag $wday ~~ [0, 6]
}
map { my $day = $_;
my $dayOfEchteZeit = $day;
$dayOfEchteZeit = ($wday>=1&&$wday<=5) ? 6 : $wday if ($day==7); # ggf. Samstag $wday ~~ [1..5]
$dayOfEchteZeit = ($wday==0||$wday==6) ? 1 : $wday if ($day==8); # ggf. Montag $wday ~~ [0, 6]
my $echtZeit = WeekdayTimer_EchteZeit($hash, $dayOfEchteZeit, $time); my $echtZeit = WeekdayTimer_EchteZeit($hash, $dayOfEchteZeit, $time);
$hash->{profile}{$d}{$echtZeit} = $parameter; $hash->{profile}{$day}{$echtZeit} = $parameter;
} @listeDerTage;
} }
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@ -221,7 +223,11 @@ sub WeekdayTimer_Profile($) {
$hash->{$profilKey} = $profiltext; $hash->{$profilKey} = $profiltext;
Log3 $hash, 4, "[$hash->{NAME}] $profiltext ($profilKey)"; Log3 $hash, 4, "[$hash->{NAME}] $profiltext ($profilKey)";
} }
# für logProxy umhaengen
$hash->{helper}{SWITCHINGTIME} = $hash->{profile};
delete $hash->{profile}; delete $hash->{profile};
#Log3 $hash, 3, "profile: " . Dumper $hash;
} }
################################################################################ ################################################################################
sub WeekdayTimer_SwitchingTime($$) { sub WeekdayTimer_SwitchingTime($$) {
@ -468,15 +474,17 @@ sub WeekdayTimer_SetTimer($) {
$hash->{profil}{$time}{NEXTSWITCH} = $nextSwitch; $hash->{profil}{$time}{NEXTSWITCH} = $nextSwitch;
my $timToSwitch = $hash->{profil}{$time}{TIM}; my $timToSwitch = $hash->{profil}{$time}{TIM};
my $tage = $hash->{profil}{$time}{TAGE};
$nextPara = $hash->{profil}{$time}{PARA}; $nextPara = $hash->{profil}{$time}{PARA};
$nextSwitch = $time; $nextSwitch = $time;
$timToSwitch -= 24*3600 if ($i == $#reverseSwitches); $timToSwitch -= 24*3600 if ($i == $#reverseSwitches);
my $secondsToSwitch = $timToSwitch - $now; my $secondsToSwitch = $timToSwitch - $now;
my $activeTimer = WeekdayTimer_isAnActiveTimer ($hash, $tage, $nextPara);
if ($secondsToSwitch>$grenzSeconds && !$switchedInThePast) { if ($secondsToSwitch>$grenzSeconds && !$switchedInThePast) {
myInternalTimer ("$time", $timToSwitch, "$hash->{TYPE}_Update", $hash, 0); myInternalTimer ("$time", $timToSwitch, "$hash->{TYPE}_Update", $hash, 0);
$switchedInThePast = ($secondsToSwitch<0); $switchedInThePast = ($secondsToSwitch<0 && $activeTimer) ;
} }
} }
} }
@ -507,19 +515,8 @@ sub WeekdayTimer_Update($) {
} }
my $active = 1; my $active = 1;
my $condition = WeekdayTimer_Condition ($hash, $tage); $active = WeekdayTimer_isAnActiveTimer ($hash, $tage, $newParam);
my $tageAsHash = WeekdayTimer_tageAsHash($hash, $tage); Log3 $hash, 4, "[$name] timer seems to be active today: ".join("",@$tage)."|$time|$newParam" if($active);
my $xPression = "{".$tageAsHash.";;".$condition ."}";
my %specials= (
"%NAME" => $hash->{DEVICE},
"%EVENT" => $newParam,
);
$xPression= EvalSpecials($xPression, %specials);
$xPression =~ s/%%days/%days/g;
if ($condition) {
$active = AnalyzeCommandChain(undef, $xPression);
}
Log3 $hash, 4, "[$name] seems to be active: $condition" if($active);
# ggf. Device schalten # ggf. Device schalten
WeekdayTimer_Device_Schalten($hash, $newParam, $tage); WeekdayTimer_Device_Schalten($hash, $newParam, $tage);
@ -535,6 +532,20 @@ sub WeekdayTimer_Update($) {
} }
################################################################################ ################################################################################
sub WeekdayTimer_isAnActiveTimer ($$$) {
my ($hash, $tage, $newParam) = @_;
my %specials = ( "%NAME" => $hash->{DEVICE}, "%EVENT" => $newParam);
my $condition = WeekdayTimer_Condition ($hash, $tage);
my $tageAsHash = WeekdayTimer_tageAsHash($hash, $tage);
my $xPression = "{".$tageAsHash.";;".$condition ."}";
$xPression = EvalSpecials($xPression, %specials);
$xPression =~ s/%%days/%days/g;
return AnalyzeCommandChain(undef, $xPression);
}
################################################################################
sub WeekdayTimer_isHeizung($) { sub WeekdayTimer_isHeizung($) {
my ($hash) = @_; my ($hash) = @_;
@ -697,10 +708,7 @@ sub WeekdayTimer_Device_Schalten($$$) {
if ($command && !$disabled && $aktParam ne $newParam) { if ($command && !$disabled && $aktParam ne $newParam) {
$newParam =~ s/:/ /g; $newParam =~ s/:/ /g;
my %specials= ( my %specials = ( "%NAME" => $hash->{DEVICE}, "%EVENT" => $newParam);
"%NAME" => $hash->{DEVICE},
"%EVENT" => $newParam,
);
$command= EvalSpecials($command, %specials); $command= EvalSpecials($command, %specials);
$command =~ s/%%days/%days/g; $command =~ s/%%days/%days/g;