2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-24 09:09:19 +00:00

98_MSwitch.pm: Bugfix (set inactive)

git-svn-id: https://svn.fhem.de/fhem/trunk@20314 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
Byte09 2019-10-05 07:39:58 +00:00
parent 752035545a
commit 26c7a215fd

View File

@ -48,6 +48,12 @@
#
#################################################################
package main;
use Time::Local;
use strict;
@ -1165,6 +1171,13 @@ sub MSwitch_Set($@) {
$cs =~ s/\n//g;
$cs =~ s/\[tr\]/#[tr]/g;
my $return = "no value";
if ($debugging eq "1")
{
MSwitch_LOG( "Debug", 0,"eveal line" . __LINE__ );
}
$return = eval($cs);
if ($@) {
@ -1213,27 +1226,27 @@ sub MSwitch_Set($@) {
#####################
if ($debugging eq "2")
{
# if ($debugging eq "2")
# {
MSwitch_LOG( $name, 0,
"############# " . __LINE__ );
# MSwitch_LOG( $name, 0,
# "############# " . __LINE__ );
MSwitch_LOG( $name, 0,
"$name tarray ". join("-",@testarray));
# MSwitch_LOG( $name, 0,
# "$name tarray ". join("-",@testarray));
MSwitch_LOG( $name, 0,
"$name ATTS $atts ");
# MSwitch_LOG( $name, 0,
# "$name ATTS $atts ");
foreach my $debug ( sort keys %setlist )
{
MSwitch_LOG( $name, 0,
"- $debug " .$setlist{$debug}." ");
# foreach my $debug ( sort keys %setlist )
# {
# MSwitch_LOG( $name, 0,
# "- $debug " .$setlist{$debug}." ");
}
}
# }
# }
foreach my $k ( sort keys %sets ) {
@ -1254,7 +1267,8 @@ sub MSwitch_Set($@) {
# bearbeite setlist und readinglist
##############################
if ( $cmd ne "?" ) {
if ( $cmd ne "?" )
{
my @sl = split( " ", AttrVal( $name, "setList", "" ) );
my $re = qr/$cmd/;
my @gefischt = grep( /$re/, @sl );
@ -1305,6 +1319,7 @@ sub MSwitch_Set($@) {
}
}
if ( ( ( $cmd eq 'on' ) || ( $cmd eq 'off' ) )
&& ( $args[0] ne '' )
&& ( $ic ne 'fromnotify' ) )
@ -1342,11 +1357,18 @@ sub MSwitch_Set($@) {
delete( $hash->{helper}{repeats} );
return;
}
MSwitch_LOG( $name, 5,"BEFEHL. $cmd ");
##############################
if ( $cmd eq 'inactive' ) {
# setze device auf inaktiv
readingsSingleUpdate( $hash, "state", 'inactive', 1 );
return;
}
@ -1354,6 +1376,7 @@ sub MSwitch_Set($@) {
if ( $cmd eq 'active' ) {
# setze device auf aktiv
readingsSingleUpdate( $hash, "state", 'active', 1 );
return;
}
@ -2000,6 +2023,13 @@ sub MSwitch_Set($@) {
if ( $testtstate eq "[:]" || $testtstate eq "[\$:]" ) {
if ($debugging eq "1")
{
MSwitch_LOG( "Debug", 0,"eveal line" . __LINE__ );
}
$devicedetails{$timerkey} =
eval MSwitch_Checkcond_state( $devicedetails{$timerkey},
$name );
@ -2242,6 +2272,9 @@ sub MSwitch_Set($@) {
readingsSingleUpdate( $hash, "state", $cmd, 1 );
}
else {
readingsSingleUpdate( $hash, "state", 'active', $showevents );
}
my $anzahl = @cmdpool;
@ -2382,6 +2415,13 @@ sub MSwitch_Cmd(@) {
MSwitch_LOG( $Name, 6,
"$Name: exec als perlcode -> " . $cmds );
if ($debugging eq "1")
{
MSwitch_LOG( "Debug", 0,"eveal line" . __LINE__ );
}
my $out = eval($cmds);
if ($@) {
MSwitch_LOG( $Name, 1,
@ -2648,6 +2688,9 @@ sub MSwitch_Attr(@) {
}
if ( $aName eq 'MSwitch_Mode' && $aVal eq 'Notify' ) {
readingsSingleUpdate( $hash, "state", 'active', 1 );
$hash->{MODEL} = 'Notify';
my $cs = "setstate $name active";
@ -3305,11 +3348,7 @@ sub MSwitch_Notify($$) {
# speichert 20 events ab zur weiterne funktion ( funktionen )
# ändern auf bedarfschaltung
if ($debugging eq "1")
{
MSwitch_LOG( $ownName, 0,"############");
MSwitch_LOG( $ownName, 0,"$ownName: eventcopy $eventcopy" );
}
@ -3346,6 +3385,12 @@ if ($debugging eq "1")
and $activecount == 0 )
{
# reading activity aktualisieren
MSwitch_LOG( $ownName, 5,"setze state neu");
readingsSingleUpdate( $own_hash, "state",
'active', $showevents );
$activecount = 1;
@ -3657,7 +3702,12 @@ sub MSwitch_fhemwebFn($$$$) {
@eventsall = @eventsallnew;
if ( AttrVal( $Name, 'MSwitch_Mode', 'Notify' ) eq "Notify" ) {
if ( ReadingsVal( $Name, 'state', '' ) ne "inactive" ) {
readingsSingleUpdate( $hash, "state", 'active', 1 );
}
$triggeroff = "";
$triggeron = "";
}
@ -5617,6 +5667,13 @@ sub MSwitch_fhemwebFn($$$$) {
my $fieldon = "";
if ( $triggeron =~ m/{(.*)}/ ) {
my $exec = "\$fieldon = " . $1;
if ($debugging eq "1")
{
MSwitch_LOG( "Debug", 0,"eveal line" . __LINE__ );
}
eval($exec);
$ret .=
"<input style='background-color:#e5e5e5;' name='info' readonly value='value = "
@ -5642,6 +5699,13 @@ sub MSwitch_fhemwebFn($$$$) {
my $fieldoff = "";
if ( $triggeroff =~ m/{(.*)}/ ) {
my $exec = "\$fieldoff = " . $1;
if ($debugging eq "1")
{
MSwitch_LOG( "Debug", 0,"eveal line" . __LINE__ );
}
eval($exec);
$ret .=
"<input style='background-color:#e5e5e5;' name='info' readonly value='value = "
@ -5667,6 +5731,13 @@ sub MSwitch_fhemwebFn($$$$) {
my $fieldcmdon = "";
if ( $triggercmdon =~ m/{(.*)}/ ) {
my $exec = "\$fieldcmdon = " . $1;
if ($debugging eq "1")
{
MSwitch_LOG( "Debug", 0,"eveal line" . __LINE__ );
}
eval($exec);
$ret .=
"<input style='background-color:#e5e5e5;' name='info' readonly value='value = "
@ -5689,6 +5760,13 @@ sub MSwitch_fhemwebFn($$$$) {
my $fieldcmdoff = "";
if ( $triggercmdoff =~ m/{(.*)}/ ) {
my $exec = "\$fieldcmdoff = " . $1;
if ($debugging eq "1")
{
MSwitch_LOG( "Debug", 0,"eveal line" . __LINE__ );
}
eval($exec);
$ret .=
"<input style='background-color:#e5e5e5;' name='info' readonly value='value = "
@ -7012,6 +7090,13 @@ sub MSwitch_Exec_Notif($$$$$) {
$testtstate =~ s/[A-Za-z0-9#\.\-_]//g;
if ( $testtstate eq "[:]" || $testtstate eq "[\$:]" ) {
if ($debugging eq "1")
{
MSwitch_LOG( "Debug", 0,"eveal line" . __LINE__ );
}
$devicedetails{$timerkey} =
eval MSwitch_Checkcond_state( $devicedetails{$timerkey}, $name );
@ -7177,6 +7262,13 @@ sub MSwitch_Exec_Notif($$$$$) {
else {
if ( $cs =~ m/{.*}/ ) {
if ($debugging eq "1")
{
MSwitch_LOG( "Debug", 0,"eveal line" . __LINE__ );
}
eval($cs);
if ($@ and $@ ne "OK" ) {
MSwitch_LOG( $name, 1,
@ -7529,6 +7621,13 @@ sub MSwitch_Restartcmd($) {
if ( $cs =~ m/{.*}/ ) {
MSwitch_LOG( $name, 5,
"$name: exec als perlcode -> " . $cs );
if ($debugging eq "1")
{
MSwitch_LOG( "Debug", 0,"eveal line" . __LINE__ );
}
eval($cs);
if ($@) {
MSwitch_LOG( $name, 1,
@ -7684,6 +7783,13 @@ sub MSwitch_checkcondition($$$) {
. $rechenzeichen
. $vergleichswert
. ";return \$ret;";
if ($debugging eq "1")
{
MSwitch_LOG( "Debug", 0,"eveal line" . __LINE__ );
}
my $erg2 = eval $erg;
MSwitch_LOG( $name, 5, "$name: ergebniss : $erg" );
MSwitch_LOG( $name, 5, "$name: ergebniss : $erg2" );
@ -7947,6 +8053,13 @@ sub MSwitch_checkcondition($$$) {
. $rechenzeichen
. $vergleichswert
. ";return \$ret;";
if ($debugging eq "1")
{
MSwitch_LOG( "Debug", 0,"eveal line" . __LINE__ );
}
my $erg1 = eval $erg;
MSwitch_LOG( $name, 5, "$name: Teststring: $erg" );
@ -8054,6 +8167,13 @@ sub MSwitch_checkcondition($$$) {
. $rechenzeichen
. $vergleichswert
. ";return \$ret;";
if ($debugging eq "1")
{
MSwitch_LOG( "Debug", 0,"eveal line" . __LINE__ );
}
my $erg1 = eval $erg;
$finalinc =
"Funktionberechnung INCREASE<br>Herangezogene Werte: letzter Wert "
@ -8090,6 +8210,13 @@ sub MSwitch_checkcondition($$$) {
$field = $secondpart;
}
else {
if ($debugging eq "1")
{
MSwitch_LOG( "Debug", 0,"eveal line" . __LINE__ );
}
eval($exec);
}
@ -8265,6 +8392,13 @@ m/(.*?)(\[\[[a-zA-Z][a-zA-Z0-9_]{0,30}:[a-zA-Z0-9_]{0,30}\]-\[[a-zA-Z][a-zA-Z0-9
$x++; # notausstieg
last if $x > 20; # notausstieg
if ( defined $2 ) {
if ($debugging eq "1")
{
MSwitch_LOG( "Debug", 0,"eveal line" . __LINE__ );
}
my $part2 = eval $3;
chop($part2);
chop($part2);
@ -8356,6 +8490,13 @@ m/(.*?)(\[\[[a-zA-Z][a-zA-Z0-9_]{0,30}:[a-zA-Z0-9_]{0,30}\]-\[[a-zA-Z][a-zA-Z0-9
MSwitch_LOG( $name, 5,
"$name: Checkcondition - finalstring -> " . $finalstring );
if ($debugging eq "1")
{
MSwitch_LOG( "Debug", 0,"eveal line" . __LINE__ );
}
my $ret = eval $finalstring;
if ($@) {
@ -8596,6 +8737,13 @@ sub MSwitch_Createtimer($) {
if ( defined $2 ) {
my $part1 = $1;
my $part3 = $3;
if ($debugging eq "1")
{
MSwitch_LOG( "Debug", 0,"eveal line" . __LINE__ );
}
my $part2 = eval $2;
if ( $part2 !~ m/^[0-9]{2}:[0-9]{2}$|^[0-9]{2}:[0-9]{2}:[0-9]{2}$/ )
{
@ -8622,6 +8770,10 @@ sub MSwitch_Createtimer($) {
$timer[3] = '' if ( !defined $timer[3] ); #cmd2
$timer[4] = '' if ( !defined $timer[4] ); #cmd1+2
#MSwitch_LOG($Name,0,"$Name timer: $timer[2] ");
# lösche bei notify und toggle
if ( AttrVal( $Name, 'MSwitch_Mode', 'Notify' ) eq "Notify" ) {
$timer[0] = '';
@ -8685,6 +8837,9 @@ sub MSwitch_Createtimer($) {
my $y = 0;
#MSwitch_LOG($Name,0,"$Name option: $option ");
while ( $option =~
@ -8694,6 +8849,15 @@ m/(.*?)([0-9]{2}):([0-9]{2})\*([0-9]{2}:[0-9]{2})-([0-9]{2}:[0-9]{2})\|?([0-9!\$
$y++;
last if $y > 20;
# MSwitch_LOG($Name,0,"$Name 1: $1 ");
# MSwitch_LOG($Name,0,"$Name 2: $2 ");
# MSwitch_LOG($Name,0,"$Name 3: $3 ");
# MSwitch_LOG($Name,0,"$Name 4: $4 ");
# MSwitch_LOG($Name,0,"$Name 5: $5 ");
# MSwitch_LOG($Name,0,"$Name 6: $6 ");
# MSwitch_LOG($Name,0,"$Name 7: $7 ");
my $part1 = '';
$part1 = $1 . ' ' if defined $1;
@ -8702,7 +8866,11 @@ m/(.*?)([0-9]{2}):([0-9]{2})\*([0-9]{2}:[0-9]{2})-([0-9]{2}:[0-9]{2})\|?([0-9!\$
my $part7 = '';
$part7 = ' ' . $7 if defined $7;
#MSwitch_LOG($Name,0,"$Name part6: $part6 ");
#MSwitch_LOG($Name,0,"$Name part7: $part7 ");
my $sectoadd = $2 * 3600 + $3 * 60;
my $t1 = $4;
my $t2 = $5;
@ -8738,7 +8906,10 @@ m/(.*?)([0-9]{2}):([0-9]{2})\*([0-9]{2}:[0-9]{2})-([0-9]{2}:[0-9]{2})\|?([0-9!\$
#my $timestamp = FmtDateTime($timecond1);
my $timestamp =substr( FmtDateTime($timecond1), 11, 5 ) . $part6;
#MSwitch_LOG($Name,0,"$Name timestamp: $timestamp ");
$timecond1 = $timecond1 + $sectoadd;
push( @newarray, $timestamp );
}
@ -9041,6 +9212,13 @@ sub MSwitch_ChangeCode($$) {
$x++; # exit secure
last if $x > 20; # exit secure
if ( defined $2 ) {
if ($debugging eq "1")
{
MSwitch_LOG( "Debug", 0,"eveal line" . __LINE__ );
}
my $part2 = eval $2 . $3;
chop($part2);
chop($part2);
@ -9306,6 +9484,13 @@ sub MSwitch_checktrigger(@) {
my $SELF = $ownName;
my $exec = "\$triggerfield = " . $1;
if ($debugging eq "1")
{
MSwitch_LOG( "Debug", 0,"eveal line" . __LINE__ );
}
eval($exec);
}
@ -9988,6 +10173,13 @@ sub MSwitch_repeat($) {
if ( AttrVal( $name, 'MSwitch_Debug', "0" ) ne '2' ) {
if ( $cs =~ m/{.*}/ ) {
if ($debugging eq "1")
{
MSwitch_LOG( "Debug", 0,"eveal line" . __LINE__ );
}
eval($cs);
if ($@) {
MSwitch_LOG( $name, 1,