From 2cab60f7f8134e82a1f7f46a9bca71a989518f3a Mon Sep 17 00:00:00 2001 From: xusader <> Date: Sun, 3 Aug 2014 18:33:15 +0000 Subject: [PATCH] git-svn-id: https://svn.fhem.de/fhem/trunk@6356 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/70_PushNotifier.pm | 200 +++++++++++++++++++++++++++++++++++ 1 file changed, 200 insertions(+) create mode 100644 fhem/FHEM/70_PushNotifier.pm diff --git a/fhem/FHEM/70_PushNotifier.pm b/fhem/FHEM/70_PushNotifier.pm new file mode 100644 index 000000000..f1e9be013 --- /dev/null +++ b/fhem/FHEM/70_PushNotifier.pm @@ -0,0 +1,200 @@ +############################################### +#$Id: 70_PushNotifier.pm 2014-07-22 11:07:00 xusader +# +# download client-app http://pushnotifier.de/apps/ +# create account http://pushnotifier.de/login/ +# get apiToken from http://gidix.de/setings/api/ and add a new app +# get appToken with: +# curl -s -F apiToken="apiToken=your apiToken" -F username="your username" -F password="your password" http://a.pushnotifier.de/1/login +# get deviceID with: +# curl -s -F "apiToken=your apiToken" -F "appToken=your appToken" http://a.pushnotifier.de/1/getDevices +# +# Define example: +# define yourname PushNotifier apiToken appToken appname deviceID +# +# notify example: +# define LampON notify Lamp:on set yourDefineName message Your message! +# + +package main; +use LWP::UserAgent; + +sub +PushNotifier_Initialize($) +{ + my ($hash) = @_; + + $hash->{DefFn} = "PushNotifier_Define"; + $hash->{SetFn} = "PushNotifier_Set"; + +} + +##################################### +sub +PushNotifier_Define($$) +{ + my ($hash, $def) = @_; + my @args = split("[ \t]+", $def); + + my ($name, $type, $apiToken, $appToken, $app, $deviceID) = @args; + + $hash->{STATE} = 'Initialized'; + + if(defined($apiToken) && defined($appToken)&& defined($app)&& defined($deviceID)) { + $hash->{apiToken} = $apiToken; + $hash->{appToken} = $appToken; + $hash->{app} = $app; + $hash->{deviceID} = $deviceID; + + return undef; + } +} + +##################################### +sub +PushNotifier_Set($@) +{ + my ($hash, $name, $cmd, @a) = @_; + my %sets = ('message' => 1); + if(!defined($sets{$cmd})) { + return "Unknown argument $cmd, choose one of " . join(" ", sort keys %sets); + } + return PushNotifier_Send_Message($hash, @a); +} +##################################### +sub +PushNotifier_Send_Message#($@) +{ + my $hash = shift; + my $msg = join(" ", @_); + my $apiToken = $hash->{apiToken}; + my $appToken = $hash->{appToken}; + my $app = $hash->{app}; + my $deviceID = $hash->{deviceID}; + + my %settings = ( + 'apiToken' => $apiToken, + 'appToken' => $appToken, + 'app' => $app, + 'deviceID' => $deviceID, + 'type' => 'MESSAGE', + 'content' => "$msg" + ); + + my $response = LWP::UserAgent->new()->post("http://a.pushnotifier.de/1/sendToDevice", \%settings); + + my $error_chk = $response->as_string; + + if($error_chk =~ m/"status":"ok"/) { + return "OK"; + } + else + { + return $error_chk; + } + +} + +1; + +############################################################################### + +=pod +=begin html + + +

PushNotifier

+ + +=end html +=begin html_DE + + +

PushNotifier

+ + +=end html_DE +=cut +