diff --git a/FHEM/26_tahoma.pm b/FHEM/26_tahoma.pm index 4337e87e7..f1064f3d2 100644 --- a/FHEM/26_tahoma.pm +++ b/FHEM/26_tahoma.pm @@ -51,6 +51,7 @@ # 2017-10-08 V 0216 group definition added # 2018-05-10 V 0217 disable activated on devices # 2018-05-25 V 0218 keepalive of http connection corrected +# 2018-06-01 V 0219 new Attributes for time interval of getEvents, getStates and refreshAllStates package main; @@ -74,6 +75,8 @@ my $hash_; sub tahoma_Initialize($) { my ($hash) = @_; + my $name = $hash->{NAME}; + Log3 $name, 3, "$name: tahoma_Initialize"; $hash->{DefFn} = "tahoma_Define"; $hash->{NOTIFYDEV} = "global"; @@ -87,6 +90,9 @@ sub tahoma_Initialize($) "debug:1 ". "disable:1 ". "interval ". + "intervalRefresh ". + "intervalEvents ". + "intervalStates ". "logfile ". "url ". "placeClasses ". @@ -120,10 +126,12 @@ my $groupId = 123001; sub tahoma_Define($$) { my ($hash, $def) = @_; + my $name = $hash->{NAME}; + Log3 $name, 3, "$name: tahoma_Define: def=$def"; my @a = split("[ \t][ \t]*", $def); - my $ModuleVersion = "0218"; + my $ModuleVersion = "0219"; my $subtype; my $name = $a[0]; @@ -136,7 +144,7 @@ sub tahoma_Define($$) $hash->{device} = $device; $hash->{fid} = $fid; - $hash->{INTERVAL} = 0; + #$hash->{INTERVAL} = 0; my $d = $modules{$hash->{TYPE}}{defptr}{"$fid"}; return "device $device already defined as $d->{NAME}" if( defined($d) && $d->{NAME} ne $name ); @@ -152,13 +160,13 @@ sub tahoma_Define($$) $hash->{oid} = $oid; $hash->{fid} = $fid; - $hash->{INTERVAL} = 0; + #$hash->{INTERVAL} = 0; my $d = $modules{$hash->{TYPE}}{defptr}{"$fid"}; return "place oid $oid already defined as $d->{NAME}" if( defined($d) && $d->{NAME} ne $name ); $modules{$hash->{TYPE}}{defptr}{"$fid"} = $hash; - + } elsif( $a[2] eq "GROUP" && @a == 4 ) { $subtype = "GROUP"; @@ -169,7 +177,7 @@ sub tahoma_Define($$) $hash->{oid} = $oid; $hash->{fid} = $fid; - $hash->{INTERVAL} = 0; + #$hash->{INTERVAL} = 0; my $d = $modules{$hash->{TYPE}}{defptr}{"$fid"}; return "group oid $oid already defined as $d->{NAME}" if( defined($d) && $d->{NAME} ne $name ); @@ -185,7 +193,7 @@ sub tahoma_Define($$) $hash->{oid} = $oid; $hash->{fid} = $fid; - $hash->{INTERVAL} = 0; + #$hash->{INTERVAL} = 0; my $d = $modules{$hash->{TYPE}}{defptr}{"$fid"}; return "scene oid $oid already defined as $d->{NAME}" if( defined($d) && $d->{NAME} ne $name ); @@ -203,8 +211,10 @@ sub tahoma_Define($$) $hash->{helper}{username} = $username; $hash->{helper}{password} = $password; $hash->{BLOCKING} = 0; - $hash->{INTERVAL} = 0; $hash->{VERSION} = $ModuleVersion; + $hash->{getEventsInterval} = 2; + $hash->{refreshStatesInterval} = 120; + $hash->{getStatesInterval} = 0; } else { return "Usage: define tahoma device\ @@ -415,7 +425,7 @@ sub tahoma_readStatusTimer($) RemoveInternalTimer($hash); my ($seconds) = gettimeofday(); - $hash->{refreshStateTimer} = $seconds + 10 if ( (!defined($hash->{refreshStateTimer})) || (!$hash->{logged_in}) ); + $hash->{refreshStatesTimer} = $seconds + 10 if ( (!defined($hash->{refreshStatesTimer})) || (!$hash->{logged_in}) ); if( $hash->{request_active} ) { Log3 $name, 3, "$name: request active"; @@ -437,24 +447,31 @@ sub tahoma_readStatusTimer($) $timeinfo = "tahoma_startup"; if ( $hash->{startup_done} ) { tahoma_getStates($hash) ; - $hash->{refreshStateTimer} = $seconds + $hash->{INTERVAL}; + $hash->{refreshStatesTimer} = $seconds + $hash->{refreshStatesInterval}; $timeinfo = "tahoma_getStates"; } } - elsif( ($seconds < $hash->{refreshStateTimer}) || ($hash->{INTERVAL} <= 0) ) + elsif( ($seconds >= $hash->{refreshStatesTimer}) && ($hash->{refreshStatesInterval} > 0) ) + { + Log3 $name, 4, "$name: refreshing all states"; + tahoma_refreshAllStates($hash); + $hash->{refreshStatesTimer} = $seconds + $hash->{refreshStatesInterval}; + $timeinfo = "tahoma_refreshAllStates"; + } + elsif( ($seconds >= $hash->{getStatesTimer}) && ($hash->{getStatesInterval} > 0) ) + { + Log3 $name, 4, "$name: get all states"; + tahoma_getStates($hash); + $hash->{getStatesTimer} = $seconds + $hash->{getStatesInterval}; + $timeinfo = "tahoma_getStates"; + } + elsif( ($seconds >= $hash->{getEventsTimer}) || ($hash->{getEventsInterval} <= 0) ) { Log3 $name, 4, "$name: refreshing event"; tahoma_getEvents($hash); + $hash->{getEventsTimer} = $seconds + $hash->{getEventsInterval}; $timeinfo = "tahoma_getEvents"; } - else - { - Log3 $name, 4, "$name: refreshing state"; - tahoma_refreshAllStates($hash); - tahoma_getStates($hash); - $hash->{refreshStateTimer} = $seconds + $hash->{INTERVAL}; - $timeinfo = "tahoma_refreshAllStates tahoma_getStates"; - } my $timedelta = time -$timestart; if ($timedelta > 0.5) @@ -476,7 +493,7 @@ sub tahoma_connect($) tahoma_login($hash); my ($seconds) = gettimeofday(); - $hash->{refreshStateTimer} = $seconds + 10; + $hash->{refreshStatesTimer} = $seconds + 10; tahoma_readStatusTimer($hash); } @@ -1068,7 +1085,7 @@ sub tahoma_parseGetEvents($$) { my($hash, $json) = @_; my $name = $hash->{NAME}; - Log3 $name, 5, "$name: tahoma_parseGetEvent"; + Log3 $name, 5, "$name: tahoma_parseGetEvents"; $hash->{refresh_event} = $json; @@ -1333,7 +1350,8 @@ sub tahoma_Get($$@) if( $cmd eq "updateAll" ) { my ($seconds) = gettimeofday(); - $hash->{refreshStateTimer} = $seconds; + $hash = $hash->{IODev} if (defined ($hash->{IODev})); + $hash->{refreshStatesTimer} = $seconds; return undef; } @@ -1418,12 +1436,26 @@ sub tahoma_Set($$@) } if( $hash->{SUBTYPE} eq "ACCOUNT") { - $list = "cancel:noArg"; + $list = "cancel:noArg reset:noArg refreshAllStates:noArg getStates:noArg"; if( $cmd eq "cancel" ) { tahoma_cancelExecutions($hash); return undef; } + elsif( $cmd eq "reset" ) { + HttpUtils_Close($hash); + $hash->{logged_in} = undef; + $hash->{loginRetryTimer} = undef; + return undef; + } + elsif( $cmd eq "refreshAllStates" ) { + tahoma_refreshAllStates($hash); + return undef; + } + elsif( $cmd eq "getStates" ) { + tahoma_getStates($hash); + return undef; + } } return "Unknown argument $cmd, choose one of $list"; @@ -1433,13 +1465,38 @@ sub tahoma_Attr($$$) { my ($cmd, $name, $attrName, $attrVal) = @_; + Log3 $name, 3, "$name: tahoma_Attr $cmd $attrName $attrVal"; + my $orig = $attrVal; if( $attrName eq "interval" ) { my $hash = $defs{$name}; + return "Attribut 'interval' only usable for type ACCOUNT" if $hash->{SUBTYPE} ne "ACCOUNT"; + $attrVal = defined $attrVal ? int($attrVal) : 0; $attrVal = int($attrVal); - $attrVal = 60*5 if ($attrVal < 60*5 && $attrVal != 0); - $hash->{INTERVAL} = $attrVal; + $attrVal = 120 if ($attrVal < 120 && $attrVal != 0); + $hash->{refreshStatesInterval} = $attrVal ? $attrVal / 2 : 120; + $hash->{getStatesInterval} = $attrVal; + } elsif( $attrName eq "intervalRefresh" ) { + my $hash = $defs{$name}; + return "Attribut 'intervalRefresh' only usable for type ACCOUNT" if $hash->{SUBTYPE} ne "ACCOUNT"; + $attrVal = defined $attrVal ? int($attrVal) : 120; + $attrVal = 60 if ($attrVal < 60 && $attrVal != 0); + $hash->{refreshStatesInterval} = $attrVal; + } elsif( $attrName eq "intervalStates" ) { + my $hash = $defs{$name}; + return "Attribut 'intervalStates' only usable for type ACCOUNT" if $hash->{SUBTYPE} ne "ACCOUNT"; + $attrVal = defined $attrVal ? int($attrVal) : 0; + $attrVal = int($attrVal); + $attrVal = 120 if ($attrVal < 120 && $attrVal != 0); + $hash->{getStatesInterval} = $attrVal; + } elsif( $attrName eq "intervalEvents" ) { + my $hash = $defs{$name}; + return "Attribut 'intervalEvents' only usable for type ACCOUNT" if $hash->{SUBTYPE} ne "ACCOUNT"; + $attrVal = defined $attrVal ? int($attrVal) : 2; + $attrVal = int($attrVal); + $attrVal = 2 if ($attrVal < 2 && $attrVal != 0); + $hash->{getEventsInterval} = $attrVal; } elsif( $attrName eq "disable" ) { my $hash = $defs{$name}; RemoveInternalTimer($hash); @@ -1449,13 +1506,19 @@ sub tahoma_Attr($$$) } } elsif( $attrName eq "blocking" ) { my $hash = $defs{$name}; + return "Attribut 'blocking' only usable for type ACCOUNT" if $hash->{SUBTYPE} ne "ACCOUNT"; + $attrVal = defined $attrVal ? int($attrVal) : 0; $hash->{BLOCKING} = $attrVal; } elsif( $attrName eq "placeClasses" ) { my $hash = $defs{$name}; - $hash->{inClass} = $attrVal if $hash->{SUBTYPE} eq "PLACE"; + return "Attribut 'placeClasses' only usable for type PLACE" if $hash->{SUBTYPE} ne "PLACE"; + $attrVal = defined $attrVal ? $attrVal : 'RollerShutter'; + $hash->{inClass} = $attrVal; } elsif ( $attrName eq "levelInvert" ) { my $hash = $defs{$name}; + return "Attribut 'placeClasses' only usable for type DEVICE" if $hash->{SUBTYPE} ne "DEVICE"; + $attrVal = defined $attrVal ? int($attrVal) : 0; my $device = tahoma_getDeviceDetail( $hash, $hash->{device} ); $device->{levelInvert} = $attrVal if (defined $device); } @@ -1611,7 +1674,7 @@ sub tahoma_decrypt($)

tahoma