mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-08 01:14:19 +00:00
Pushover: fix attributes
git-svn-id: https://svn.fhem.de/fhem/trunk@9146 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
fd61da6488
commit
7fa6d77afd
@ -376,70 +376,68 @@ sub Pushover_ReceiveCommand($$$) {
|
|||||||
if ( ref($return) eq "HASH" ) {
|
if ( ref($return) eq "HASH" ) {
|
||||||
|
|
||||||
if ( $return->{status} ne "1" && defined $return->{errors} ) {
|
if ( $return->{status} ne "1" && defined $return->{errors} ) {
|
||||||
$values->{result} =
|
$values{result} =
|
||||||
"Error: " . Dumper( $return->{errors} );
|
"Error: " . Dumper( $return->{errors} );
|
||||||
$state = "error";
|
$state = "error";
|
||||||
}
|
}
|
||||||
elsif ( $return->{status} ne "1" ) {
|
elsif ( $return->{status} ne "1" ) {
|
||||||
$values->{result} = "Unspecified error";
|
$values{result} = "Unspecified error";
|
||||||
$state = "error";
|
$state = "error";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
$values->{result} = "ok";
|
$values{result} = "ok";
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "lastTitle", $values->{title} );
|
readingsBulkUpdate( $hash, "lastTitle", $values{title} );
|
||||||
readingsBulkUpdate( $hash, "lastMessage",
|
readingsBulkUpdate( $hash, "lastMessage",
|
||||||
$values->{message} );
|
$values{message} );
|
||||||
readingsBulkUpdate( $hash, "lastPriority",
|
readingsBulkUpdate( $hash, "lastPriority",
|
||||||
$values->{priority} );
|
$values{priority} );
|
||||||
readingsBulkUpdate( $hash, "lastAction", $values->{action} )
|
readingsBulkUpdate( $hash, "lastAction", $values{action} )
|
||||||
if ( $values->{action} ne "" );
|
if ( $values{action} ne "" );
|
||||||
readingsBulkUpdate( $hash, "lastAction", "-" )
|
readingsBulkUpdate( $hash, "lastAction", "-" )
|
||||||
if ( $values->{action} eq "" );
|
if ( $values{action} eq "" );
|
||||||
readingsBulkUpdate( $hash, "lastDevice", $values->{device} )
|
readingsBulkUpdate( $hash, "lastDevice", $values{device} )
|
||||||
if ( $values->{device} ne "" );
|
if ( $values{device} ne "" );
|
||||||
readingsBulkUpdate( $hash, "lastDevice", $hash->{DEVICES} )
|
readingsBulkUpdate( $hash, "lastDevice", $hash->{DEVICES} )
|
||||||
if ( $values->{device} eq "" );
|
if ( $values{device} eq "" );
|
||||||
|
|
||||||
if ( defined $return->{request} ) {
|
if ( defined $return->{request} ) {
|
||||||
readingsBulkUpdate( $hash, "lastRequest",
|
readingsBulkUpdate( $hash, "lastRequest",
|
||||||
$return->{request} );
|
$return->{request} );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $values->{expire} ne "" ) {
|
if ( $values{expire} ne "" ) {
|
||||||
readingsBulkUpdate( $hash, "cbTitle_" . $values->{cbNr},
|
readingsBulkUpdate( $hash, "cbTitle_" . $values{cbNr},
|
||||||
$values->{title} );
|
$values{title} );
|
||||||
readingsBulkUpdate( $hash, "cbMsg_" . $values->{cbNr},
|
readingsBulkUpdate( $hash, "cbMsg_" . $values{cbNr},
|
||||||
$values->{message} );
|
$values{message} );
|
||||||
readingsBulkUpdate( $hash, "cbPrio_" . $values->{cbNr},
|
readingsBulkUpdate( $hash, "cbPrio_" . $values{cbNr},
|
||||||
$values->{priority} );
|
$values{priority} );
|
||||||
readingsBulkUpdate( $hash, "cbAck_" . $values->{cbNr},
|
readingsBulkUpdate( $hash, "cbAck_" . $values{cbNr},
|
||||||
"0" );
|
"0" );
|
||||||
|
|
||||||
if ( $values->{device} ne "" ) {
|
if ( $values{device} ne "" ) {
|
||||||
readingsBulkUpdate( $hash,
|
readingsBulkUpdate( $hash, "cbDev_" . $values{cbNr},
|
||||||
"cbDev_" . $values->{cbNr},
|
$values{device} );
|
||||||
$values->{device} );
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
readingsBulkUpdate( $hash,
|
readingsBulkUpdate( $hash,
|
||||||
"cbDev_" . $values->{cbNr}, "all" );
|
"cbDev_" . $values{cbNr}, "all" );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( defined $return->{receipt} ) {
|
if ( defined $return->{receipt} ) {
|
||||||
readingsBulkUpdate( $hash, "cb_" . $values->{cbNr},
|
readingsBulkUpdate( $hash, "cb_" . $values{cbNr},
|
||||||
$return->{receipt} );
|
$return->{receipt} );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
readingsBulkUpdate( $hash, "cb_" . $values->{cbNr},
|
readingsBulkUpdate( $hash, "cb_" . $values{cbNr},
|
||||||
$values->{cbNr} );
|
$values{cbNr} );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $values->{action} ne "" ) {
|
if ( $values{action} ne "" ) {
|
||||||
readingsBulkUpdate( $hash,
|
readingsBulkUpdate( $hash, "cbAct_" . $values{cbNr},
|
||||||
"cbAct_" . $values->{cbNr},
|
$values{action} );
|
||||||
$values->{action} );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -451,23 +449,23 @@ sub Pushover_ReceiveCommand($$$) {
|
|||||||
if ( ref($return) eq "HASH" ) {
|
if ( ref($return) eq "HASH" ) {
|
||||||
|
|
||||||
if ( $return->{status} ne "1" && defined $return->{errors} ) {
|
if ( $return->{status} ne "1" && defined $return->{errors} ) {
|
||||||
$values->{result} =
|
$values{result} =
|
||||||
"Error: " . Dumper( $return->{errors} );
|
"Error: " . Dumper( $return->{errors} );
|
||||||
$state = "unauthorized";
|
$state = "unauthorized";
|
||||||
}
|
}
|
||||||
elsif ( $return->{status} ne "1" ) {
|
elsif ( $return->{status} ne "1" ) {
|
||||||
$values->{result} = "Unspecified error";
|
$values{result} = "Unspecified error";
|
||||||
$state = "unauthorized";
|
$state = "unauthorized";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$values->{result} = "ok";
|
$values{result} = "ok";
|
||||||
$hash->{DEVICES} = join( ",", @{ $return->{devices} } );
|
$hash->{DEVICES} = join( ",", @{ $return->{devices} } );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "lastResult", $values->{result} );
|
readingsBulkUpdate( $hash, "lastResult", $values{result} );
|
||||||
}
|
}
|
||||||
|
|
||||||
# Set reading for state
|
# Set reading for state
|
||||||
@ -490,15 +488,15 @@ sub Pushover_SetMessage {
|
|||||||
my %values = ();
|
my %values = ();
|
||||||
|
|
||||||
#Set defaults
|
#Set defaults
|
||||||
my $values->{title} = AttrVal( $hash->{NAME}, "title", "" );
|
$values{title} = AttrVal( $hash->{NAME}, "title", "Information" );
|
||||||
my $values->{message} = "";
|
$values{message} = "";
|
||||||
my $values->{device} = AttrVal( $hash->{NAME}, "device", "" );
|
$values{device} = AttrVal( $hash->{NAME}, "device", "" );
|
||||||
my $values->{priority} = AttrVal( $hash->{NAME}, "priority", 0 );
|
$values{priority} = AttrVal( $hash->{NAME}, "priority", 0 );
|
||||||
my $values->{sound} = AttrVal( $hash->{NAME}, "sound", "" );
|
$values{sound} = AttrVal( $hash->{NAME}, "sound", "" );
|
||||||
my $values->{retry} = "";
|
$values{retry} = "";
|
||||||
my $values->{expire} = "";
|
$values{expire} = "";
|
||||||
my $values->{url_title} = "";
|
$values{url_title} = "";
|
||||||
my $values->{action} = "";
|
$values{action} = "";
|
||||||
|
|
||||||
my $callback = (
|
my $callback = (
|
||||||
defined( $attr{$name}{callbackUrl} )
|
defined( $attr{$name}{callbackUrl} )
|
||||||
@ -535,116 +533,116 @@ sub Pushover_SetMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( $argc > 1 ) {
|
if ( $argc > 1 ) {
|
||||||
$values->{title} = $1;
|
$values{title} = $1 if ( $1 ne "" );
|
||||||
$values->{message} = $2;
|
$values{message} = $2 if ( $2 ne "" );
|
||||||
|
|
||||||
if ( $argc > 2 ) {
|
if ( $argc > 2 ) {
|
||||||
$values->{device} = $3;
|
$values{device} = $3 if ( $3 ne "" );
|
||||||
$values->{priority} = $4;
|
$values{priority} = $4 if ( $4 ne "" );
|
||||||
$values->{sound} = $5;
|
$values{sound} = $5 if ( $5 ne "" );
|
||||||
|
|
||||||
if ( $argc > 5 ) {
|
if ( $argc > 5 ) {
|
||||||
$values->{retry} = $6;
|
$values{retry} = $6 if ( $6 ne "" );
|
||||||
$values->{expire} = $7;
|
$values{expire} = $7 if ( $7 ne "" );
|
||||||
|
|
||||||
if ( $argc > 7 ) {
|
if ( $argc > 7 ) {
|
||||||
$values->{url_title} = $8;
|
$values{url_title} = $8 if ( $8 ne "" );
|
||||||
$values->{action} = $9;
|
$values{action} = $9 if ( $9 ne "" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elsif ( $argc == 1 ) {
|
elsif ( $argc == 1 ) {
|
||||||
$values->{message} = $1;
|
$values{message} = $1 if ( $1 ne "" );
|
||||||
}
|
}
|
||||||
|
|
||||||
#Remove quotation marks
|
#Remove quotation marks
|
||||||
if ( $values->{title} =~ /^['"](.*)['"]$/s ) {
|
if ( $values{title} =~ /^['"](.*)['"]$/s ) {
|
||||||
$values->{title} = $1;
|
$values{title} = $1;
|
||||||
}
|
}
|
||||||
if ( $values->{message} =~ /^['"](.*)['"]$/s ) {
|
if ( $values{message} =~ /^['"](.*)['"]$/s ) {
|
||||||
$values->{message} = $1;
|
$values{message} = $1;
|
||||||
}
|
}
|
||||||
if ( $values->{device} =~ /^['"](.*)['"]$/s ) {
|
if ( $values{device} =~ /^['"](.*)['"]$/s ) {
|
||||||
$values->{device} = $1;
|
$values{device} = $1;
|
||||||
}
|
}
|
||||||
if ( $values->{priority} =~ /^['"](.*)['"]$/s ) {
|
if ( $values{priority} =~ /^['"](.*)['"]$/s ) {
|
||||||
$values->{priority} = $1;
|
$values{priority} = $1;
|
||||||
}
|
}
|
||||||
if ( $values->{sound} =~ /^['"](.*)['"]$/s ) {
|
if ( $values{sound} =~ /^['"](.*)['"]$/s ) {
|
||||||
$values->{sound} = $1;
|
$values{sound} = $1;
|
||||||
}
|
}
|
||||||
if ( $values->{retry} =~ /^['"](.*)['"]$/s ) {
|
if ( $values{retry} =~ /^['"](.*)['"]$/s ) {
|
||||||
$values->{retry} = $1;
|
$values{retry} = $1;
|
||||||
}
|
}
|
||||||
if ( $values->{expire} =~ /^['"](.*)['"]$/s ) {
|
if ( $values{expire} =~ /^['"](.*)['"]$/s ) {
|
||||||
$values->{expire} = $1;
|
$values{expire} = $1;
|
||||||
}
|
}
|
||||||
if ( $values->{url_title} =~ /^['"](.*)['"]$/s ) {
|
if ( $values{url_title} =~ /^['"](.*)['"]$/s ) {
|
||||||
$values->{url_title} = $1;
|
$values{url_title} = $1;
|
||||||
}
|
}
|
||||||
if ( $values->{action} =~ /^['"](.*)['"]$/s ) {
|
if ( $values{action} =~ /^['"](.*)['"]$/s ) {
|
||||||
$values->{action} = $1;
|
$values{action} = $1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#Check if all mandatory arguments are filled
|
#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
|
#"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
|
#"url_title" and "action" need to be set together and require "expire" to be set as well
|
||||||
if (
|
if (
|
||||||
( $values->{title} ne "" && $values->{message} ne "" )
|
( $values{title} ne "" && $values{message} ne "" )
|
||||||
&& ( ( $values->{retry} ne "" && $values->{expire} ne "" )
|
&& ( ( $values{retry} ne "" && $values{expire} ne "" )
|
||||||
|| $values->{priority} < 2 )
|
|| $values{priority} < 2 )
|
||||||
&& (
|
&& (
|
||||||
(
|
(
|
||||||
$values->{url_title} ne ""
|
$values{url_title} ne ""
|
||||||
&& $values->{action} ne ""
|
&& $values{action} ne ""
|
||||||
&& $values->{expire} ne ""
|
&& $values{expire} ne ""
|
||||||
)
|
)
|
||||||
|| ( $values->{url_title} eq "" && $values->{action} eq "" )
|
|| ( $values{url_title} eq "" && $values{action} eq "" )
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
my $body = "title=" . $values->{title};
|
my $body = "title=" . $values{title};
|
||||||
|
|
||||||
if ( $values->{message} =~
|
if ( $values{message} =~
|
||||||
/\<(\/|)[biu]\>|\<(\/|)font(.+)\>|\<(\/|)a(.*)\>/
|
/\<(\/|)[biu]\>|\<(\/|)font(.+)\>|\<(\/|)a(.*)\>/
|
||||||
&& $values->{message} !~ /^nohtml:.*/ )
|
&& $values{message} !~ /^nohtml:.*/ )
|
||||||
{
|
{
|
||||||
Log3 $name, 4, "handling message with HTML content";
|
Log3 $name, 4, "handling message with HTML content";
|
||||||
$body = $body . "&html=1";
|
$body = $body . "&html=1";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $values->{message} =~ /^nohtml:.*/ ) {
|
if ( $values{message} =~ /^nohtml:.*/ ) {
|
||||||
Log3 $name, 4, "explicitly ignoring HTML tags in message";
|
Log3 $name, 4, "explicitly ignoring HTML tags in message";
|
||||||
$values->{message} =~ s/^(nohtml:).*//;
|
$values{message} =~ s/^(nohtml:).*//;
|
||||||
$body = $body . "&message=" . $values->{message};
|
$body = $body . "&message=" . $values{message};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$body = $body . "&message=" . $values->{message};
|
$body = $body . "&message=" . $values{message};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $values->{device} ne "" ) {
|
if ( $values{device} ne "" ) {
|
||||||
$body = $body . "&" . "device=" . $values->{device};
|
$body = $body . "&" . "device=" . $values{device};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $values->{priority} ne "" ) {
|
if ( $values{priority} ne "" ) {
|
||||||
$body = $body . "&" . "priority=" . $values->{priority};
|
$body = $body . "&" . "priority=" . $values{priority};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $values->{sound} ne "" ) {
|
if ( $values{sound} ne "" ) {
|
||||||
$body = $body . "&" . "sound=" . $values->{sound};
|
$body = $body . "&" . "sound=" . $values{sound};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $values->{retry} ne "" ) {
|
if ( $values{retry} ne "" ) {
|
||||||
$body = $body . "&" . "retry=" . $values->{retry};
|
$body = $body . "&" . "retry=" . $values{retry};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $values->{expire} ne "" ) {
|
if ( $values{expire} ne "" ) {
|
||||||
$body = $body . "&" . "expire=" . $values->{expire};
|
$body = $body . "&" . "expire=" . $values{expire};
|
||||||
|
|
||||||
$values->{cbNr} = int( time() ) + $values->{expire};
|
$values{cbNr} = int( time() ) + $values{expire};
|
||||||
my $cbReading = "cb_" . $values->{cbNr};
|
my $cbReading = "cb_" . $values{cbNr};
|
||||||
$values->{cbNr}++
|
$values{cbNr}++
|
||||||
until ( !defined( $hash->{READINGS}{$cbReading}{VAL} ) );
|
until ( !defined( $hash->{READINGS}{$cbReading}{VAL} ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -654,23 +652,23 @@ sub Pushover_SetMessage {
|
|||||||
$body = $body . "&" . "timestamp=" . int( time() );
|
$body = $body . "&" . "timestamp=" . int( time() );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $callback ne "" && $values->{priority} > 1 ) {
|
if ( $callback ne "" && $values{priority} > 1 ) {
|
||||||
Log3 $name, 5, "Adding emergency callback URL $callback";
|
Log3 $name, 5, "Adding emergency callback URL $callback";
|
||||||
$body = $body . "&callback=" . $callback;
|
$body = $body . "&callback=" . $callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $values->{url_title} ne ""
|
if ( $values{url_title} ne ""
|
||||||
&& $values->{action} ne ""
|
&& $values{action} ne ""
|
||||||
&& $values->{expire} ne "" )
|
&& $values{expire} ne "" )
|
||||||
{
|
{
|
||||||
my $url;
|
my $url;
|
||||||
|
|
||||||
if ( $callback eq ""
|
if ( $callback eq ""
|
||||||
|| $values->{action} !~
|
|| $values{action} !~
|
||||||
/(?:https?:\/\/)(?:[\w]+\.)([a-zA-Z\.]{2,63})([\/\w\.-]*)*\/?/ )
|
/(?:https?:\/\/)(?:[\w]+\.)([a-zA-Z\.]{2,63})([\/\w\.-]*)*\/?/ )
|
||||||
{
|
{
|
||||||
$url = $values->{action};
|
$url = $values{action};
|
||||||
$values->{expire} = "";
|
$values{expire} = "";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$url =
|
$url =
|
||||||
@ -678,15 +676,15 @@ sub Pushover_SetMessage {
|
|||||||
. "?acknowledged=1&acknowledged_by="
|
. "?acknowledged=1&acknowledged_by="
|
||||||
. $hash->{USER_KEY}
|
. $hash->{USER_KEY}
|
||||||
. "&FhemCallbackId="
|
. "&FhemCallbackId="
|
||||||
. $values->{cbNr};
|
. $values{cbNr};
|
||||||
}
|
}
|
||||||
|
|
||||||
Log3 $name, 5,
|
Log3 $name, 5,
|
||||||
"Adding supplementary URL '$values->{url_title}' ($url) with action '$values->{action}' (expires after $values->{expire} => $values->{cbNr})";
|
"Adding supplementary URL '$values{url_title}' ($url) with action '$values{action}' (expires after $values{expire} => $values{cbNr})";
|
||||||
$body =
|
$body =
|
||||||
$body
|
$body
|
||||||
. "&url_title="
|
. "&url_title="
|
||||||
. urlEncode( $values->{url_title} ) . "&url="
|
. urlEncode( $values{url_title} ) . "&url="
|
||||||
. urlEncode($url);
|
. urlEncode($url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -743,7 +741,7 @@ sub Pushover_SetMessage {
|
|||||||
}
|
}
|
||||||
else {
|
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 "" ) ) {
|
if ( 1 == $argc && $values{title} eq "" ) {
|
||||||
return
|
return
|
||||||
"Please define the default title in the pushover device arguments.";
|
"Please define the default title in the pushover device arguments.";
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user