diff --git a/fhem/FHEM/70_Pushover.pm b/fhem/FHEM/70_Pushover.pm
index c4f39dc03..3cf9a36d0 100644
--- a/fhem/FHEM/70_Pushover.pm
+++ b/fhem/FHEM/70_Pushover.pm
@@ -20,15 +20,11 @@ sub Pushover_Initialize($$) {
$hash->{UndefFn} = "Pushover_Undefine";
$hash->{SetFn} = "Pushover_Set";
$hash->{AttrList} =
-"disable:0,1 disabledForIntervals do_not_notify:0,1 timestamp:0,1 title sound:pushover,bike,bugle,cashregister,classical,cosmic,falling,gamelan,incoming,intermission,magic,mechanical,pianobar,siren,spacealarm,tugboat,alien,climb,persistent,echo,updown,none device priority:0,1,-1,-2 callbackUrl "
+"disable:0,1 disabledForIntervals do_not_notify:0,1 timestamp:0,1 title sound:pushover,bike,bugle,cashregister,classical,cosmic,falling,gamelan,incoming,intermission,magic,mechanical,pianobar,siren,spacealarm,tugboat,alien,climb,persistent,echo,updown,none device priority:0,1,2,-1,-2 callbackUrl retry expire "
. $readingFnAttributes;
#$hash->{parseParams} = 1; # not possible due to legacy msg command schema
$hash->{'.msgParams'} = { parseParams => 1, };
-
- # a priority value of 2 is not predifined as for this also a value for
- # retry and expire must be set which will most likely not be used with
- # default values.
}
#------------------------------------------------------------------------------
@@ -134,15 +130,14 @@ sub Pushover_Set($@) {
unless ( $cmd =~ /^(msg|msgCancel|glance)$/i ) {
my $usage = "Unknown argument $cmd, choose one of msg glance";
- sort keys %{ $hash->{READINGS} };
my $cancelIds;
- while ( my ( $key, $value ) = each %{ $hash->{READINGS} } ) {
- if ( defined( $value->{VAL} )
- && $value->{VAL} ne ""
+ foreach my $key ( sort keys %{ $hash->{READINGS} } ) {
+ if ( defined( $hash->{READINGS}{$key}{VAL} )
+ && $hash->{READINGS}{$key}{VAL} ne ""
&& $key =~ /^cbCancelId_(\d+)$/ )
{
$cancelIds .= "," if ($cancelIds);
- $cancelIds .= $value->{VAL};
+ $cancelIds .= $hash->{READINGS}{$key}{VAL};
}
}
@@ -752,25 +747,18 @@ sub Pushover_SetMessage {
Log3 $name, 5, "Pushover $name: called function Pushover_SetMessage()";
- #Set defaults
+ # Set defaults
$values{title} = AttrVal( $hash->{NAME}, "title", "" );
$values{message} = "";
$values{device} = AttrVal( $hash->{NAME}, "device", "" );
$values{priority} = AttrVal( $hash->{NAME}, "priority", 0 );
$values{sound} = AttrVal( $hash->{NAME}, "sound", "" );
- $values{retry} = "";
- $values{expire} = "";
+ $values{retry} = AttrVal( $hash->{NAME}, "retry", "" );
+ $values{expire} = AttrVal( $hash->{NAME}, "expire", "" );
$values{url_title} = "";
$values{action} = "";
- my $callback = (
- defined( $attr{$name}{callbackUrl} )
- && defined( $hash->{fhem}{infix} )
- ? $attr{$name}{callbackUrl}
- : ""
- );
-
- #Split parameters
+ # Split parameters
my $param = join( " ", @_ );
my $argc = 0;
if ( $param =~
@@ -832,237 +820,27 @@ sub Pushover_SetMessage {
Log3 $name, 4, "Pushover $name: message=$values{message}";
}
- #Remove quotation marks
- if ( $values{title} =~ /^['"](.*)['"]$/s ) {
- $values{title} = $1;
- }
- if ( $values{message} =~ /^['"](.*)['"]$/s ) {
- $values{message} = $1;
- }
- if ( $values{device} =~ /^['"](.*)['"]$/s ) {
- $values{device} = $1;
- }
- if ( $values{priority} =~ /^['"](.*)['"]$/s ) {
- $values{priority} = $1;
- }
- if ( $values{sound} =~ /^['"](.*)['"]$/s ) {
- $values{sound} = $1;
- }
- if ( $values{retry} =~ /^['"](.*)['"]$/s ) {
- $values{retry} = $1;
- }
- if ( $values{expire} =~ /^['"](.*)['"]$/s ) {
- $values{expire} = $1;
- }
- if ( $values{url_title} =~ /^['"](.*)['"]$/s ) {
- $values{url_title} = $1;
- }
- if ( $values{action} =~ /^['"](.*)['"]$/s ) {
- $values{action} = $1;
- }
+ # Remove quotation marks
+ $values{title} = $1
+ if ( $values{title} =~ /^['"](.*)['"]$/s );
+ $values{message} = $1
+ if ( $values{message} =~ /^['"](.*)['"]$/s );
+ $values{device} = $1
+ if ( $values{device} =~ /^['"](.*)['"]$/s );
+ $values{priority} = $1
+ if ( $values{priority} =~ /^['"](.*)['"]$/s );
+ $values{sound} = $1
+ if ( $values{sound} =~ /^['"](.*)['"]$/s );
+ $values{retry} = $1
+ if ( $values{retry} =~ /^['"](.*)['"]$/s );
+ $values{expire} = $1
+ if ( $values{expire} =~ /^['"](.*)['"]$/s );
+ $values{url_title} = $1
+ if ( $values{url_title} =~ /^['"](.*)['"]$/s );
+ $values{action} = $1
+ if ( $values{action} =~ /^['"](.*)['"]$/s );
- # check if we got a user or group key as device and use it as
- # user-key instead of hash->USER_KEY
- if ( $values{device} =~ /^(([A-Za-z0-9]{30}):)?([A-Za-z0-9,_-]*)(.*)$/ ) {
- $values{USER_KEY} = $2 if ( $2 ne "" );
- $values{device} = $3;
-
- return $hash->{helper}{FAILED_USERKEYS}{ $values{USER_KEY} }
- if ( $values{USER_KEY}
- && defined( $hash->{helper}{FAILED_USERKEYS}{ $values{USER_KEY} } )
- );
- }
-
- # Check if all mandatory arguments are filled:
- # "message" can not be empty and if "priority" is set to "2" "retry" and
- # "expire" must also be set.
- # "url_title" and "action" need to be set together and require "expire"
- # to be set as well.
- if (
- $values{message} ne ""
- && ( ( $values{retry} ne "" && $values{expire} ne "" )
- || $values{priority} < 2 )
- && (
- (
- $values{url_title} ne ""
- && $values{action} ne ""
- && $values{expire} ne ""
- )
- || ( $values{url_title} eq "" && $values{action} eq "" )
- )
- )
- {
- my $body;
- $body = "title=" . urlEncode( $values{title} )
- if ( $values{title} ne "" );
-
- if ( $values{message} =~
- /\<(\/|)[biu]\>|\<(\/|)font(.+)\>|\<(\/|)a(.*)\>|\
/
- && $values{message} !~ /^nohtml:.*/ )
- {
- Log3 $name, 4, "Pushover $name: handling message with HTML content";
- $body .= "&html=1";
-
- # replace \n by
but ignore \\n
- $values{message} =~ s/(?/g;
- }
-
- elsif ( $values{message} =~ /^nohtml:.*/ ) {
- Log3 $name, 4,
- "Pushover $name: explicitly ignoring HTML tags in message";
- $values{message} =~ s/^(nohtml:).*//;
- }
-
- # HttpUtil's urlEncode() does not handle \n but would escape %
- # so we encode first
- $values{message} = urlEncode( $values{message} );
-
- # replace any URL-encoded \n with their hex equivalent but ignore \\n
- $values{message} =~ s/(? 2 );
- $values{priority} = -2 if ( $values{priority} < -2 );
- $body .= "&priority=" . $values{priority};
- }
-
- if ( $values{sound} ne "" ) {
- $body .= "&sound=" . $values{sound};
- }
-
- if ( $values{retry} ne "" ) {
- $body .= "&retry=" . $values{retry};
- }
-
- if ( $values{expire} ne "" ) {
- $body .= "&expire=" . $values{expire};
-
- $values{cbNr} = int( time() ) + $values{expire};
- my $cbReading = "cb_" . $values{cbNr};
- until ( ReadingsVal( $name, $cbReading, "" ) eq "" ) {
- $values{cbNr}++;
- $cbReading = "cb_" . $values{cbNr};
- }
- }
-
- if ( 1 == AttrVal( $hash->{NAME}, "timestamp", 0 ) ) {
- $body .= "×tamp=" . int( time() );
- }
-
- if ( $callback ne "" && $values{priority} > 1 ) {
- Log3 $name, 5,
- "Pushover $name: Adding emergency callback URL $callback";
- $body .= "&callback=" . $callback;
- }
-
- if ( $values{url_title} ne ""
- && $values{action} ne ""
- && $values{expire} ne "" )
- {
- my $url;
-
- if (
- $callback eq ""
- || ( $values{action} !~ /^http[s]?:\/\/.*$/
- && $values{action} =~ /^[\w-]+:\/\/.*$/ )
- )
- {
- $url = $values{action};
- $values{expire} = "";
- }
- else {
- $url =
- $callback
- . "?acknowledged=1&acknowledged_by="
- . $hash->{USER_KEY}
- . "&FhemCallbackId="
- . $values{cbNr};
- }
-
- Log3 $name, 5,
-"Pushover $name: Adding supplementary URL '$values{url_title}' ($url) with "
- . "action '$values{action}' (expires after $values{expire} => "
- . "$values{cbNr})";
- $body =
- $body
- . "&url_title="
- . urlEncode( $values{url_title} ) . "&url="
- . urlEncode($url);
- }
-
- # cleanup callback readings
- keys %{ $hash->{READINGS} };
- while ( my ( $key, $value ) = each %{ $hash->{READINGS} } ) {
- if ( $key =~ /^cb_(\d+)$/ ) {
- my $rTit = "cbTitle_" . $1;
- my $rMsg = "cbMsg_" . $1;
- my $rPrio = "cbPrio_" . $1;
- my $rAct = "cbAct_" . $1;
- my $rAck = "cbAck_" . $1;
- my $rAckAt = "cbAckAt_" . $1;
- my $rAckBy = "cbAckBy_" . $1;
- my $rCancelId = "cbCancelId_" . $1;
- my $rDev = "cbDev_" . $1;
-
- Log3 $name, 5,
- "Pushover $name: checking to clean up "
- . $hash->{NAME}
- . " $key: time="
- . $1 . " ack="
- . ReadingsVal( $name, $rAck, "-" )
- . " curTime="
- . int( time() );
-
- if ( ReadingsVal( $name, $rAck, "0" ) eq "1"
- || $1 <= int( time() ) )
- {
- delete $hash->{READINGS}{$key};
- delete $hash->{READINGS}{$rTit};
- delete $hash->{READINGS}{$rMsg};
- delete $hash->{READINGS}{$rPrio};
- delete $hash->{READINGS}{$rAck};
- delete $hash->{READINGS}{$rDev};
-
- delete $hash->{READINGS}{$rAct}
- if ( defined( $hash->{READINGS}{$rAct} ) );
- delete $hash->{READINGS}{$rAckAt}
- if ( defined( $hash->{READINGS}{$rAckAt} ) );
- delete $hash->{READINGS}{$rAckBy}
- if ( defined( $hash->{READINGS}{$rAckBy} ) );
- delete $hash->{READINGS}{$rCancelId}
- if ( defined( $hash->{READINGS}{$rCancelId} ) );
-
- Log3 $name, 4,
- "Pushover $name: cleaned up expired receipt " . $1;
- }
- }
- }
-
- return Pushover_SendCommand( $hash, "messages.json", $body, %values );
- }
- else {
-
- # There was a problem with the arguments, so tell the user the
- # correct usage of the 'set msg' command
- if ( 1 == $argc && $values{title} eq "" ) {
- return
-"Please define the default title in the pushover device arguments.";
- }
- else {
- return
-"Syntax: $name msg ['
priority
expire
retry
sound
priority
expire
retry
sound