RandomTimer - bug repaired in conjunction with onCmd and offCmd

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@6482 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
dietmar63 2014-08-30 20:11:54 +00:00
parent 4c07c937ce
commit 115ce96b69

View File

@ -170,7 +170,7 @@ sub RandomTimer_Exec($) {
# Wenn aktiv und Abschaltzeit erreicht, dann Gerät ausschalten, Meldung ausgeben und Timer schließen # Wenn aktiv und Abschaltzeit erreicht, dann Gerät ausschalten, Meldung ausgeben und Timer schließen
if ($stopTimeReached) { if ($stopTimeReached) {
Log3 $hash, 3, "[".$hash->{NAME}."] RandomTimer for $hash->{DEVICE} going down"; Log3 $hash, 3, "[".$hash->{NAME}."] RandomTimer for $hash->{DEVICE} going down";
RandomTimer_device_off($hash); #RandomTimer_device_off($hash);
RandomTimer_down($hash); RandomTimer_down($hash);
$hash->{active} = 0; $hash->{active} = 0;
if ( AttrVal($hash->{NAME}, "runonce", -1) eq 1 ) { if ( AttrVal($hash->{NAME}, "runonce", -1) eq 1 ) {
@ -222,14 +222,14 @@ sub RandomTimer_down($) {
my ($hash) = @_; my ($hash) = @_;
$hash->{COMMAND} = AttrVal($hash->{NAME}, "keepDeviceAlive", 0) ? "on" : "off"; $hash->{COMMAND} = AttrVal($hash->{NAME}, "keepDeviceAlive", 0) ? "on" : "off";
fhem ("set $hash->{DEVICE} $hash->{COMMAND}"); RandomTimer_device_switch($hash);
} }
######################################################################## ########################################################################
sub RandomTimer_device_off($) { #sub RandomTimer_device_off($) {
my ($hash) = @_; # my ($hash) = @_;
#
$hash->{COMMAND} = AttrVal($hash->{NAME}, "keepDeviceAlive", 0) ? "on" : "off"; # $hash->{COMMAND} = AttrVal($hash->{NAME}, "keepDeviceAlive", 0) ? "on" : "off";
} #}
######################################################################## ########################################################################
sub RandomTimer_setState($) { sub RandomTimer_setState($) {
my ($hash) = @_; my ($hash) = @_;
@ -342,30 +342,30 @@ sub stopZeitErmitteln ($$) {
} }
######################################################################## ########################################################################
sub schaltzeitenErmitteln ($) #sub schaltzeitenErmitteln ($)
{ #{
my ($hash) = @_; # my ($hash) = @_;
my($sec,$min,$hour)=localtime(time); # my($sec,$min,$hour)=localtime(time);
#
my $timespec_stop = $hash->{TIMESPEC_STOP}; # my $timespec_stop = $hash->{TIMESPEC_STOP};
#
Log3 ($hash, 3, "Wrong timespec_stop <$timespec_stop>, use \"[+][*]<time or func>\"" ) # Log3 ($hash, 3, "Wrong timespec_stop <$timespec_stop>, use \"[+][*]<time or func>\"" )
if($timespec_stop !~ m/^(\+)?(\*)?(.*)$/i); # if($timespec_stop !~ m/^(\+)?(\*)?(.*)$/i);
my ($srel, $srep, $stspec) = ($1, $2, $3); # my ($srel, $srep, $stspec) = ($1, $2, $3);
my ($err, $h, $m, $s, $fn) = GetTimeSpec($stspec); # my ($err, $h, $m, $s, $fn) = GetTimeSpec($stspec);
Log3 ($hash, 3, $err) if($err); # Log3 ($hash, 3, $err) if($err);
$h -=24 if ($h >= 24); # $h -=24 if ($h >= 24);
#
if ($hash->{S_REL}) { # if ($hash->{S_REL}) {
my ($thour, $tmin, $tsec) = split(/:/, $hash->{STARTTIME}); # my ($thour, $tmin, $tsec) = split(/:/, $hash->{STARTTIME});
my $timeToStart = time() + 3600*($thour-$hour) + 60*($tmin-$min) + ($tsec-$sec); # my $timeToStart = time() + 3600*($thour-$hour) + 60*($tmin-$min) + ($tsec-$sec);
my $timeToStop = $timeToStart + 3600*$h + 60*$m + $s; # my $timeToStop = $timeToStart + 3600*$h + 60*$m + $s;
($s,$m,$h)=localtime($timeToStop); # ($s,$m,$h)=localtime($timeToStop);
} # }
#
my $timeToStop_st = sprintf ("%02d:%02d:%2d", $h,$m,$s ); # my $timeToStop_st = sprintf ("%02d:%02d:%2d", $h,$m,$s );
return ($timeToStop_st); # return ($timeToStop_st);
} #}
######################################################################## ########################################################################
sub RandomTimer_device_toggle ($) sub RandomTimer_device_toggle ($)
{ {
@ -379,22 +379,27 @@ sub RandomTimer_device_toggle ($)
if ($zufall < $sigma ) { if ($zufall < $sigma ) {
$hash->{COMMAND} = ($hash->{COMMAND} eq "on") ? "off" : "on"; $hash->{COMMAND} = ($hash->{COMMAND} eq "on") ? "off" : "on";
RandomTimer_device_switch($hash);
my $command = "set @ $hash->{COMMAND}";
if ($hash->{COMMAND} eq "on") {
$command = AttrVal($hash->{NAME}, "onCmd", $command);
} else {
$command = AttrVal($hash->{NAME}, "offCmd", $command);
}
$command =~ s/@/$hash->{DEVICE}/g;
$command = SemicolonEscape($command);
Log3 $hash, 4, "[".$hash->{NAME}. "]"." command: $command";
my $ret = AnalyzeCommandChain(undef, $command);
Log3 ($hash, 3, $ret) if($ret);
} }
} }
######################################################################## ########################################################################
sub RandomTimer_device_switch ($)
{
my ($hash) = @_;
my $command = "set @ $hash->{COMMAND}";
if ($hash->{COMMAND} eq "on") {
$command = AttrVal($hash->{NAME}, "onCmd", $command);
} else {
$command = AttrVal($hash->{NAME}, "offCmd", $command);
}
$command =~ s/@/$hash->{DEVICE}/g;
$command = SemicolonEscape($command);
Log3 $hash, 4, "[".$hash->{NAME}. "]"." command: $command";
my $ret = AnalyzeCommandChain(undef, $command);
Log3 ($hash, 3, $ret) if($ret)
}
########################################################################
sub get_switchmode ($) { sub get_switchmode ($) {
my ($hash) = @_; my ($hash) = @_;