2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-14 16:01:53 +00:00

70_PushNotifier: added line break in Messages (xusader)

git-svn-id: https://svn.fhem.de/fhem/trunk@7229 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
xusader 2014-12-16 16:55:31 +00:00
parent d5380ab007
commit 90ceb5f45a

@ -1,5 +1,5 @@
############################################### ###############################################
#$Id: 70_PushNotifier.pm 2014-12-11 13:28:00 xusader #$Id: 70_PushNotifier.pm 2014-12-16 17:00:00 xusader
# #
# download client-app http://pushnotifier.de/apps/ # download client-app http://pushnotifier.de/apps/
# create account http://pushnotifier.de/login/ # create account http://pushnotifier.de/login/
@ -43,29 +43,32 @@ PushNotifier_Define($$)
$hash->{passwd} = $passwd; $hash->{passwd} = $passwd;
$hash->{deviceID} = $deviceID; $hash->{deviceID} = $deviceID;
my %getAppToken = ( my $responseAT = LWP::UserAgent->new()->post("http://a.pushnotifier.de/1/login",
'apiToken' => $apiToken, ['apiToken' => $apiToken,
'username' => $user, 'username' => $user,
'password' => $passwd); 'password' => $passwd]);
my $responseAT = LWP::UserAgent->new()->post("http://a.pushnotifier.de/1/login", \%getAppToken);
my $strg_chkAT = $responseAT->as_string; my $strg_chkAT = $responseAT->as_string;
$strg_chkAT =~ m{"appToken":"([\w]+)}; $strg_chkAT =~ m{"appToken":"([\w]+)};
my $appToken = $1; my $appToken = $1;
$hash->{appToken} = $appToken; $hash->{appToken} = $appToken;
#my $name = $hash->{NAME}; my $responseID = LWP::UserAgent->new()->post("http://a.pushnotifier.de/1/getDevices",
#Log3 $name, 2, $appToken; ['apiToken' => $apiToken,
'appToken' => $appToken]);
my %getDevices = (
'apiToken' => $apiToken,
'appToken' => $appToken);
my $responseID = LWP::UserAgent->new()->post("http://a.pushnotifier.de/1/getDevices", \%getDevices);
my $strg_chkID = $responseID->as_string; my $strg_chkID = $responseID->as_string;
$strg_chkID =~ m/":([\d].*)/; $strg_chkID =~ s/[-"{}_]//g;
my $devices = $1;
$hash->{devices} = $devices; $re1='.*?';
$re2='(\\[.*?\\])';
$re=$re1.$re2;
if ($strg_chkID =~ m/$re/is)
{
$sbraces1=$1;
my $devices = $sbraces1;
$hash->{devices} = $devices;
}
return undef; return undef;
} }
@ -75,13 +78,12 @@ PushNotifier_Define($$)
sub sub
PushNotifier_Set($@) PushNotifier_Set($@)
{ {
my ($hash, $name, $cmd, @a) = @_; my ($hash, $name, $cmd, @args) = @_;
my %sets = ('message' => 1); my %sets = ('message' => 1);
if(!defined($sets{$cmd})) { if(!defined($sets{$cmd})) {
return "Unknown argument $cmd, choose one of " . join(" ", sort keys %sets); return "Unknown argument ". $cmd . ", choose one of " . join(" ", sort keys %sets);
} }
return PushNotifier_Send_Message($hash, @args);
return PushNotifier_Send_Message($hash, , @a);
} }
##################################### #####################################
sub sub
@ -89,35 +91,25 @@ PushNotifier_Send_Message
{ {
my $hash = shift; my $hash = shift;
my $msg = join(" ", @_); my $msg = join(" ", @_);
$msg =~ s/\_/\n/g;
my $apiToken = $hash->{apiToken}; my $response = LWP::UserAgent->new()->post('http://a.pushnotifier.de/1/sendToDevice',
my $app = $hash->{app}; ['apiToken' => $hash->{apiToken},
my $user = $hash->{user}; 'appToken' => $hash->{appToken},
my $passwd = $hash->{passwd}; 'app' => $hash->{app},
my $appToken = $hash->{appToken}; 'deviceID' => $hash->{deviceID},
my $deviceID = $hash->{deviceID};
my %settings = (
'apiToken' => $apiToken,
'appToken' => $appToken,
'app' => $app,
'deviceID' => $deviceID,
'type' => 'MESSAGE', 'type' => 'MESSAGE',
'content' => "$msg" 'content' => "$msg"]);
);
my $response = LWP::UserAgent->new()->post("http://a.pushnotifier.de/1/sendToDevice", \%settings); my $error_chk = $response->as_string;
my $error_chk = $response->as_string;
if($error_chk =~ m/"status":"ok"/) { if($error_chk =~ m/"status":"ok"/) {
return "OK"; return "OK!\n\n$msg";
} }
else else
{ {
return $error_chk; return $error_chk;
} }
} }
1; 1;
@ -162,6 +154,10 @@ PushNotifier_Send_Message
<ul> <ul>
<code>set PushNotifier1 message This is a text.</code><br> <code>set PushNotifier1 message This is a text.</code><br>
</ul> </ul>
Linebreak:
<ul>
<code>set PushNotifier1 message This is a text._New Line.</code><br>
</ul>
</ul> </ul>
<br> <br>
<a name="PushNotifierEvents"></a> <a name="PushNotifierEvents"></a>
@ -209,6 +205,10 @@ PushNotifier_Send_Message
<ul> <ul>
<code>set PushNotifier1 message Dies ist ein Text.</code><br> <code>set PushNotifier1 message Dies ist ein Text.</code><br>
</ul> </ul>
Zeilenumbruch:
<ul>
<code>set PushNotifier1 message Dies ist ein Text._Neue Zeile.</code><br>
</ul>
</ul> </ul>
<br> <br>
<b>Get</b> <ul>N/A</ul><br> <b>Get</b> <ul>N/A</ul><br>