From bf6cfad12d55db39c778f4fab2f289faa02c1b52 Mon Sep 17 00:00:00 2001 From: fladdy <> Date: Sat, 15 Sep 2012 13:17:23 +0000 Subject: [PATCH] Fix: switching between internal and full activation or vice versa requires Unset first git-svn-id: https://svn.fhem.de/fhem/trunk@1848 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/contrib/58_SecvestIP.pm | 42 ++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/fhem/contrib/58_SecvestIP.pm b/fhem/contrib/58_SecvestIP.pm index e3056e94c..fdf3f5309 100644 --- a/fhem/contrib/58_SecvestIP.pm +++ b/fhem/contrib/58_SecvestIP.pm @@ -1,18 +1,29 @@ ##################################################################### # # # SecvestIP.pm written by Peter J. Flathmann # -# Version 0.1, 2012-09-07 # -# Version 0.2, 2012-09-13 # +# Version 0.3, 2012-09-15 # # SecvestIP firmware version 2.3.4 # # # +# ----------------------------------------------------------------- # # # -# Usage: define SecvestIP # +# Usage: # # # +# define SecvestIP # +# set # # # # Example: # # # # define EMA SecvestIP secvestip admin geheimesKennwort # # attr EMA webCmd state # +# set EMA Set # +# # +# ----------------------------------------------------------------- # +# # +# Possible states: # +# # +# Set: activated # +# PartSet: internally activated # +# Unset: deactivated # # # ##################################################################### @@ -52,11 +63,11 @@ sub SecvestIP_Get($) { Password => $hash->{PASSWORD}} ); + # Get SecvestIP state $response = $agent->get ($url.'getMode.cgi?ts='.time().'&Action=AudioAlarm&Source=Webpage'); my @pairs = split(/\s+/,$response->content); my @state = split('=',$pairs[0]); - $hash->{STATE} = $state[1]; return undef; @@ -65,13 +76,13 @@ sub SecvestIP_Get($) { sub SecvestIP_Set($$$) { my ($hash, $name ,$cmd) = @_; + + return "Unknown argument $cmd, choose one of state:Set,Unset,PartSet" if ($cmd eq "?"); Log 1, "SecvestIP: Set $name $cmd"; - if ("?" eq $cmd) { - SecvestIP_Get($hash); - return "Unknown argument $cmd, choose one of state:Set,Unset,PartSet"; - } + # Get current SecvestIP state + SecvestIP_Get($hash); my $url = 'http://'.$hash->{HOST}.'/'; @@ -86,13 +97,16 @@ sub SecvestIP_Set($$$) { UserName => $hash->{USER}, Password => $hash->{PASSWORD}} ); - + + # switching between internal and full activation or vice versa requires Unset first + if ($cmd eq "Set" and $hash->{STATE} eq "PartSet" or $cmd eq "PartSet" and $hash->{STATE} eq "Set") { + Log 1, "SecvestIP: switching from $hash->{STATE} to $cmd"; + $response = $agent->get ($url.'setMode.cgi?Mode=Unset&Source=Webpage&ts='.time() ); + sleep(2); # wait a moment to avoid confusing SecvestIP's web interface + } + $response = $agent->get ($url.'setMode.cgi?Mode='.$cmd.'&Source=Webpage&ts='.time() ); - - readingsBeginUpdate($hash); - readingsUpdate($hash, 'state', $cmd); - readingsEndUpdate($hash, 1); - $hash->{STATE} = $cmd; + SecvestIP_Get($hash); return undef; }