2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 18:59:33 +00:00

98_MSwitch.pm:update V2.09

git-svn-id: https://svn.fhem.de/fhem/trunk@18073 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
Byte09 2018-12-28 06:48:07 +00:00
parent 5c3b5fa1ff
commit 300c3a9a7f

View File

@ -27,6 +27,8 @@
#################################################################
# Todo's:
# reading las_cmd fehlerhaft bei befehlen mit delay
# evtcount einführen
# del delays kontrollieren
#---------------------------------------------------------------
#
# info sonderreadings
@ -83,7 +85,7 @@ if ( $preconf && $preconf ne "" ) {
}
my $autoupdate = 'off'; #off/on
my $version = '2.08';
my $version = '2.09';
my $vupdate = 'V2.00'
; # versionsnummer der datenstruktur . änderung der nummer löst MSwitch_VUpdate aus .
my $savecount = 30
@ -218,6 +220,8 @@ sub MSwitch_Initialize($) {
. " MSwitch_Activate_MSwitchcmds:0,1"
. " MSwitch_Lock_Quickedit:0,1"
. " MSwitch_Ignore_Types:textField-long "
. " MSwitch_Reset_EVT_CMD1_COUNT"
. " MSwitch_Reset_EVT_CMD2_COUNT"
. " MSwitch_Trigger_Filter"
. " MSwitch_Extensions:0,1"
. " MSwitch_Inforoom"
@ -234,7 +238,7 @@ sub MSwitch_Initialize($) {
$hash->{FW_addDetailToSummary} = 0;
}
####################
#################### EVT_CMD1_COUNT
sub MSwitch_Rename($) {
# routine nicht in funktion
@ -949,6 +953,8 @@ sub MSwitch_Set($@) {
$setList =~ s/\n/ /g;
my $devicemode = AttrVal( $name, 'MSwitch_Mode', 'Full' );
my $delaymode = AttrVal( $name, 'MSwitch_Delete_Delays', '0' );
if ( !exists( $sets{$cmd} ) ) {
my @cList;
@ -1542,6 +1548,12 @@ sub MSwitch_Set($@) {
#neu ausführung on/off
if ( $cmd eq "off" || $cmd eq "on" ) {
### neu
if ( $delaymode eq '1' ) {
MSwitch_Delete_Delay( $hash, $name );
}
############
# ausführen des off befehls
my $zweig = 'nicht definiert';
$zweig = "cmd1" if $cmd eq "on";
@ -2216,6 +2228,19 @@ sub MSwitch_Attr(@) {
delete( $hash->{helper}{savemodeblock} );
delete( $hash->{READINGS}{Safemode} );
}
if ( $testarg eq 'MSwitch_Reset_EVT_CMD1_COUNT' ) {
delete( $hash->{READINGS}{EVT_CMD1_COUNT} );
}
if ( $testarg eq 'MSwitch_Reset_EVT_CMD2_COUNT' ) {
delete( $hash->{READINGS}{EVT_CMD2_COUNT} );
}
}
return undef;
}
@ -2254,8 +2279,31 @@ sub MSwitch_Notify($$) {
my $eventset = '0';
my $execids = "0";
my $foundcmd1 = 0;
my $foundcmd2 = 0;
my $showevents = AttrVal( $ownName, "MSwitch_generate_Events", 1 );
my $resetcmd1 = AttrVal( $ownName, "MSwitch_Reset_EVT_CMD1_COUNT", 0 );
my $resetcmd2 = AttrVal( $ownName, "MSwitch_Reset_EVT_CMD2_COUNT", 0 );
if ($resetcmd1 > 0 && ReadingsVal( $ownName, 'EVT_CMD1_COUNT', '0' ) >= $resetcmd1)
{
readingsSingleUpdate( $own_hash, "EVT_CMD1_COUNT", 0, $showevents );
}
if ($resetcmd2 > 0 && ReadingsVal( $ownName, 'EVT_CMD2_COUNT', '0' ) >= $resetcmd1)
{
readingsSingleUpdate( $own_hash, "EVT_CMD2_COUNT", 0, $showevents );
}
#readingsSingleUpdate( $own_hash, "trigdev0", 'anfang ', 1 ); # nur zu testzwecken
# nur abfragen für eigenes Notify
@ -2434,6 +2482,11 @@ sub MSwitch_Notify($$) {
my $activecount = 0;
my $anzahl;
EVENT: foreach my $event (@eventscopy) {
#MSwitch_LOG( $ownName, 0, "$ownName: event -> $event " );
$own_hash->{eventsave} = 'unsaved';
MSwitch_LOG( $ownName, 5,
"$ownName: eingehendes Event -> "
@ -2548,6 +2601,7 @@ sub MSwitch_Notify($$) {
my $testvar = '';
my $check = 0;
#test auf zweige cmd1/2 and switch MSwitch on/off
if ( $triggeron ne 'no_trigger' ) {
MSwitch_LOG( $ownName, 6,
@ -2560,6 +2614,7 @@ sub MSwitch_Notify($$) {
if ( $testvar ne 'undef' ) {
$set = $testvar;
$check = 1;
$foundcmd1 = 1;
$trigevent = $eventcopy;
#readingsSingleUpdate( $own_hash, "incomming", $eventcopy, 0 );
@ -2579,6 +2634,7 @@ sub MSwitch_Notify($$) {
if ( $testvar ne 'undef' ) {
$set = $testvar;
$check = 1;
$foundcmd2 = 1;
$trigevent = $eventcopy;
#readingsSingleUpdate( $own_hash, "incomming", $eventcopy, 0 );
@ -2587,6 +2643,10 @@ sub MSwitch_Notify($$) {
"$ownName: checktrigger ergebniss -> " . $testvar );
}
#test auf zweige cmd1/2 and switch MSwitch on/off ENDE
#test auf zweige cmd1/2 only
@ -2601,7 +2661,7 @@ sub MSwitch_Notify($$) {
if ( $testvar ne 'undef' ) {
push @cmdarray, $own_hash . ',off,check,' . $eventcopy1;
$check = 1;
$foundcmd2 = 1;
}
MSwitch_LOG( $ownName, 6,
"$ownName: checktrigger ergebniss -> " . $testvar );
@ -2617,6 +2677,7 @@ sub MSwitch_Notify($$) {
if ( $testvar ne 'undef' ) {
push @cmdarray, $own_hash . ',on,check,' . $eventcopy1;
$check = 1;
$foundcmd1 = 1;
}
MSwitch_LOG( $ownName, 6,
"$ownName: checktrigger ergebniss -> " . $testvar );
@ -2675,6 +2736,51 @@ sub MSwitch_Notify($$) {
}
}
#foundcmd1/2
if( $foundcmd1 eq "1" && AttrVal( $ownName, "MSwitch_Reset_EVT_CMD1_COUNT" ,'undef') ne 'undef')
{
my $inhalt = ReadingsVal( $ownName, 'EVT_CMD1_COUNT', '0' );
if ($resetcmd1 == 0 )
{
$inhalt++;
readingsSingleUpdate( $own_hash, "EVT_CMD1_COUNT", $inhalt, $showevents );
}
elsif ($resetcmd1 > 0 && $inhalt < $resetcmd1)
{
$inhalt++;
readingsSingleUpdate( $own_hash, "EVT_CMD1_COUNT", $inhalt, $showevents );
}
}
#MSwitch_LOG( $ownName, 0, "$ownName: cmdcount erreicht -> $foundcmd1 - $foundcmd2 " );
if( $foundcmd2 eq "1" && AttrVal( $ownName, "MSwitch_Reset_EVT_CMD2_COUNT" ,'undef') ne 'undef')
{
my $inhalt = ReadingsVal( $ownName, 'EVT_CMD2_COUNT', '0' );
if ($resetcmd2 == 0 )
{
$inhalt++;
readingsSingleUpdate( $own_hash, "EVT_CMD2_COUNT", $inhalt, $showevents );
}
elsif ($resetcmd2 > 0 && $inhalt < $resetcmd2)
{
$inhalt++;
readingsSingleUpdate( $own_hash, "EVT_CMD2_COUNT", $inhalt, $showevents );
}
}
#ausführen aller cmds in @cmdarray nach triggertest aber vor conditiontest
#my @cmdarray1; #enthält auszuführende befehle nach conditiontest
#schaltet zweig 3 und 4
@ -5975,6 +6081,10 @@ sub MSwitch_Exec_Notif($$$$$) {
$out = $devicedetails{$ekey};
}
# MSwitch_LOG( $name, 0,"$name: delaymode -> " . $delaymode ." - ".$device );
if ( $delaymode eq '1' ) {
MSwitch_Delete_Delay( $hash, $device );
}
@ -6537,6 +6647,12 @@ sub MSwitch_checkcondition($$$) {
$condition =~ s/\[\$EVTPART2\]/"\$EVTPART2"/g;
$condition =~ s/\[\$EVTPART3\]/"\$EVTPART3"/g;
$condition =~ s/\[\$EVT_CMD1_COUNT\]/"\$EVT_CMD1_COUNT"/g;
$condition =~ s/\[\$EVT_CMD2_COUNT\]/"\$EVT_CMD2_COUNT"/g;
MSwitch_LOG( $name, 6,
"$name: Checkcondition - Parameter condition -> " . $condition );
MSwitch_LOG( $name, 6,
@ -6666,6 +6782,15 @@ sub MSwitch_checkcondition($$$) {
$condition =~ s/\$EVTPART2/$evtparts[1]/ig;
$condition =~ s/\$EVTPART3/$evtparts[2]/ig;
my $evtcmd1 = ReadingsVal( $name, 'EVT_CMD1_COUNT', '0' );
my $evtcmd2 = ReadingsVal( $name, 'EVT_CMD2_COUNT', '0' );
$condition =~ s/\$EVT_CMD1_COUNT/$evtcmd1/ig;
$condition =~ s/\$EVT_CMD2_COUNT/$evtcmd2/ig;
MSwitch_LOG( $name, 5, "condition: " . $condition );
######################################
$condition =~ s/{!\$we}/ !\$we /ig;