From 6dca6dd5493ca357d5e77935efed1ba6ca10184e Mon Sep 17 00:00:00 2001 From: Byte09 Date: Thu, 5 Dec 2019 04:24:17 +0000 Subject: [PATCH] 98_MSwitch.pm: some cleanups git-svn-id: https://svn.fhem.de/fhem/trunk@20659 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/98_MSwitch.pm | 522 +++++----------------------------------- 1 file changed, 63 insertions(+), 459 deletions(-) diff --git a/fhem/FHEM/98_MSwitch.pm b/fhem/FHEM/98_MSwitch.pm index 7278779ac..b1b4a37f1 100644 --- a/fhem/FHEM/98_MSwitch.pm +++ b/fhem/FHEM/98_MSwitch.pm @@ -25,8 +25,6 @@ # ################################################################# # Todo's: -# reading last_cmd fehlerhaft bei befehlen mit delay - fixed -# del delays kontrollieren - fixed #--------------------------------------------------------------- # # info sonderreadings @@ -49,17 +47,11 @@ ################################################################# - - - - - package main; use Time::Local; use strict; use warnings; use POSIX; - use SetExtensions; # Version ####################################################### @@ -269,11 +261,7 @@ sub MSwitch_Initialize($) { . $readingFnAttributes; $hash->{FW_addDetailToSummary} = 0; - - - - #. " MSwitch_Develop_Affected:textField-long" - #. " MSwitch_Develop_Trigger:textField-long" + } #################### sub MSwitch_Rename($) { @@ -282,8 +270,6 @@ sub MSwitch_Rename($) { my ( $new_name, $old_name ) = @_; my $hash_new = $defs{$new_name}; - - my $hashold = $defs{$new_name}{$old_name}; RemoveInternalTimer($hashold); Log3( $old_name, 0, "clear rename ! $old_name $new_name" ); @@ -294,9 +280,7 @@ sub MSwitch_Rename($) { RemoveInternalTimer($key); } delete( $hashold->{helper}{repeats} ); - - - + RemoveInternalTimer($hash_new); Log3( $old_name, 0, "clear rename ! $old_name $new_name" ); my $inhalt1 = $hash_new->{helper}{repeats}; @@ -307,16 +291,8 @@ sub MSwitch_Rename($) { } delete( $hash_new->{helper}{repeats} ); delete( $modules{MSwitch}{defptr}{$old_name} ); - - $modules{MSwitch}{defptr}{$new_name} = $hash_new; - #MSwitch_Createtimer($hash_new); return undef; - - - - - } ##################################### sub MSwitch_Shutdown($) { @@ -561,20 +537,13 @@ sub MSwitch_check_init($) { my $Name = $hash->{NAME}; Log3( $Name, 5, "start checkinit !" );#LOG my $oldtrigger = ReadingsVal( $Name, 'Trigger_device', 'undef' ); - #Log3( $Name, 0, "start checkinit ! oldtrigger: ".$oldtrigger );#LOG - #Log3( $Name, 0, "start checkinit ! NOTIFYDEF ".$hash->{NOTIFYDEV} );#LOG - #if ( $oldtrigger ne 'undef' && $hash->{NOTIFYDEV} ne $oldtrigger) if ( $oldtrigger ne 'undef') { $hash->{NOTIFYDEV} = $oldtrigger; readingsSingleUpdate( $hash, "Trigger_device", $oldtrigger, 0 ); } - #else{ - #$hash->{NOTIFYDEV} = 'no_trigger'; - #} } - #################### sub MSwitch_LoadHelper($) { my ($hash) = @_; @@ -583,9 +552,6 @@ sub MSwitch_LoadHelper($) { my $devhash = undef; my $cdev = ''; my $ctrigg = ''; - - #Log3( $Name, 0, "start Loadhelper $Name !" );#LOG - if ( $hash->{INIT} eq "def" ) { return; @@ -767,15 +733,8 @@ sub MSwitch_Define($$) { { $hash->{INIT} = 'fhem.save'; } - -#Log3( $name, 5, "start checkinitdone ".$init_done );#LOG - - if ( $init_done && !defined( $hash->{OLDDEF} ) ) - #if ( $init_done ) { - ## prüfe NOTIFYDEF - #Log3( $name, 0, "start checkinitdone wird ausgeführt ".$init_done );#LOG my $timecond = gettimeofday() + 5; InternalTimer( $timecond, "MSwitch_check_init", $hash ); } @@ -891,9 +850,6 @@ sub MSwitch_Get($$@) { return $ret; } #################### - - - my $KLAMMERFEHLER; my $CONDTRUE; my $CONDTRUE1; @@ -944,19 +900,6 @@ if (AttrVal( $name, 'MSwitch_Language',AttrVal( 'global', 'language', 'EN' ) ) e $SYSTEMZEIT="system time:"; $SCHALTZEIT="Switching times (at - commands)"; } - - - - - - - - - - - - - if ( $opt eq 'MSwitch_preconf' ) { @@ -1247,15 +1190,6 @@ sub MSwitch_AsyncOutput ($) { sub MSwitch_Set($@) { my ( $hash, $name, $cmd, @args ) = @_; MSwitch_LOG( $name, 5, "$name Set $cmd, @args " . __LINE__ ); - - #if ( ReadingsVal( $name, '.First_init', 'undef' ) ne 'done' ) - #{ - # unvollständige daten ergänzen - #Log3( $name, 0, "starte helper aus set " );#LOG - #Log3( $name, 0, "starte helper aus set " );#LOG - #MSwitch_LoadHelper($hash); - #} - #lösche saveddevicecmd MSwitch_del_savedcmds($hash); return "" if ( IsDisabled($name) && ( $cmd eq 'on' || $cmd eq 'off' ) );# Return without any further action if the module is disabled @@ -1316,7 +1250,6 @@ sub MSwitch_Set($@) { MSwitch_Check_Event( $hash, "MSwitch_self:".$cmd.":".$args[0] ) if defined $setlist{$cmd}; } - my %setlist; if ( !defined $args[0] ) { $args[0] = ''; } @@ -2209,17 +2142,13 @@ my %setlist; return; } - ################################################################## + ################################## my $update = ''; # unbedingt überarbeiten !!! my @testdetails =qw(_on _off _onarg _offarg _playback _record _timeon _timeoff _conditionon _conditionoff); my @testdetailsstandart =( 'no_action', 'no_action', '', '', 'nein', 'nein', 0, 0, '', '' ); ################################## -###################################################################### - - - #neu ausführung on/off if ( $cmd eq "off" || $cmd eq "on" ) { @@ -2245,8 +2174,7 @@ my %setlist; } ################################################### - - + ### neu if ( $delaymode eq '1' ) { @@ -2865,10 +2793,6 @@ sub MSwitch_Attr(@) { . " textField-long "; setDevAttrList($name, $attrzerolist); - - - #. " MSwitch_Develop_Affected:textField-long" - #. " MSwitch_Develop_Trigger:textField-long" } if ( $aName eq 'MSwitch_Mode' && $aVal eq 'Notify' ) @@ -3335,18 +3259,15 @@ delete( $own_hash->{helper}{history} );# lösche historyberechnung verschieben a if ( $triggerdevice eq "all_events" ) { $own_hash->{helper}{events}{'all_events'}{ $devName . ':' . $eventcopy } = "on"; - #$own_hash->{helper}{eventlog}{$zeit}=$devName . ':' . $eventcopy ; } else { $own_hash->{helper}{events}{$devName}{$eventcopy} = "on"; - #$own_hash->{helper}{eventlog}{$zeit}=$devName . ':' . $eventcopy; } } else { $own_hash->{helper}{events}{MSwitch_Self}{$eventcopy} = "on"; - #$own_hash->{helper}{eventlog}{$zeit}="MSitch_Self:". $eventcopy; } } @@ -3411,7 +3332,6 @@ delete( $own_hash->{helper}{history} );# lösche historyberechnung verschieben a if ( AttrVal( $ownName, "MSwitch_Selftrigger_always", 0 ) eq "1" && $incommingdevice eq "MSwitch_Self") { $eventcopy1 = "MSwitch_Self:$eventcopy"; - #Log3( $ownName, 0, $ownName." eventcopy1 : ".$eventcopy1 ); $eventcopy = $eventcopy1; } @@ -3421,7 +3341,6 @@ delete( $own_hash->{helper}{history} );# lösche historyberechnung verschieben a my $testvar = ''; my $check = 0; -#if ( $devicemode ne "Dummy") { #test auf zweige cmd1/2 and switch MSwitch on/off if ( $triggeron ne 'no_trigger' ) { @@ -3513,7 +3432,7 @@ delete( $own_hash->{helper}{history} );# lösche historyberechnung verschieben a $check = 1; $foundcmd1 = 1; } - } + } # speichert 20 events ab zur weiterne funktion ( funktionen ) # ändern auf bedarfschaltung @@ -3822,7 +3741,7 @@ my $EXECCMD; if (AttrVal( $Name, 'MSwitch_Language',AttrVal( 'global', 'language', 'EN' ) ) eq "DE") { - $MSDISTRIBUTORTEXT="Event zu ID Verteilung (einstellung über Attribut)"; + $MSDISTRIBUTORTEXT="Zuordnung Event/ID (einstellung über Attribut)"; $MSDISTRIBUTOREVENT="eingehendes Event"; $LOOPTEXT= "ACHTUNG: Der Safemodus hat eine Endlosschleife erkannt, welche zum Fhemabsturz führen könnte.
Dieses Device wurde automatisch deaktiviert ( ATTR 'disable') !
 "; $ATERROR="AT-Kommandos können nicht ausgeführt werden !"; @@ -3864,24 +3783,12 @@ if (AttrVal( $Name, 'MSwitch_Language',AttrVal( 'global', 'language', 'EN' ) ) e #################### - - - - - - - # lösche saveddevicecmd # - if ( ReadingsVal( $Name, '.First_init', 'undef' ) ne 'done' ) { MSwitch_LoadHelper($hash); } - - - - my $cmdfrombase = "0"; MSwitch_del_savedcmds($hash); @@ -4189,16 +4096,16 @@ if ( ReadingsVal( $Name, '.First_init', 'undef' ) ne 'done' ) ######################################### # SHOW # teste auf grössere PRIORITY als anzahl devices - # foreach (@testidsdev) - # { - # MSwitch_LOG( $Name, 5, "dev @testidsdev" ); - # my @testid = split( /#\[NF\]/, $_ ); - # my $x = 0; - # MSwitch_LOG( $Name, 5, "devfelder @testid" ); - # my $id = $testid[18]; - # MSwitch_LOG( $Name, 5, "id $id" ); - # $anzahl1 = $id if $id > $anzahl; - # } + foreach (@testidsdev) + { + MSwitch_LOG( $Name, 5, "dev @testidsdev" ); + my @testid = split( /#\[NF\]/, $_ ); + my $x = 0; + MSwitch_LOG( $Name, 5, "devfelder @testid" ); + my $id = $testid[18]; + MSwitch_LOG( $Name, 5, "id $id" ); + $anzahl1 = $id if $id > $anzahl; + } ################################# my $showfolgehtml = ""; @@ -4365,18 +4272,7 @@ if ( ReadingsVal( $Name, '.First_init', 'undef' ) ne 'done' ) { $errors = ''; } - - # my @tmparg = split( /of /, $errors ); - # if ( !defined $tmparg[1] ) { $tmparg[1] = "" } - # if ( $tmparg[1] ne '' ) - # { - # $errors = $tmparg[1]; - # } - # else - # { - # $errors = ''; - # } - + $errors = '|' . $errors; $errors =~ s/\| //g; $errors =~ s/\|//g; @@ -4777,13 +4673,9 @@ MS-HELPdelay my $cellhightexpert =$1."px"; my $cellhightdebug =$1."px"; - -# $extrakthtml =~m/(.*)/ ; $controlhtml=$1; $controlhtml=~ s/#/\n/g; - #MSwitch_LOG( $Name, 0, "HTML " . $controlhtml ); - # detailsatz in scalar laden my %savedetails = MSwitch_makeCmdHash($Name); @@ -4853,9 +4745,7 @@ $controlhtml=~ s/#/\n/g; $HELPexeccmd=""; $HELPdelay=""; } - - if ( $affecteddevices[0] ne 'no_device' ) { ####################### sortierungsblock @@ -4902,14 +4792,10 @@ $controlhtml=~ s/#/\n/g; "; - ########################## # $detailhtml .= $sortierung; ########################## - #my $detailhtmlold; - - my $alert; foreach (@affecteddevices) { @@ -5183,20 +5069,6 @@ $controlhtml=~ s/#/\n/g; . $savedetails{ $aktdevice . '_comment' } . ""; } - - - # my $rephide = "style='display:none;'"; - # my $rows = 7; - # if ( $hash->{INIT} eq 'define' ) - # { - # $rows = 2; - # } - - # if ( AttrVal( $Name, 'MSwitch_Expert', "0" ) eq '1' ) - # { - # $rephide = ''; - # $rows = 8; #8 - # } if ( $devicenamet ne 'FreeCmd' ) { @@ -5234,13 +5106,11 @@ $controlhtml=~ s/#/\n/g; "; - } else { # freecmd $savedetails{ $aktdevice . '_onarg' } =~ s/'/'/g; - $SET1 = ""; @@ -5258,7 +5128,6 @@ $controlhtml=~ s/#/\n/g; . "_on_sel'> "; } - ######################## ## block off #$devicename @@ -5301,16 +5170,15 @@ $controlhtml=~ s/#/\n/g; if ( AttrVal( $Name, 'MSwitch_Debug', "0" ) eq '1' ) { -$MSTEST1=""; + $MSTEST1=""; + + $MSTEST2=""; + } -$MSTEST2=""; -} - - } else { @@ -5336,18 +5204,15 @@ $MSTEST2=""; + $MSTEST1=""; -$MSTEST2=""; + $MSTEST2=""; -} - - - + } } } else @@ -5375,8 +5240,6 @@ $MSTEST2=" "; } - - if ( AttrVal( $Name, 'MSwitch_Debug', "0" ) eq '1' ) { $COND1check1=""; - - - - - } - #$aktdevicename - - - +#$aktdevicename #alltriggers if ( $hash->{INIT} ne 'define' ) @@ -5449,10 +5304,7 @@ $COND1check1=" " . $testtimestroff ); - - + if ( $testtimestroff eq "[:]"|| $testtimestroff eq "[\$:]" || $testtimestroff eq "::" ) { $timestroff = $savedetails{ $aktdevice . '_timeoff' }; #sekunden @@ -5524,16 +5376,6 @@ $COND1check1="delay with Cond-check immediately and delayed:"; $DELAYset1 .= ""; $DELAYset1 .= ""; @@ -5565,15 +5407,6 @@ $COND1check1="delay with Cond-check immediately and delayed:"; $DELAYset2 .= ""; $DELAYset2 .= ""; @@ -5601,9 +5434,7 @@ $COND1check1=""; - - - + } @@ -5621,12 +5452,6 @@ $COND1check1=""; + ######################## my $blocking = ''; $blocking = $hash->{helper}{savemodeblock}{blocking} if ( defined $hash->{helper}{savemodeblock}{blocking} ); - - # endlosschleife if ( $blocking eq 'on' ) { @@ -5835,8 +5645,6 @@ $detailhtml .= $modify;
 
"; } - - # debugmode if ( AttrVal( $Name, 'MSwitch_Debug', "0" ) eq '2' @@ -5867,10 +5675,7 @@ $detailhtml .= $modify;
"; } - - # einblendung wrong timespec - if ( defined $hash->{helper}{wrongtimespec} and $hash->{helper}{wrongtimespec} ne "" ) { $ret .= " @@ -5883,8 +5688,6 @@ $detailhtml .= $modify; $ret .= "
 
"; - - # use HH:MM
HH must be < 24
MM must be < 60
Timer werden nicht ausgeführt } if ( defined $hash->{helper}{wrongtimespeccond} and $hash->{helper}{wrongtimespeccond} ne "" ) @@ -5899,7 +5702,6 @@ $detailhtml .= $modify; $ret .= "
 
"; - #use HH:MM
HH must be < 24
MM must be < 60
Bedingung gilt immer als FALSCH } # einblendung info @@ -5914,11 +5716,6 @@ $detailhtml .= $modify; "; } - - - - - # anpassung durch configeinspielung if ( ReadingsVal( $Name, '.change', 'undef' ) ne "undef" ) { @@ -6233,8 +6030,6 @@ my $MSHidedummy=""; my $MSHidewhitelist="id='triggerwhitelist'"; my $MScheckcondition=""; - # my $inhalt2 = "execute 'cmd1' only"; - # my $inhalt3 = "execute 'cmd2' only"; my $inhalt5 = "switch $Name on and execute cmd1"; my $displaynot = ''; my $displayntog = ''; @@ -6245,8 +6040,7 @@ my $MScheckcondition=""; { $MShidefull="style='display:none;'"; $displaynot = "style='display:none;'"; - # $inhalt2 = $help . "execute 'cmd1'"; - # $inhalt3 = $help . "execute 'cmd2'"; + } @@ -6256,13 +6050,6 @@ my $MScheckcondition=""; $inhalt5 = "toggle $Name and execute cmd1/cmd2"; } - # if ( AttrVal( $Name, 'MSwitch_Mode', 'Notify' ) eq "Dummy" ) - # { - # $inhalt2 = $help . "execute 'cmd1'"; - # $inhalt3 = $help . "execute 'cmd2'"; - # } - - if ( AttrVal( $Name, 'MSwitch_Mode', 'Notify' ) ne "Dummy" ) { $MSHidedummy=""; @@ -6284,7 +6071,6 @@ my $MScheckcondition=""; . ReadingsVal( $Name, '.Trigger_Whitelist', '' ) . "' onClick=\"javascript:bigwindow(this.id);\" >"; - $MSonand1=""; $MSonand2="" .$triggerhtml. "
"; - - - - + # trigger ende #################### @@ -6635,20 +6418,14 @@ my($wert1,$wert2) = split (/->/,$_); $triggerdetailhtml =~ s/$wert1/$wert2/g; } - $ret.="
".$triggerdetailhtml."

"; - ################################################################# - - # id event bridge my $idmode = AttrVal( $Name, 'MSwitch_Event_Id_Distributor', 'undef' ); - - - + if ( $hash->{helper}{eventtoid} && $idmode ne "undef" && $expertmode eq "1" ) @@ -6673,11 +6450,8 @@ $triggerdetailhtml =~ s/$wert1/$wert2/g; ############################################################### # id event bridge neu - - ############################################################### - #auswfirst MSwitch_Selftrigger_always my $style = ""; if ( AttrVal( $Name, 'MSwitch_Mode', 'Notify' ) eq "Dummy" && AttrVal( $Name, 'MSwitch_Selftrigger_always', '0' ) ne "1") @@ -6692,8 +6466,6 @@ $triggerdetailhtml =~ s/$wert1/$wert2/g; "; } - - my $MSSAVED=""; my $MSSELECT=""; my $MSHELP=""; @@ -6711,6 +6483,7 @@ all devicecomands saved->alle Devicekommandos gespeichert modify Devices->Devices speichern show greater list->grosses Auswahlfeld reload->neu laden +affected devices->zu schaltende Geräte end:textersetzung:ger -->