From 8e81ef6964ce95edc8255b4d1705ef3081e2f89f Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Sun, 9 Sep 2012 08:44:02 +0000 Subject: [PATCH] By Peter git-svn-id: https://svn.fhem.de/fhem/trunk@1832 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/contrib/58_SecvestIP.pm | 118 +++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 fhem/contrib/58_SecvestIP.pm diff --git a/fhem/contrib/58_SecvestIP.pm b/fhem/contrib/58_SecvestIP.pm new file mode 100644 index 000000000..844e70a69 --- /dev/null +++ b/fhem/contrib/58_SecvestIP.pm @@ -0,0 +1,118 @@ +##################################################################### +# # +# SecvestIP.pm written by Peter J. Flathmann # +# Version 0.1, 2012-09-07 # +# SecvestIP firmware version 2.3.4 # +# # +# # +# Usage: define SecvestIP # +# # +# # +# Example: # +# # +# define EMA SecvestIP secvestip admin geheimesKennwort # +# # +# define Alarmanlage dummy # +# attr Alarmanlage alias SecvestIP # +# attr Alarmanlage eventMap on:on off:off # +# # +# define AlarmanlageScharf notify Alarmanlage:on set EMA Set # +# define AlarmanlageUnscharf notify Alarmanlage:off set EMA Unset # +# # +##################################################################### + +package main; +use strict; +use warnings; +use POSIX; +use LWP::UserAgent; +use HTTP::Cookies; + +sub +SecvestIP_Initialize($) +{ + my ($hash) = @_; + + $hash->{DefFn} = "SecvestIP_Define"; + $hash->{SetFn} = "SecvestIP_Set"; + $hash->{GetFn} = "SecvestIP_Get"; +} + +sub SecvestIP_Get($@) { + + my ($hash,@a) = @_; + + my $url = 'http://'.$hash->{HOST}.'/'; + + my $agent = LWP::UserAgent->new( + cookie_jar => HTTP::Cookies->new, + requests_redirectable => [ 'GET', 'HEAD', 'POST' ] + ); + + # Login + my $response = $agent->post( $url."login.cgi", { + Language => 'deutsch', + UserName => $hash->{USER}, + Password => $hash->{PASSWORD}} + ); + + $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; +} + +sub SecvestIP_Set($$$) { + + my ($hash, $name ,$cmd) = @_; + + Log 1, "SecvestIP: Set $name $cmd"; + return "Unknown argument $cmd, choose one of Set Unset PartSet" if ("?" eq $cmd); + + my $url = 'http://'.$hash->{HOST}.'/'; + + my $agent = LWP::UserAgent->new( + cookie_jar => HTTP::Cookies->new, + requests_redirectable => [ 'GET', 'HEAD', 'POST' ] + ); + + # Login + my $response = $agent->post( $url."login.cgi", { + Language => 'deutsch', + UserName => $hash->{USER}, + Password => $hash->{PASSWORD}} + ); + + $response = $agent->get ($url.'setMode.cgi?Mode='.$cmd.'&Source=Webpage&ts='.time() ); + $hash->{STATE} = $cmd; + + return undef; +} + +sub SecvestIP_Define($$) { + + my ($hash, $def) = @_; + + Log 1, "SecvestIP: define $def"; + + my @a = split("[ \t][ \t]*", $def); + + return "syntax: define SecvestIP " if (int(@a) != 5); + + $hash->{STATE} = "Initialized"; + + $hash->{NAME} = $a[0]; + $hash->{HOST} = $a[2]; + $hash->{USER} = $a[3]; + $hash->{PASSWORD} = $a[4]; + + SecvestIP_Get($hash); + + return undef; +} + +1;