From 2a3c57f2d1bab187853cc4a9568abaa5182f80f4 Mon Sep 17 00:00:00 2001 From: markusbloch <> Date: Tue, 18 Oct 2016 17:01:52 +0000 Subject: [PATCH] Pushsafer: added new option "ttl" (short: "l") to define a time-to-live for a message (Forum: #59004), implement a value check for several options git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@12375 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- FHEM/70_Pushsafer.pm | 49 ++++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/FHEM/70_Pushsafer.pm b/FHEM/70_Pushsafer.pm index 97d6e31f7..38d2708da 100755 --- a/FHEM/70_Pushsafer.pm +++ b/FHEM/70_Pushsafer.pm @@ -35,15 +35,16 @@ use HttpUtils; use utf8; my %Pushsaver_Params = ( - "title" => "t", - "sound" => "s", - "vibration" => "v", - "icon" => "i", - "url" => "u", - "device" => "d", - "key" => "k", - "urlText" => "ut", - "message" => "m" + "title" => {"short" => "t", "check" => qr/^.*$/}, + "sound" => {"short" => "s", "check" => qr/^\d+$/}, + "vibration" => {"short" => "v", "check" => qr/^\d+$/}, + "icon" => {"short" => "i", "check" => qr/^\d+$/}, + "url" => {"short" => "u", "check" => qr/^[a-z]+:/}, + "device" => {"short" => "d", "check" => qr/^(?:gs)?\d+$/}, + "key" => {"short" => "k", "check" => qr/^[a-zA-Z\d]{20}$/}, + "urlText" => {"short" => "ut"}, + "message" => {"short" => "m"}, + "ttl" => {"short" => "l", "check" => qr/^\d+$/} ); @@ -158,11 +159,27 @@ sub Pushsafer_createBody($$) { if(exists($Pushsaver_Params{$item})) { - push @urlParts, $Pushsaver_Params{$item}."=".urlEncode($args->{$item}); + if(exists($Pushsaver_Params{$item}{check}) and $args->{$item} !~ $Pushsaver_Params{$item}{check}) + { + push @errs, "wrong syntax for option $item: ".$args->{$item}; + } + else + { + push @urlParts, $Pushsaver_Params{$item}{short}."=".urlEncode($args->{$item}); + } } - elsif(grep($Pushsaver_Params{$_} eq $item, keys(%Pushsaver_Params))) + elsif(grep($Pushsaver_Params{$_}{short} eq $item, keys(%Pushsaver_Params))) { - push @urlParts, $item."=".urlEncode($args->{$item}); + my $command = join "", grep($Pushsaver_Params{$_}{short} eq $item, keys(%Pushsaver_Params)); + + if(exists($Pushsaver_Params{$command}{check}) and $args->{$item} !~ $Pushsaver_Params{$command}{check}) + { + push @errs, "wrong syntax for option $item: ".$args->{$item}; + } + else + { + push @urlParts, $item."=".urlEncode($args->{$item}); + } } else { @@ -314,7 +331,8 @@ sub Pushsafer_Callback($$$) vibration - short: - type: number - The number of times the device should vibrate upon reception (maximum: 3 times; iOS/Android only). If not set, the default behavior of the device is used.
url       - short: - type: text - A URL that should be included in the message. This can be regular http:// URL's but also specific app schemas. See Pushsafer.com for a complete list of supported URL schemas.
urlText   - short: ut - type: text - A text that should be used to display a URL from the "url" option.
- key       - short: - type: text - Overrides the private key given in the define statement. Also an alias key can be used.
+ key       - short: - type: text - Overrides the private key given in the define statement. Also an alias key can be used.
+ ttl       - short: - type: number - Defines a "time-to-live" given in minutes after the message will be deleted on the target device(s). Possible range is between 1 - 43200 minutes (30 days).

Examples:

@@ -402,10 +420,11 @@ sub Pushsafer_Callback($$$) sound     - Kurzform: - Typ: Ganzzahl - Die Nummer eines Tons, welcher beim Empfang der Nachricht auf dem Zielgerät ertönen soll (siehe pushsafer.com für eine Liste möglicher Werte).
icon      - Kurzform: - Typ: Ganzzahl - Die Nummer eines Icons, welches zusammen mit der Nachricht auf dem Zielgerät angezeigt werden soll (siehe Pushsafer.com für eine Liste möglicher Werte).
vibration - Kurzform: - Typ: Ganzzahl - Die Anzahl, wie oft das Zielgerät vibrieren soll beim Empfang der Nachricht (maximal 3 mal; nur für iOS-/Android-Geräte nutzbar). Falls nicht benutzt, wird die geräteinterne Einstellung verwendet.
- url       - Kurzform: - Typ: Text - Eine URL welche der Nachricht angehangen werden soll. Dies kann eine normale http:// bzw. https:// URL sein, es sind jedoch auch weitere spezielle Schemas möglich. Eine Liste aller möglichen URL-Schemas gibt es unter pushsafer.com .
+ url       - Kurzform: - Typ: Text - Eine URL, welche der Nachricht angehangen werden soll. Dies kann eine normale http:// bzw. https:// URL sein, es sind jedoch auch weitere spezielle Schemas möglich. Eine Liste aller möglichen URL-Schemas gibt es unter pushsafer.com .
urlText   - Kurzform: ut - Typ: Text - Der Text, welcher zum Anzeigen der URL benutzt werden soll anstatt der Zieladresse.
key       - Kurzform: - Typ: Text - Übersteuert den zu nutzenden Schlüssel zur Identifikation aus dem define-Kommando. Es kann hierbei auch ein Email-Alias-Schlüssel benutzt werden.
-
+ ttl       - Kurzform: - Typ: Ganzzahl - Die Lebensdauer der Nachricht in Minuten. Sobald die Lebensdauer erreicht ist, wird die Nachricht selbstständig auf allen Geräten gelöscht. Der mögliche Wertebereich liegt zwischen 1 - 43200 Minuten (entspricht 30 Tagen).
+
Beispiele: