2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 18:59:33 +00:00

Pushalot: added pushalot-module that allows to send push notifications to windows phone

git-svn-id: https://svn.fhem.de/fhem/trunk@8696 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
talkabout 2015-06-05 19:22:47 +00:00
parent 8d816eb573
commit a21ec8fa95
2 changed files with 423 additions and 0 deletions

422
fhem/FHEM/70_Pushalot.pm Normal file
View File

@ -0,0 +1,422 @@
###############################################################################
#
# A module to send notifications to Pushalot.
#
# written 2015 by Talkabout B <talk dot about at gmx dot de>
#
###############################################################################
#
# Definition:
# define <name> Pushalot <token> [<source>]
#
# Example:
# define PushNotification Pushalot 123234 FHEM
#
#
# You can send messages via the following command:
# set <Pushalot_device> message "<message>" ["<title>"] ["<link>"] ["<link_title>"] ["<image>"] [<important>] [<silent>]
#
# Examples:
# set PushNotification message "This is my message."
# set PushNotification message "This is my message." "With Title"
# set PushNotification message "This is my message." "With Title" "http://www.xyz.com""
# set PushNotification message "This is my message." "With Title" "http://www.xyz.com" "Link Title"
# set PushNotification message "This is my message." "With Title" "http://www.xyz.com" "Link Title" "http://www.xyz/image.png"
# set PushNotification message "This is my message." "With Title" "http://www.xyz.com" "Link Title" "http://www.xyz/image.png" True False
#
# Explantation:
#
# - The first parameter is the message to send
# - The second parameter is an optional title for the message
# - The third parameter is an optional link for the message
# - The fourth parameter is an optional link title for the message
# - The fifth parameter is an optional image for the message
# - The sixth parameter defines whether the message should be marked as important
# - The seventh parameter defines whether the message should be delivered silently
#
# For further documentation
# https://pushalot.com/api:
package main;
use HttpUtils;
use utf8;
use JSON;
use URI::Escape;
my %sets = (
"message" => 1
);
#------------------------------------------------------------------------------
sub Pushalot_Initialize($$)
#------------------------------------------------------------------------------
{
my ($hash) = @_;
$hash->{DefFn} = "Pushalot_Define";
$hash->{SetFn} = "Pushalot_Set";
$hash->{AttrList} = "disable:0,1";
Log3 $hash, 3, "Pushalot initialized";
return undef;
}
#------------------------------------------------------------------------------
sub Pushalot_Define($$)
#------------------------------------------------------------------------------
{
my ($hash, $def) = @_;
my @args = split("[ \t]+", $def);
if (int(@args) < 1)
{
return "Invalid number of arguments: define <name> Pushalot <token> [<source>]";
}
my ($name, $type, $token, $source) = @args;
$hash->{STATE} = 'Initialized';
$hash->{helper}{Url} = "https://pushalot.com/api/sendmessage";
if(defined($token))
{
$hash->{Token} = $token;
}
else
{
return "Token and/or user missing.";
}
if(defined($source))
{
$hash->{Source} = $source;
}
else
{
$hash->{Source} = '';
}
Log3 $hash, 3, "Pushalot defined for token: " . $token;
return undef;
}
#------------------------------------------------------------------------------
sub Pushalot_Set($@)
#------------------------------------------------------------------------------
{
my ($hash, $name, $cmd, @args) = @_;
if (!defined($sets{$cmd}))
{
return "Unknown argument " . $cmd . ", choose one of " . join(" ", sort keys %sets);
}
if (@args < 1)
{
return "Argument \"message\" missing";
}
if (AttrVal($name, "disable", 0 ) == 1)
{
return "Device is disabled";
}
if ($cmd eq 'message')
{
return Pushalot_Send($hash, Pushalot_Build_Body($hash, @args));
}
}
sub Pushalot_Build_Body($@)
{
my ($hash, @args) = @_;
my $string = join(" ", @args);
my @matches = ($string =~ /"[^"]*"| True| False/g);
my ($message, $title, $image, $link, $linkTitle, $important, $silent) = @matches;
$message =~ s/^[\s"]+|[\s"]+$//g;
$title =~ s/^[\s"]+|[\s"]+$//g;
$image =~ s/^[\s"]+|[\s"]+$//g;
$link =~ s/^[\s"]+|[\s"]+$//g;
$linkTitle =~ s/^[\s"]+|[\s"]+$//g;
$important =~ s/^[\s"]+|[\s"]+$//g;
$silent =~ s/^[\s"]+|[\s"]+$//g;
if ($message eq "")
{
$message = $string;
}
return
"AuthorizationToken="
. $hash->{Token}
. "&Source=" . $hash->{Source}
. "&Body=" . uri_escape($message)
. "&Title=" . uri_escape($title)
. "&Image=" . uri_escape($image)
. "&Link=" . uri_escape($link)
. "&LinkTitle=" . uri_escape($linkTitle)
. "&IsImportant=" . $important
. "&IsSilent=" . $silent;
}
#------------------------------------------------------------------------------
sub Pushalot_Send($$)
#------------------------------------------------------------------------------
{
my ($hash,$body) = @_;
$response = GetFileFromURL($hash->{helper}{Url}, 10, $body, 0, 5);
return Pushalot_Parse_Result($hash, $message, $response);
}
sub Pushalot_Parse_Result($$$)
{
my ($hash, $message, $result) = @_;
my $returnObject = decode_json $result;
readingsBeginUpdate($hash);
readingsBulkUpdate($hash, "last-message-raw", $message);
readingsBulkUpdate($hash, "last-result-raw", $result);
readingsBulkUpdate($hash, "last-success", $returnObject->{"Success"});
readingsBulkUpdate($hash, "last-status", $returnObject->{"Status"});
readingsBulkUpdate($hash, "last-description", $returnObject->{"Description"});
readingsEndUpdate($hash, 1);
return undef if($returnObject->{"Status"} == 200);
return $returnObject->{"Description"};
}
1;
###############################################################################
=pod
=begin html
<a name="Pushalot"></a>
<h3>Pushalot</h3>
<ul>
Pushalot is a service to receive instant push notifications on your
Windows Phone device from a variety of sources.<br>
You need an account to use this module.<br>
For further information about the service see <a href="https://pushalot.com" target="_blank">pushalot.com</a>.<br>
<br>
Discuss the module <a href="http://forum.fhem.de/index.php/topic,37775.0.html" target="_blank">here</a>.<br>
<br>
<br>
<a name="PushalotDefine"></a>
<b>Define</b>
<ul>
<code>define &lt;name&gt; Pushalot &lt;token&gt; [&lt;source&gt;]</code><br>
<br>
<table>
<colgroup>
<col style="width: 100px";"></col>
<col></col>
</colgroup>
<tr>
<td>&lt;token&gt;</td>
<td>The token that identifies a pushalot-account. You need to create if no account yet.</td>
</tr>
<tr>
<td>&lt;source&gt;</td>
<td>The source defines what will be shown in the 'from'-field of the message (the sender).</td>
</tr>
</table>
<br>
Example:
<ul>
<code>define PushNotification Pushalot 123234 FHEM</code>
</ul>
</ul>
<br>
<a name="PushalotSet"></a>
<b>Set</b>
<ul>
<code>set &lt;Pushalot_device&gt; "&lt;message&gt;" ["&lt;title&gt;"] ["&lt;link&gt;"] ["&lt;link_title&gt;"] ["&lt;image&gt;"] ["&lt;important&gt;"] ["&lt;silent&gt;"]</code>
<br>
<br>
<table>
<colgroup>
<col style="width: 100px";"></col>
<col></col>
</colgroup>
<tr>
<td>&lt;message&gt;</td>
<td>The message body that should appear in the message.</td>
</tr>
<tr>
<td>&lt;title&gt;</td>
<td>The title of the message.</td>
</tr>
<tr>
<td>&lt;link&gt;</td>
<td>An optional link that should be appended to the message body.</td>
</tr>
<tr>
<td>&lt;link_title&gt;</td>
<td>An optional link title. If no title is set, the URL is shown as title in the message.</td>
</tr>
<tr>
<td>&lt;image&gt;</td>
<td>An optional image URL that is shown in the message.</td>
</tr>
<tr>
<td>&lt;important&gt;</td>
<td>True|False: True if the message should be marked as 'important', otherwise False (Default)</td>
</tr>
<tr>
<td>&lt;silent&gt;</td>
<td>True|False: True if the message should be delivered silently (no notify sound is played), otherwise False (Default)</td>
</tr>
</table>
<br>
Examples:
<ul>
<code>set PushNotification message "This is my message."</code><br>
<code>set PushNotification message "This is my message." "With Title"</code><br>
<code>set PushNotification message "This is my message." "With Title" "http://www.xyz.com"</code><br>
<code>set PushNotification message "This is my message." "With Title" "http://www.xyz.com" "Link Title"</code><br>
<code>set PushNotification message "This is my message." "With Title" "http://www.xyz.com" "Link Title" "http://www.xyz.com/image.png"</code><br>
<code>set PushNotification message "This is my message." "With Title" "http://www.xyz.com" "Link Title" "http://www.xyz.com/image.png" True</code><br>
<code>set PushNotification message "This is my message." "With Title" "http://www.xyz.com" "Link Title" "http://www.xyz.com/image.png" True False</code><br>
</ul>
<br>
</ul>
<br>
<b>Get</b> <ul>N/A</ul><br>
<a name="PushalotAttr"></a>
<b>Attributes</b> <ul>N/A</ul><br>
<ul>
</ul>
<br>
<a name="PushalotEvents"></a>
<b>Generated events:</b>
<ul>
N/A
</ul>
</ul>
=end html
=begin html_DE
<a name="Pushalot"></a>
<h3>Pushalot</h3>
<ul>
Pusalot ist ein Dienst, um Benachrichtigungen von einer vielzahl
von Quellen auf ein Windows Phone Device zu empfangen.<br>
Du brauchst einen Account um dieses Modul zu verwenden.<br>
Für weitere Informationen über den Dienst besuche <a href="https://pushalot.com" target="_blank">pushalot.com</a>.<br>
<br>
Diskutiere das Modul <a href="http://forum.fhem.de/index.php/topic,37775.0.html" target="_blank">hier</a>.<br>
<br>
<br>
<a name="PushalotDefine"></a>
<b>Define</b>
<ul>
<code>define &lt;name&gt; Pushalot &lt;token&gt; [&lt;source&gt;]</code><br>
<br>
<table>
<colgroup>
<col style="width: 100px";"></col>
<col></col>
</colgroup>
<tr>
<td>&lt;token&gt;</td>
<td>Der Token der den pushalot-Account identifiziert. Um diesen zu bekommen, muss ein Account erstellt werden.</td>
</tr>
<tr>
<td>&lt;source&gt;</td>
<td>Definiert den Absender, der in der Nachricht angezeigt werden soll.</td>
</tr>
</table>
<br>
Beispiel:
<ul>
<code>define Pushalot PushNotification 123234 FHEM</code>
</ul>
</ul>
<br>
<a name="PushalotSet"></a>
<b>Set</b>
<ul>
<code>set &lt;Pushalot_device&gt; "&lt;message&gt;" ["&lt;title&gt;"] ["&lt;link&gt;"] ["&lt;link_title&gt;"] ["&lt;image&gt;"] ["&lt;important&gt;"] ["&lt;silent&gt;"]</code>
<br>
<br>
<table>
<colgroup>
<col style="width: 100px";"></col>
<col></col>
</colgroup>
<tr>
<td>&lt;message&gt;</td>
<td>Der Nachrichten-Text.</td>
</tr>
<tr>
<td>&lt;title&gt;</td>
<td>Der Titel der Nachricht.</td>
</tr>
<tr>
<td>&lt;link&gt;</td>
<td>Ein optionaler Link der an die Nachricht angehängt werden soll.</td>
</tr>
<tr>
<td>&lt;link_title&gt;</td>
<td>Optionaler Link Titel. Wenn kein Titel angegeben wird, ist dieser die URL.</td>
</tr>
<tr>
<td>&lt;image&gt;</td>
<td>Optionale Bild-URL die in der Nachricht angezeigt werden soll.</td>
</tr>
<tr>
<td>&lt;important&gt;</td>
<td>True|False: True wenn die Nachricht als 'wichtig' markiert werden soll, sonst False (Default)</td>
</tr>
<tr>
<td>&lt;silent&gt;</td>
<td>True|False: True wenn die Nachricht 'still' ausgeliefert werden soll (kein Benachrichtigungssound wird abgespielt), ansonsten False (Default)</td>
</tr>
</table>
<br>
Beispiele:
<ul>
<code>set PushNotification message "Das ist meine Nachricht."</code><br>
<code>set PushNotification message "Das ist meine Nachricht." "Mit Titel"</code><br>
<code>set PushNotification message "Das ist meine Nachricht." "Mit Titel" "http://www.xyz.com"</code><br>
<code>set PushNotification message "Das ist meine Nachricht." "Mit Titel" "http://www.xyz.com" "Link Titel"</code><br>
<code>set PushNotification message "Das ist meine Nachricht." "Mit Titel" "http://www.xyz.com" "Link Titel" "http://www.xyz.com/image.png"</code><br>
<code>set PushNotification message "Das ist meine Nachricht." "Mit Titel" "http://www.xyz.com" "Link Titel" "http://www.xyz.com/image.png" True</code><br>
<code>set PushNotification message "Das ist meine Nachricht." "Mit Titel" "http://www.xyz.com" "Link Title" "http://www.xyz.com/image.png" True False</code><br>
</ul>
<br>
Notes:
<ul>
</ul>
</ul>
<br>
<b>Get</b> <ul>N/A</ul><br>
<a name="PushalotAttr"></a>
<b>Attribute</b> <ul>N/A</ul><br>
<ul>
</ul>
<br>
<a name="PushalotEvents"></a>
<b>Generierte events:</b>
<ul>
N/A
</ul>
</ul>
=end html_DE
=cut

View File

@ -209,6 +209,7 @@ FHEM/70_XBMC.pm vbs http://forum.fhem.de Multimedi
FHEM/70_Pushbullet.pm fhainz http://forum.fhem.de Unterstuetzende Dienste
FHEM/70_Pushover.pm Johannes_B http://forum.fhem.de Unterstuetzende Dienste
FHEM/70_PushNotifier.pm xusader http://forum.fhem.de Unterstuetzende Dienste
FHEM/70_Pushalot.pm Talkabout http://forum.fhem.de Codeschnipsel
FHEM/71_PHILIPS_AUDIO.pm ra666ack http://forum.fhem.de Multimedia
FHEM/71_YAMAHA_AVR.pm markusbloch http://forum.fhem.de Multimedia
FHEM/71_YAMAHA_BD.pm markusbloch http://forum.fhem.de Multimedia