mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-02-01 01:09:47 +00:00
70_Pushover: make title optional parameter to match commandref and Pushover API definition
git-svn-id: https://svn.fhem.de/fhem/trunk@10394 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
58e4aa5b68
commit
74133df9eb
@ -71,8 +71,9 @@ sub Pushover_Initialize($$) {
|
||||
"disable: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 "
|
||||
. $readingFnAttributes;
|
||||
|
||||
#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.
|
||||
# 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.
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
@ -136,10 +137,16 @@ sub Pushover_Define($$) {
|
||||
|
||||
# start Validation Timer
|
||||
RemoveInternalTimer($hash);
|
||||
if (ReadingsVal($name,"tokenState","invalid") ne "valid" || ReadingsVal($name,"userState","invalid") ne "valid" || $init_done) {
|
||||
InternalTimer( gettimeofday() + 5, "Pushover_ValidateUser", $hash, 0 );
|
||||
} else {
|
||||
InternalTimer( gettimeofday() + 21600, "Pushover_ValidateUser", $hash, 0 );
|
||||
if ( ReadingsVal( $name, "tokenState", "invalid" ) ne "valid"
|
||||
|| ReadingsVal( $name, "userState", "invalid" ) ne "valid"
|
||||
|| $init_done )
|
||||
{
|
||||
InternalTimer( gettimeofday() + 5,
|
||||
"Pushover_ValidateUser", $hash, 0 );
|
||||
}
|
||||
else {
|
||||
InternalTimer( gettimeofday() + 21600,
|
||||
"Pushover_ValidateUser", $hash, 0 );
|
||||
}
|
||||
|
||||
return undef;
|
||||
@ -216,12 +223,14 @@ sub Pushover_SendCommand($$;$\%) {
|
||||
|
||||
$cmd .= "&" if ( $cmd ne "" );
|
||||
$cmd .= "token=" . $hash->{APP_TOKEN};
|
||||
|
||||
if (!defined($type->{USER_KEY})) {
|
||||
$cmd .= "&user=" . $hash->{USER_KEY};
|
||||
} else {
|
||||
Log3 $name, 4, "Pushover $name: USER_KEY found in device name: ".$type->{USER_KEY};
|
||||
$cmd .= "&user=" . $type->{USER_KEY};
|
||||
|
||||
if ( !defined( $type->{USER_KEY} ) ) {
|
||||
$cmd .= "&user=" . $hash->{USER_KEY};
|
||||
}
|
||||
else {
|
||||
Log3 $name, 4,
|
||||
"Pushover $name: USER_KEY found in device name: " . $type->{USER_KEY};
|
||||
$cmd .= "&user=" . $type->{USER_KEY};
|
||||
}
|
||||
|
||||
my $URL;
|
||||
@ -325,7 +334,13 @@ sub Pushover_ReceiveCommand($$$) {
|
||||
my $values = $param->{type};
|
||||
my $return;
|
||||
|
||||
Log3 $name, 5, "Pushover $name: Received HttpUtils callback:\n\nPARAM:\n".Dumper($param)."\n\nERROR:\n".Dumper($err)."\n\nDATA:\n".Dumper($data);
|
||||
Log3 $name, 5,
|
||||
"Pushover $name: Received HttpUtils callback:\n\nPARAM:\n"
|
||||
. Dumper($param)
|
||||
. "\n\nERROR:\n"
|
||||
. Dumper($err)
|
||||
. "\n\nDATA:\n"
|
||||
. Dumper($data);
|
||||
|
||||
readingsBeginUpdate($hash);
|
||||
|
||||
@ -393,102 +408,141 @@ sub Pushover_ReceiveCommand($$$) {
|
||||
#
|
||||
|
||||
$values{result} = "ok";
|
||||
|
||||
|
||||
# extract API stats
|
||||
my $apiLimit = 7500;
|
||||
my $apiLimit = 7500;
|
||||
my $apiRemaining = 1;
|
||||
my $apiReset;
|
||||
if ( $param->{httpheader} =~ m/X-Limit-App-Limit:[\s\t]*(.*)[\s\t\n]*/ ) {
|
||||
$apiLimit = $1;
|
||||
readingsBulkUpdate( $hash, "apiLimit", $1 )
|
||||
if ( ReadingsVal($name,"apiLimit","") ne $1 );
|
||||
if ( $param->{httpheader} =~ m/X-Limit-App-Limit:[\s\t]*(.*)[\s\t\n]*/ )
|
||||
{
|
||||
$apiLimit = $1;
|
||||
readingsBulkUpdate( $hash, "apiLimit", $1 )
|
||||
if ( ReadingsVal( $name, "apiLimit", "" ) ne $1 );
|
||||
}
|
||||
if ( $param->{httpheader} =~ m/X-Limit-App-Remaining:[\s\t]*(.*)[\s\t\n]*/ ) {
|
||||
$apiRemaining = $1;
|
||||
readingsBulkUpdate( $hash, "apiRemaining", $1 )
|
||||
if ( ReadingsVal($name,"apiRemaining","") ne $1 );
|
||||
if ( $param->{httpheader} =~
|
||||
m/X-Limit-App-Remaining:[\s\t]*(.*)[\s\t\n]*/ )
|
||||
{
|
||||
$apiRemaining = $1;
|
||||
readingsBulkUpdate( $hash, "apiRemaining", $1 )
|
||||
if ( ReadingsVal( $name, "apiRemaining", "" ) ne $1 );
|
||||
}
|
||||
if ( $param->{httpheader} =~ m/X-Limit-App-Reset:[\s\t]*(.*)[\s\t\n]*/ ) {
|
||||
$apiReset = $1;
|
||||
readingsBulkUpdate( $hash, "apiReset", $1 )
|
||||
if ( ReadingsVal($name,"apiReset","") ne $1 );
|
||||
if ( $param->{httpheader} =~ m/X-Limit-App-Reset:[\s\t]*(.*)[\s\t\n]*/ )
|
||||
{
|
||||
$apiReset = $1;
|
||||
readingsBulkUpdate( $hash, "apiReset", $1 )
|
||||
if ( ReadingsVal( $name, "apiReset", "" ) ne $1 );
|
||||
}
|
||||
|
||||
# Server error
|
||||
if ($param->{code} >= 500) {
|
||||
$state = "error";
|
||||
$values{result} = "Server Error " . $param->{code};
|
||||
if ( $param->{code} >= 500 ) {
|
||||
$state = "error";
|
||||
$values{result} = "Server Error " . $param->{code};
|
||||
}
|
||||
|
||||
# error handling
|
||||
elsif ( ($param->{code} == 200 || $param->{code} >= 400) &&
|
||||
( (ref($return) eq "HASH" && $return->{status} ne "1") || (ref($return) ne "HASH" && $return !~ m/"status":1,/) ) ) {
|
||||
$values{result} = "Error " . $param->{code} . ": Unspecified error occured";
|
||||
if (ref($return) eq "HASH" && defined $return->{errors}) {
|
||||
elsif (
|
||||
( $param->{code} == 200 || $param->{code} >= 400 )
|
||||
&& ( ( ref($return) eq "HASH" && $return->{status} ne "1" )
|
||||
|| ( ref($return) ne "HASH" && $return !~ m/"status":1,/ ) )
|
||||
)
|
||||
{
|
||||
$values{result} =
|
||||
"Error " . $param->{code} . ": " . join( ". ", @{ $return->{errors} } );
|
||||
}
|
||||
elsif ( ref($return) ne "HASH" && $return =~ m/"errors":\[(.*)\]/ ) {
|
||||
$values{result} = "Error " . $param->{code} . ": " . $1;
|
||||
}
|
||||
"Error " . $param->{code} . ": Unspecified error occured";
|
||||
if ( ref($return) eq "HASH" && defined $return->{errors} ) {
|
||||
$values{result} =
|
||||
"Error "
|
||||
. $param->{code} . ": "
|
||||
. join( ". ", @{ $return->{errors} } );
|
||||
}
|
||||
elsif ( ref($return) ne "HASH" && $return =~ m/"errors":\[(.*)\]/ )
|
||||
{
|
||||
$values{result} = "Error " . $param->{code} . ": " . $1;
|
||||
}
|
||||
|
||||
$state = "error";
|
||||
$state = "error";
|
||||
|
||||
if ( ref($return) eq "HASH" && defined( $return->{token} ) ) {
|
||||
$state = "unauthorized";
|
||||
readingsBulkUpdate( $hash, "tokenState", $return->{token} )
|
||||
if (
|
||||
ReadingsVal( $name, "tokenState", "" ) ne $return->{token}
|
||||
);
|
||||
}
|
||||
elsif ( ref($return) ne "HASH" && $return =~ m/"token":"invalid"/ )
|
||||
{
|
||||
$state = "unauthorized";
|
||||
readingsBulkUpdate( $hash, "tokenState", "invalid" )
|
||||
if ( ReadingsVal( $name, "tokenState", "" ) ne "invalid" );
|
||||
}
|
||||
else {
|
||||
readingsBulkUpdate( $hash, "tokenState", "valid" )
|
||||
if ( ReadingsVal( $name, "tokenState", "" ) ne "valid" );
|
||||
}
|
||||
|
||||
if ( ref($return) eq "HASH" && defined( $return->{user} ) ) {
|
||||
|
||||
$state = "unauthorized" if ( !defined( $values->{USER_KEY} ) );
|
||||
readingsBulkUpdate( $hash, "userState", $return->{user} )
|
||||
if ( ReadingsVal( $name, "userState", "" ) ne $return->{user}
|
||||
&& !defined( $values->{USER_KEY} ) );
|
||||
|
||||
$hash->{helper}{FAILED_USERKEYS}{ $values->{USER_KEY} } =
|
||||
"USERKEY "
|
||||
. $values->{USER_KEY} . " "
|
||||
. $return->{user} . " - "
|
||||
. $values{result}
|
||||
if ( defined( $values->{USER_KEY} ) );
|
||||
|
||||
}
|
||||
elsif ( ref($return) ne "HASH" && $return =~ m/"user":"invalid"/ ) {
|
||||
|
||||
$state = "unauthorized" if ( !defined( $values->{USER_KEY} ) );
|
||||
readingsBulkUpdate( $hash, "userState", "invalid" )
|
||||
if ( ReadingsVal( $name, "userState", "" ) ne "invalid"
|
||||
&& !defined( $values->{USER_KEY} ) );
|
||||
|
||||
$hash->{helper}{FAILED_USERKEYS}{ $values->{USER_KEY} } =
|
||||
"USERKEY "
|
||||
. $values->{USER_KEY}
|
||||
. " invalid - "
|
||||
. $values{result}
|
||||
if ( defined( $values->{USER_KEY} ) );
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
readingsBulkUpdate( $hash, "userState", "valid" )
|
||||
if ( ReadingsVal( $name, "userState", "" ) ne "valid"
|
||||
&& !defined( $values->{USER_KEY} ) );
|
||||
|
||||
delete $hash->{helper}{FAILED_USERKEYS}{ $values->{USER_KEY} }
|
||||
if (
|
||||
!defined( $values->{USER_KEY} )
|
||||
&& defined(
|
||||
$hash->{helper}{FAILED_USERKEYS}{ $values->{USER_KEY} }
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
$state = "limited" if ( $apiRemaining < 1 );
|
||||
|
||||
if ( ref($return) eq "HASH" && defined($return->{token}) ) {
|
||||
$state = "unauthorized";
|
||||
readingsBulkUpdate( $hash, "tokenState", $return->{token} )
|
||||
if ( ReadingsVal($name,"tokenState","") ne $return->{token} );
|
||||
} elsif ( ref($return) ne "HASH" && $return =~ m/"token":"invalid"/ ) {
|
||||
$state = "unauthorized";
|
||||
readingsBulkUpdate( $hash, "tokenState", "invalid" )
|
||||
if ( ReadingsVal($name,"tokenState","") ne "invalid" );
|
||||
} else {
|
||||
readingsBulkUpdate( $hash, "tokenState", "valid" )
|
||||
if ( ReadingsVal($name,"tokenState","") ne "valid" );
|
||||
}
|
||||
|
||||
if ( ref($return) eq "HASH" && defined($return->{user}) ) {
|
||||
|
||||
$state = "unauthorized" if ( !defined($values->{USER_KEY}) );
|
||||
readingsBulkUpdate( $hash, "userState", $return->{user} )
|
||||
if ( ReadingsVal($name,"userState","") ne $return->{user} && !defined($values->{USER_KEY}) );
|
||||
|
||||
$hash->{helper}{FAILED_USERKEYS}{ $values->{USER_KEY} } = "USERKEY ".$values->{USER_KEY}." ".$return->{user}." - ".$values{result}
|
||||
if (defined($values->{USER_KEY}));
|
||||
|
||||
} elsif ( ref($return) ne "HASH" && $return =~ m/"user":"invalid"/ ) {
|
||||
|
||||
$state = "unauthorized" if ( !defined($values->{USER_KEY}) );
|
||||
readingsBulkUpdate( $hash, "userState", "invalid" )
|
||||
if ( ReadingsVal($name,"userState","") ne "invalid" && !defined($values->{USER_KEY}) );
|
||||
|
||||
$hash->{helper}{FAILED_USERKEYS}{ $values->{USER_KEY} } = "USERKEY ".$values->{USER_KEY}." invalid - ".$values{result}
|
||||
if (defined($values->{USER_KEY}));
|
||||
|
||||
} else {
|
||||
|
||||
if ( ReadingsVal( $name, "tokenState", "" ) ne "valid"
|
||||
&& !defined( $values->{USER_KEY} ) );
|
||||
readingsBulkUpdate( $hash, "userState", "valid" )
|
||||
if ( ReadingsVal($name,"userState","") ne "valid" && !defined($values->{USER_KEY}) );
|
||||
|
||||
delete $hash->{helper}{FAILED_USERKEYS}{ $values->{USER_KEY} }
|
||||
if (!defined($values->{USER_KEY}) && defined($hash->{helper}{FAILED_USERKEYS}{ $values->{USER_KEY} }) );
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
$state = "limited" if($apiRemaining < 1);
|
||||
|
||||
readingsBulkUpdate( $hash, "tokenState", "valid" )
|
||||
if ( ReadingsVal($name,"tokenState","") ne "valid" && !defined($values->{USER_KEY}) );
|
||||
readingsBulkUpdate( $hash, "userState", "valid" )
|
||||
if ( ReadingsVal($name,"userState","") ne "valid" && !defined($values->{USER_KEY}) );
|
||||
if ( ReadingsVal( $name, "userState", "" ) ne "valid"
|
||||
&& !defined( $values->{USER_KEY} ) );
|
||||
}
|
||||
|
||||
# messages.json
|
||||
if ( $service eq "messages.json" ) {
|
||||
|
||||
readingsBulkUpdate( $hash, "lastTitle", $values->{title} );
|
||||
readingsBulkUpdate( $hash, "lastMessage", urlDecode($values->{message}) );
|
||||
readingsBulkUpdate( $hash, "lastTitle", $values->{title} );
|
||||
readingsBulkUpdate( $hash, "lastMessage",
|
||||
urlDecode( $values->{message} ) );
|
||||
readingsBulkUpdate( $hash, "lastPriority", $values->{priority} );
|
||||
readingsBulkUpdate( $hash, "lastAction", $values->{action} )
|
||||
if ( $values->{action} ne "" );
|
||||
@ -496,7 +550,8 @@ sub Pushover_ReceiveCommand($$$) {
|
||||
if ( $values->{action} eq "" );
|
||||
readingsBulkUpdate( $hash, "lastDevice", $values->{device} )
|
||||
if ( $values->{device} ne "" );
|
||||
readingsBulkUpdate( $hash, "lastDevice", ReadingsVal($name, "devices", "all") )
|
||||
readingsBulkUpdate( $hash, "lastDevice",
|
||||
ReadingsVal( $name, "devices", "all" ) )
|
||||
if ( $values->{device} eq "" );
|
||||
|
||||
if ( ref($return) eq "HASH" ) {
|
||||
@ -507,8 +562,11 @@ sub Pushover_ReceiveCommand($$$) {
|
||||
if ( $values->{expire} ne "" ) {
|
||||
readingsBulkUpdate( $hash, "cbTitle_" . $values->{cbNr},
|
||||
$values->{title} );
|
||||
readingsBulkUpdate( $hash, "cbMsg_" . $values->{cbNr},
|
||||
urlDecode($values->{message}) );
|
||||
readingsBulkUpdate(
|
||||
$hash,
|
||||
"cbMsg_" . $values->{cbNr},
|
||||
urlDecode( $values->{message} )
|
||||
);
|
||||
readingsBulkUpdate( $hash, "cbPrio_" . $values->{cbNr},
|
||||
$values->{priority} );
|
||||
readingsBulkUpdate( $hash, "cbAck_" . $values->{cbNr},
|
||||
@ -519,8 +577,11 @@ sub Pushover_ReceiveCommand($$$) {
|
||||
$values->{device} );
|
||||
}
|
||||
else {
|
||||
readingsBulkUpdate( $hash, "cbDev_" . $values->{cbNr},
|
||||
ReadingsVal($name, "devices", "all") );
|
||||
readingsBulkUpdate(
|
||||
$hash,
|
||||
"cbDev_" . $values->{cbNr},
|
||||
ReadingsVal( $name, "devices", "all" )
|
||||
);
|
||||
}
|
||||
|
||||
if ( defined $return->{receipt} ) {
|
||||
@ -548,15 +609,16 @@ sub Pushover_ReceiveCommand($$$) {
|
||||
# users/validate.json
|
||||
elsif ( $service eq "users/validate.json" ) {
|
||||
if ( ref($return) eq "HASH" ) {
|
||||
my $devices = "-";
|
||||
my $group = "0";
|
||||
$devices = join( ",", @{ $return->{devices} } ) if (defined($return->{devices}));
|
||||
$group = $return->{group} if (defined($return->{group}));
|
||||
my $devices = "-";
|
||||
my $group = "0";
|
||||
$devices = join( ",", @{ $return->{devices} } )
|
||||
if ( defined( $return->{devices} ) );
|
||||
$group = $return->{group} if ( defined( $return->{group} ) );
|
||||
|
||||
readingsBulkUpdate( $hash, "devices", $devices )
|
||||
if ( ReadingsVal($name,"devices","") ne $devices );
|
||||
readingsBulkUpdate( $hash, "group", $group )
|
||||
if ( ReadingsVal($name,"group","") ne $group );
|
||||
readingsBulkUpdate( $hash, "devices", $devices )
|
||||
if ( ReadingsVal( $name, "devices", "" ) ne $devices );
|
||||
readingsBulkUpdate( $hash, "group", $group )
|
||||
if ( ReadingsVal( $name, "group", "" ) ne $group );
|
||||
}
|
||||
}
|
||||
|
||||
@ -566,33 +628,43 @@ sub Pushover_ReceiveCommand($$$) {
|
||||
# Set reading for availability
|
||||
#
|
||||
my $available = 0;
|
||||
$available = 1 if ( $param->{code} ne "429" && ($state eq "connected" || $state eq "error") );
|
||||
$available = 1
|
||||
if ( $param->{code} ne "429"
|
||||
&& ( $state eq "connected" || $state eq "error" ) );
|
||||
readingsBulkUpdate( $hash, "available", $available )
|
||||
if ( ReadingsVal($name,"available","") ne $available );
|
||||
if ( ReadingsVal( $name, "available", "" ) ne $available );
|
||||
|
||||
# Set reading for state
|
||||
#
|
||||
readingsBulkUpdate( $hash, "state", $state )
|
||||
if ( ReadingsVal($name,"state","") ne $state );
|
||||
if ( ReadingsVal( $name, "state", "" ) ne $state );
|
||||
|
||||
# credentials validation loop
|
||||
#
|
||||
my $nextTimer = "none";
|
||||
|
||||
# if we could not connect, try again in 5 minutes
|
||||
if ($state eq "disconnected") {
|
||||
$nextTimer = gettimeofday() + 300;
|
||||
if ( $state eq "disconnected" ) {
|
||||
$nextTimer = gettimeofday() + 300;
|
||||
|
||||
}
|
||||
|
||||
# re-validate every 6 hours if there was no message sent during
|
||||
# that time
|
||||
elsif ( $available eq "1" ) {
|
||||
$nextTimer = gettimeofday() + 21600;
|
||||
|
||||
}
|
||||
|
||||
# re-validate every 6 hours if there was no message sent during that time
|
||||
} elsif ($available eq "1") {
|
||||
$nextTimer = gettimeofday() + 21600;
|
||||
# re-validate after API limit was reset
|
||||
} elsif ($state eq "limited" || $param->{code} == 429) {
|
||||
$nextTimer = ReadingsVal($name,"apiReset",gettimeofday() + 21277) + 323;
|
||||
elsif ( $state eq "limited" || $param->{code} == 429 ) {
|
||||
$nextTimer =
|
||||
ReadingsVal( $name, "apiReset", gettimeofday() + 21277 ) + 323;
|
||||
}
|
||||
RemoveInternalTimer($hash);
|
||||
$hash->{VALIDATION_TIMER} = $nextTimer;
|
||||
InternalTimer( $nextTimer, "Pushover_ValidateUser", $hash, 0 ) if ($nextTimer ne "none");
|
||||
InternalTimer( $nextTimer, "Pushover_ValidateUser", $hash, 0 )
|
||||
if ( $nextTimer ne "none" );
|
||||
|
||||
readingsEndUpdate( $hash, 1 );
|
||||
|
||||
@ -610,10 +682,11 @@ sub Pushover_ValidateUser ($;$) {
|
||||
RemoveInternalTimer($hash);
|
||||
|
||||
if ( AttrVal( $name, "disable", 0 ) == 1 ) {
|
||||
$hash->{VALIDATION_TIMER} = "disabled";
|
||||
RemoveInternalTimer($hash);
|
||||
InternalTimer( gettimeofday() + 900, "Pushover_ValidateUser", $hash, 0 );
|
||||
return;
|
||||
$hash->{VALIDATION_TIMER} = "disabled";
|
||||
RemoveInternalTimer($hash);
|
||||
InternalTimer( gettimeofday() + 900, "Pushover_ValidateUser", $hash,
|
||||
0 );
|
||||
return;
|
||||
}
|
||||
|
||||
elsif ( $device ne "" ) {
|
||||
@ -634,7 +707,7 @@ sub Pushover_SetMessage {
|
||||
my %values = ();
|
||||
|
||||
#Set defaults
|
||||
$values{title} = AttrVal( $hash->{NAME}, "title", "Information" );
|
||||
$values{title} = AttrVal( $hash->{NAME}, "title", "" );
|
||||
$values{message} = "";
|
||||
$values{device} = AttrVal( $hash->{NAME}, "device", "" );
|
||||
$values{priority} = AttrVal( $hash->{NAME}, "priority", 0 );
|
||||
@ -742,20 +815,24 @@ sub Pushover_SetMessage {
|
||||
$values{action} = $1;
|
||||
}
|
||||
|
||||
# check if we got a user or group key as device and use it as user-key instead of hash->USER_KEY
|
||||
# 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_-]+))?$/s ) {
|
||||
$values{USER_KEY} = $1;
|
||||
$values{device} = $3;
|
||||
$values{USER_KEY} = $1;
|
||||
$values{device} = $3;
|
||||
|
||||
return $hash->{helper}{FAILED_USERKEYS}{ $values{USER_KEY} }
|
||||
if (defined($hash->{helper}{FAILED_USERKEYS}{ $values{USER_KEY} }) );
|
||||
return $hash->{helper}{FAILED_USERKEYS}{ $values{USER_KEY} }
|
||||
if (
|
||||
defined( $hash->{helper}{FAILED_USERKEYS}{ $values{USER_KEY} } ) );
|
||||
}
|
||||
|
||||
#Check if all mandatory arguments are filled
|
||||
#"title" and "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
|
||||
# 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{title} ne "" && $values{message} ne "" )
|
||||
$values{message} ne ""
|
||||
&& ( ( $values{retry} ne "" && $values{expire} ne "" )
|
||||
|| $values{priority} < 2 )
|
||||
&& (
|
||||
@ -768,7 +845,9 @@ sub Pushover_SetMessage {
|
||||
)
|
||||
)
|
||||
{
|
||||
my $body = "title=" . urlEncode( $values{title} );
|
||||
my $body;
|
||||
$body = "title=" . urlEncode( $values{title} )
|
||||
if ( $values{title} ne "" );
|
||||
|
||||
if ( $values{message} =~
|
||||
/\<(\/|)[biu]\>|\<(\/|)font(.+)\>|\<(\/|)a(.*)\>|\<br\s?\/?\>/
|
||||
@ -776,7 +855,9 @@ sub Pushover_SetMessage {
|
||||
{
|
||||
Log3 $name, 4, "Pushover $name: handling message with HTML content";
|
||||
$body = $body . "&html=1";
|
||||
$values{message} =~ s/(?<!\\)(\\n)/<br \/>/g; # replace \n by <br /> but ignore \\n
|
||||
|
||||
# replace \n by <br /> but ignore \\n
|
||||
$values{message} =~ s/(?<!\\)(\\n)/<br \/>/g;
|
||||
}
|
||||
|
||||
elsif ( $values{message} =~ /^nohtml:.*/ ) {
|
||||
@ -785,9 +866,16 @@ sub Pushover_SetMessage {
|
||||
$values{message} =~ s/^(nohtml:).*//;
|
||||
}
|
||||
|
||||
$values{message} = urlEncode( $values{message} ); # HttpUtil's urlEncode() does not handle \n but would escape % so we encode first
|
||||
$values{message} =~ s/(?<!%5c)(%5cn)/%0a/g; # replace any URL-encoded \n with their hex equivalent but ignore \\n
|
||||
$values{message} =~ s/%5c%5cn/%5cn/g; # replace any URL-encoded \\n by \n
|
||||
# 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/(?<!%5c)(%5cn)/%0a/g;
|
||||
|
||||
# replace any URL-encoded \\n by \n
|
||||
$values{message} =~ s/%5c%5cn/%5cn/g;
|
||||
|
||||
$body = $body . "&message=" . $values{message};
|
||||
|
||||
if ( $values{device} ne "" ) {
|
||||
@ -795,8 +883,8 @@ sub Pushover_SetMessage {
|
||||
}
|
||||
|
||||
if ( $values{priority} ne "" ) {
|
||||
$values{priority} = 2 if ($values{priority} > 2);
|
||||
$values{priority} = -2 if ($values{priority} < -2);
|
||||
$values{priority} = 2 if ( $values{priority} > 2 );
|
||||
$values{priority} = -2 if ( $values{priority} < -2 );
|
||||
$body = $body . "&priority=" . $values{priority};
|
||||
}
|
||||
|
||||
@ -813,7 +901,7 @@ sub Pushover_SetMessage {
|
||||
|
||||
$values{cbNr} = int( time() ) + $values{expire};
|
||||
my $cbReading = "cb_" . $values{cbNr};
|
||||
until ( ReadingsVal($name, $cbReading, "") eq "" ) {
|
||||
until ( ReadingsVal( $name, $cbReading, "" ) eq "" ) {
|
||||
$values{cbNr}++;
|
||||
$cbReading = "cb_" . $values{cbNr};
|
||||
}
|
||||
@ -854,7 +942,9 @@ sub Pushover_SetMessage {
|
||||
}
|
||||
|
||||
Log3 $name, 5,
|
||||
"Pushover $name: Adding supplementary URL '$values{url_title}' ($url) with action '$values{action}' (expires after $values{expire} => $values{cbNr})";
|
||||
"Pushover $name: Adding supplementary URL '$values{url_title}' ($url) with "
|
||||
. "action '$values{action}' (expires after $values{expire} => "
|
||||
. "$values{cbNr})";
|
||||
$body =
|
||||
$body
|
||||
. "&url_title="
|
||||
@ -881,11 +971,11 @@ sub Pushover_SetMessage {
|
||||
. $hash->{NAME}
|
||||
. " $key: time="
|
||||
. $rBase[1] . " ack="
|
||||
. ReadingsVal($name, $rAck, "-")
|
||||
. ReadingsVal( $name, $rAck, "-" )
|
||||
. " curTime="
|
||||
. int( time() );
|
||||
|
||||
if ( ReadingsVal($name, $rAck, 0) == 1
|
||||
if ( ReadingsVal( $name, $rAck, 0 ) == 1
|
||||
|| $rBase[1] <= int( time() ) )
|
||||
{
|
||||
delete $hash->{READINGS}{$key};
|
||||
@ -916,14 +1006,17 @@ sub Pushover_SetMessage {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
#There was a problem with the arguments, so tell the user the correct usage of the 'set msg' command
|
||||
|
||||
# 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 ['<title>'] '<msg>' ['<device>' <priority> '<sound>' [<retry> <expire> ['<url_title>' '<action>']]]";
|
||||
"Syntax: $name msg ['<title>'] '<msg>' ['<device>' <priority> '<sound>' "
|
||||
. "[<retry> <expire> ['<url_title>' '<action>']]]";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1005,7 +1098,7 @@ sub Pushover_CGI() {
|
||||
if ( !defined( $webArgs->{acknowledged_by} )
|
||||
|| $webArgs->{acknowledged_by} ne $hash->{USER_KEY} );
|
||||
|
||||
if ( ReadingsVal($name, $rAck, 1) == 0
|
||||
if ( ReadingsVal( $name, $rAck, 1 ) == 0
|
||||
&& $rBase[1] > int( time() ) )
|
||||
{
|
||||
readingsBeginUpdate($hash);
|
||||
@ -1027,19 +1120,20 @@ sub Pushover_CGI() {
|
||||
my $redirect = "";
|
||||
|
||||
# run FHEM command if desired
|
||||
if ( ReadingsVal($name, $rAct, "pushover://") !~ /^[\w-]+:\/\/.*$/ )
|
||||
if ( ReadingsVal( $name, $rAct, "pushover://" ) !~
|
||||
/^[\w-]+:\/\/.*$/ )
|
||||
{
|
||||
$redirect = "pushover://";
|
||||
|
||||
fhem ReadingsVal($name, $rAct, "");
|
||||
fhem ReadingsVal( $name, $rAct, "" );
|
||||
readingsBulkUpdate( $hash, $rAct,
|
||||
"executed: " . ReadingsVal($name, $rAct, ""));
|
||||
"executed: " . ReadingsVal( $name, $rAct, "" ) );
|
||||
}
|
||||
|
||||
# redirect to presented URL
|
||||
if ( ReadingsVal($name, $rAct, "none") =~ /^[\w-]+:\/\/.*$/ )
|
||||
if ( ReadingsVal( $name, $rAct, "none" ) =~ /^[\w-]+:\/\/.*$/ )
|
||||
{
|
||||
$redirect = ReadingsVal($name, $rAct, "");
|
||||
$redirect = ReadingsVal( $name, $rAct, "" );
|
||||
}
|
||||
|
||||
readingsEndUpdate( $hash, 1 );
|
||||
@ -1050,7 +1144,8 @@ sub Pushover_CGI() {
|
||||
. $redirect
|
||||
. "\"></head><body><a href=\""
|
||||
. $redirect
|
||||
. "\">Click here to get redirected to your destination</a></body></html>"
|
||||
. "\">Click here to get redirected to your destination"
|
||||
. "</a></body></html>"
|
||||
) if ( $redirect ne "" );
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user