2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-22 14:16:42 +00:00

98_MSwitch.pm:change Timecontrol/Events - Conditiontest/Events

git-svn-id: https://svn.fhem.de/fhem/trunk@17243 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
Byte09 2018-09-01 04:45:42 +00:00
parent 4ece3571cf
commit 11652d845f

View File

@ -36,7 +36,7 @@ use warnings;
use POSIX; use POSIX;
# Version ####################################################### # Version #######################################################
my $version = 'V1.73'; my $version = 'V1.74';
my $vupdate = 'V 1.2'; my $vupdate = 'V 1.2';
my $savecount = 30; my $savecount = 30;
my $standartstartdelay =60; my $standartstartdelay =60;
@ -79,6 +79,7 @@ sub MSwitch_set_dev($);
sub MSwitch_EventBulk($$$); sub MSwitch_EventBulk($$$);
sub MSwitch_priority ; sub MSwitch_priority ;
sub MSwitch_dec($$); sub MSwitch_dec($$);
sub MSwitch_makefreecmd($$);
my %sets = ( my %sets = (
@ -512,6 +513,11 @@ sub MSwitch_Get($$@) {
if ( $opt eq 'checkcondition' ) { if ( $opt eq 'checkcondition' ) {
my ( $condstring, $eventstring ) = split( /\|/, $args[0] ); my ( $condstring, $eventstring ) = split( /\|/, $args[0] );
Log3( $name, 0,"cond: $condstring " . __LINE__ );
Log3( $name, 0,"event: $eventstring " . __LINE__ );
$condstring =~ s/#\[dp\]/:/g; $condstring =~ s/#\[dp\]/:/g;
$condstring =~ s/#\[pt\]/./g; $condstring =~ s/#\[pt\]/./g;
$condstring =~ s/#\[ti\]/~/g; $condstring =~ s/#\[ti\]/~/g;
@ -1183,28 +1189,43 @@ sub MSwitch_Set($@) {
if ( $devicenamet eq 'FreeCmd' ) if ( $devicenamet eq 'FreeCmd' )
{ {
$cs = "$devicedetails{$device.'_onarg'}"; $cs = "$devicedetails{$device.'_onarg'}";
$cs = MSwitch_makefreecmd($hash,$cs);
# # setmagic
# my $ersetzung ="";
# #Log3( $name, 0,"$name MSwitch_Set: ".$cs." L:". __LINE__ );
# setmagic # $cs =~ s/#\[ti\]/~/g;
#Log3( $name, 0,"$name MSwitch_Set: ".$cs." L:". __LINE__ ); # # entferne kommntarzeilen
# $cs =~ s/#.*\n//g;
$cs =~ s/#\[ti\]/~/g;
# entferne kommntarzeilen
$cs =~ s/#.*\n//g;
$cs =~ s/\n//g; # $cs =~ s/\n//g;
# $ersetzung = ReadingsVal( $name, "EVTPART3", "" );
# $cs =~ s/\$EVTPART3/$ersetzung/g;
# $ersetzung = ReadingsVal( $name, "EVTPART2", "" );
# $cs =~ s/\$EVTPART2/$ersetzung/g;
# $ersetzung = ReadingsVal( $name, "EVTPART1", "" );
# $cs =~ s/\$EVTPART1/$ersetzung/g;
# $ersetzung = ReadingsVal( $name, "EVENT", "" );
# $cs =~ s/\$EVENT/$ersetzung/g;
# $ersetzung = ReadingsVal( $name, "EVENTFULL", "" );
# $cs =~ s/\$EVENTFULL/$ersetzung/g;
my $x =0;
while ( $cs =~ m/(.*)\[(.*)\:(.*)\](.*)/ )
{
$x++; # notausstieg notausstieg
last if $x > 20; # notausstieg notausstieg # my $x =0;
my $setmagic = ReadingsVal( $2, $3, 0 ); # while ( $cs =~ m/(.*)\[(.*)\:(.*)\](.*)/ )
$cs = $1.$setmagic.$4; # {
} # $x++; # notausstieg notausstieg
# last if $x > 20; # notausstieg notausstieg
# my $setmagic = ReadingsVal( $2, $3, 0 );
# $cs = $1.$setmagic.$4;
# }
} }
if ($devicedetails{$timerkey} eq "0"|| $devicedetails{$timerkey} eq "") if ($devicedetails{$timerkey} eq "0"|| $devicedetails{$timerkey} eq "")
@ -1352,23 +1373,39 @@ sub MSwitch_Set($@) {
if ( $devicenamet eq 'FreeCmd' ) if ( $devicenamet eq 'FreeCmd' )
{ {
$cs = "$devicedetails{$device.'_offarg'}"; $cs = "$devicedetails{$device.'_offarg'}";
# setmagic $cs = MSwitch_makefreecmd($hash,$cs);
$cs =~ s/#\[ti\]/~/g; # # setmagic
# my $ersetzung ="";
# $cs =~ s/#\[ti\]/~/g;
# entferne kommntarzeilen # # entferne kommntarzeilen
$cs =~ s/#.*\n//g; # $cs =~ s/#.*\n//g;
$cs =~ s/\n//g; # $cs =~ s/\n//g;
my $x =0; # $ersetzung = ReadingsVal( $name, "EVTPART3", "" );
while ( $cs =~ m/(.*)\[(.*)\:(.*)\](.*)/ ) # $cs =~ s/\$EVTPART3/$ersetzung/g;
{ # $ersetzung = ReadingsVal( $name, "EVTPART2", "" );
$x++; # exit # $cs =~ s/\$EVTPART2/$ersetzung/g;
last if $x > 20; # exit # $ersetzung = ReadingsVal( $name, "EVTPART1", "" );
my $setmagic = ReadingsVal( $2, $3, 0 ); # $cs =~ s/\$EVTPART1/$ersetzung/g;
$cs = $1.$setmagic.$4; # $ersetzung = ReadingsVal( $name, "EVENT", "" );
} # $cs =~ s/\$EVENT/$ersetzung/g;
# $ersetzung = ReadingsVal( $name, "EVENTFULL", "" );
# $cs =~ s/\$EVENTFULL/$ersetzung/g;
# my $x =0;
# while ( $cs =~ m/(.*)\[(.*)\:(.*)\](.*)/ )
# {
# $x++; # exit
# last if $x > 20; # exit
# my $setmagic = ReadingsVal( $2, $3, 0 );
# $cs = $1.$setmagic.$4;
# }
} }
#my $conditionkey; #my $conditionkey;
@ -3492,7 +3529,11 @@ sub MSwitch_fhemwebFn($$$$) {
if ( AttrVal( $Name, 'MSwitch_Debug', "0" ) eq '1' ) if ( AttrVal( $Name, 'MSwitch_Debug', "0" ) eq '1' )
{ {
$ret = $ret. " <input name='info' type='button' value='check condition' onclick=\"javascript: checkcondition('triggercondition',document.querySelector('#triggercondition').value)\">"; # $ret = $ret. " <input name='info' type='button' value='check condition' onclick=\"javascript: checkcondition('triggercondition',document.querySelector('#triggercondition').value)\">";
$ret = $ret. " <input name='info' type='button' value='check condition' onclick=\"javascript: checkcondition('triggercondition','$Name:trigger:conditiontest')\">";
} }
$ret = $ret . "</td></tr>"; $ret = $ret . "</td></tr>";
@ -3751,23 +3792,31 @@ sub MSwitch_fhemwebFn($$$$) {
function checkcondition(condition,event){ function checkcondition(condition,event){
//alert(condition,event);
var selected =document.getElementById(condition).value; var selected =document.getElementById(condition).value;
// event = \"test:test:test\";
if (selected == '') if (selected == '')
{ {
var textfinal = \"<div style ='font-size: medium;'>Es ist keine Bedingung definiert, das Kommando wird immer ausgeführt.</div>\"; var textfinal = \"<div style ='font-size: medium;'>Es ist keine Bedingung definiert, das Kommando wird immer ausgeführt.</div>\";
FW_okDialog(textfinal); FW_okDialog(textfinal);
return; return;
} }
//selected = selected.replace(/ /g,'~');
selected = selected.replace(/\\|/g,'(DAYS)');
//var textfinal = \"<div style ='font-size: medium;'>\"+event+\"</div>\";
//FW_okDialog(textfinal);
//return;
selected = selected.replace(/\\|/g,'(DAYS)');
selected = selected.replace(/\\./g,'#[pt]'); selected = selected.replace(/\\./g,'#[pt]');
selected = selected.replace(/:/g,'#[dp]'); selected = selected.replace(/:/g,'#[dp]');
selected= selected.replace(/~/g,'#[ti]'); selected= selected.replace(/~/g,'#[ti]');
selected = selected.replace(/ /g,'#[sp]'); selected = selected.replace(/ /g,'#[sp]');
event = event.replace(/~/g,'#[ti]'); event = event.replace(/~/g,'#[ti]');
//event = event.replace(/ /g,'~');
event = event.replace(/ /g,'#[sp]'); event = event.replace(/ /g,'#[sp]');
cmd ='get " . $Name . " checkcondition '+selected+'|'+event; cmd ='get " . $Name . " checkcondition '+selected+'|'+event;
@ -4385,25 +4434,32 @@ sub MSwitch_Exec_Notif($$$$) {
{ {
$cs = " $devicedetails{$device.'_'.$comand.'arg'}"; $cs = " $devicedetails{$device.'_'.$comand.'arg'}";
$cs = MSwitch_makefreecmd($hash,$cs);
# setmagic # my $ersetzung ="";
# # setmagic
$cs =~ s/#\[ti\]/~/g; # $cs =~ s/#\[ti\]/~/g;
# entferne kommentarte # # entferne kommentarte
# $cs =~ s/#.*\n//g;
$cs =~ s/#.*\n//g; # $cs =~ s/\n//g;
# $ersetzung = ReadingsVal( $name, "EVTPART3", "" );
$cs =~ s/\n//g; # $cs =~ s/\$EVTPART3/$ersetzung/g;
# $ersetzung = ReadingsVal( $name, "EVTPART2", "" );
# $cs =~ s/\$EVTPART2/$ersetzung/g;
my $x =0; # $ersetzung = ReadingsVal( $name, "EVTPART1", "" );
while ( $cs =~ m/(.*)\[(.*)\:(.*)\](.*)/ ) # $cs =~ s/\$EVTPART1/$ersetzung/g;
{ # $ersetzung = ReadingsVal( $name, "EVENT", "" );
$x++; # notausstieg notausstieg # $cs =~ s/\$EVENT/$ersetzung/g;
last if $x > 20; # notausstieg notausstieg # $ersetzung = ReadingsVal( $name, "EVENTFULL", "" );
my $setmagic = ReadingsVal( $2, $3, 0 ); # $cs =~ s/\$EVENTFULL/$ersetzung/g;
$cs = $1.$setmagic.$4; # my $x =0;
} # while ( $cs =~ m/(.*)\[(.*)\:(.*)\](.*)/ )
# {
# $x++; # notausstieg notausstieg
# last if $x > 20; # notausstieg notausstieg
# my $setmagic = ReadingsVal( $2, $3, 0 );
# $cs = $1.$setmagic.$4;
# }
} }
else else
@ -5357,10 +5413,15 @@ sub MSwitch_Execute_Timer($) {
$triggercondition =~ s/#\[ti\]/~/g; $triggercondition =~ s/#\[ti\]/~/g;
$triggercondition =~ s/#\[sp\]/ /g; $triggercondition =~ s/#\[sp\]/ /g;
if ( $triggercondition ne '' ) if ( $triggercondition ne '' )
{ {
#Log3( $Name, 5,"aufruf triggerconditionr". __LINE__ ); Log3( $Name, 0,"aufruf triggerconditionr". __LINE__ );
my $ret = MSwitch_checkcondition( $triggercondition, $Name, '' ); my $ret = MSwitch_checkcondition( $triggercondition, $Name, '' );
@ -5371,18 +5432,23 @@ sub MSwitch_Execute_Timer($) {
} }
} }
readingsBeginUpdate($hash);
readingsBulkUpdate( $hash, "EVENT", $Name.":execute_timer:P".$param ); my $extime = POSIX::strftime("%H:%M",localtime);
readingsBulkUpdate( $hash, "EVTFULL", $Name.":execute_timer:P".$param );
readingsBulkUpdate( $hash, "EVTPART1", $Name );
readingsBulkUpdate( $hash, "EVTPART2","execute_timer" ); readingsBeginUpdate($hash);
readingsBulkUpdate( $hash, "EVTPART3","P".$param ); readingsBulkUpdate( $hash, "EVENT", $Name.":execute_timer_P".$param.":".$extime );
readingsEndUpdate( $hash, 1 ); readingsBulkUpdate( $hash, "EVTFULL", $Name.":execute_timer_P".$param.":".$extime );
readingsBulkUpdate( $hash, "EVTPART1", $Name );
readingsBulkUpdate( $hash, "EVTPART2","execute_timer_P".$param );
readingsBulkUpdate( $hash, "EVTPART3",$extime );
readingsEndUpdate( $hash, 1 );
if ( $param eq '1' ) if ( $param eq '1' )
{ {
my $cs = "set $Name on"; my $cs = "set $Name on";
Log3( $Name, 3, "$Name MSwitch_Execute_Timer: Befehlsausfuehrung -> $cs" . __LINE__ ); Log3( $Name, 3, "$Name MSwitch_Execute_Timer: Befehlsausfuehrung -> $cs" . __LINE__ );
#Log3( $Name, 3, "$Name MSwitch_Execute_Timer: Befehlsausfuehrung -> $cs" . __LINE__ );
my $errors = AnalyzeCommandChain( undef, $cs ); my $errors = AnalyzeCommandChain( undef, $cs );
if ( defined($errors) ) if ( defined($errors) )
{ {
@ -6367,6 +6433,47 @@ $todec =~ s/#\[wa\]/|/g;
return $todec; return $todec;
} }
################################################################
sub MSwitch_makefreecmd($$) {
my ( $hash, $cs) = @_;
my $name = $hash->{NAME};
my $ersetzung ="";
$cs =~ s/#\[ti\]/~/g;
# entferne kommntarzeilen
$cs =~ s/#.*\n//g;
# entferne zeilenumbruch
$cs =~ s/\n//g;
# ersetze Eventvariablen
$ersetzung = ReadingsVal( $name, "EVTPART3", "" );
$cs =~ s/\$EVTPART3/$ersetzung/g;
$ersetzung = ReadingsVal( $name, "EVTPART2", "" );
$cs =~ s/\$EVTPART2/$ersetzung/g;
$ersetzung = ReadingsVal( $name, "EVTPART1", "" );
$cs =~ s/\$EVTPART1/$ersetzung/g;
$ersetzung = ReadingsVal( $name, "EVENT", "" );
$cs =~ s/\$EVENT/$ersetzung/g;
$ersetzung = ReadingsVal( $name, "EVENTFULL", "" );
$cs =~ s/\$EVENTFULL/$ersetzung/g;
# setmagic ersetzun
my $x =0;
while ( $cs =~ m/(.*)\[(.*)\:(.*)\](.*)/ )
{
$x++; # notausstieg notausstieg
last if $x > 20; # notausstieg notausstieg
my $setmagic = ReadingsVal( $2, $3, 0 );
$cs = $1.$setmagic.$4;
}
return $cs;
}
#################################
1; 1;