mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-03 16:56:54 +00:00
70_Pushover: revert file added by accident in commit 9761
git-svn-id: https://svn.fhem.de/fhem/trunk@9762 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
de34c65c64
commit
1cce897457
@ -136,11 +136,7 @@ sub Pushover_Define($$) {
|
|||||||
|
|
||||||
# start Validation Timer
|
# start Validation Timer
|
||||||
RemoveInternalTimer($hash);
|
RemoveInternalTimer($hash);
|
||||||
if (ReadingsVal($name,"tokenState","invalid") ne "valid" || ReadingsVal($name,"userState","invalid") ne "valid" || $init_done) {
|
InternalTimer( gettimeofday() + 5, "Pushover_ValidateUser", $hash, 0 );
|
||||||
InternalTimer( gettimeofday() + 5, "Pushover_ValidateUser", $hash, 0 );
|
|
||||||
} else {
|
|
||||||
InternalTimer( gettimeofday() + 21600, "Pushover_ValidateUser", $hash, 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@ -174,17 +170,13 @@ sub Pushover_Set($@) {
|
|||||||
. join( " ", sort keys %sets );
|
. join( " ", sort keys %sets );
|
||||||
}
|
}
|
||||||
|
|
||||||
return "Unable to send message: Device is disabled"
|
if ( AttrVal( $name, "disable", 0 ) == 1 ) {
|
||||||
if ( AttrVal( $name, "disable", 0 ) == 1 );
|
return "Device is disabled";
|
||||||
|
}
|
||||||
|
|
||||||
return "Unable to send message: User key is invalid"
|
if ( $cmd eq 'msg' ) {
|
||||||
if ( ReadingsVal( $name, "userState", "invalid" ) eq "invalid" );
|
return Pushover_SetMessage( $hash, @args );
|
||||||
|
}
|
||||||
return "Unable to send message: App token is invalid"
|
|
||||||
if ( ReadingsVal( $name, "tokenState", "invalid" ) eq "invalid" );
|
|
||||||
|
|
||||||
return Pushover_SetMessage( $hash, @args )
|
|
||||||
if ( $cmd eq 'msg' );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
@ -318,7 +310,7 @@ sub Pushover_ReceiveCommand($$$) {
|
|||||||
my $values = $param->{type};
|
my $values = $param->{type};
|
||||||
my $return;
|
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: called function Pushover_ReceiveCommand()";
|
||||||
|
|
||||||
readingsBeginUpdate($hash);
|
readingsBeginUpdate($hash);
|
||||||
|
|
||||||
@ -386,81 +378,6 @@ sub Pushover_ReceiveCommand($$$) {
|
|||||||
#
|
#
|
||||||
|
|
||||||
$values{result} = "ok";
|
$values{result} = "ok";
|
||||||
|
|
||||||
# extract API stats
|
|
||||||
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-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 );
|
|
||||||
}
|
|
||||||
|
|
||||||
# Server error
|
|
||||||
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}) {
|
|
||||||
$values{result} =
|
|
||||||
"Error " . $param->{code} . ": " . join( ". ", @{ $return->{errors} } ) . ".";
|
|
||||||
}
|
|
||||||
elsif ( ref($return) ne "HASH" && $return =~ m/"errors":\[(.*)\]/ ) {
|
|
||||||
$values{result} = "Error " . $param->{code} . ": " . $1;
|
|
||||||
}
|
|
||||||
|
|
||||||
$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";
|
|
||||||
readingsBulkUpdate( $hash, "tokenState", $return->{user} )
|
|
||||||
if ( ReadingsVal($name,"tokenState","") ne $return->{user} );
|
|
||||||
} elsif ( ref($return) ne "HASH" && $return =~ m/"user":"invalid"/ ) {
|
|
||||||
$state = "unauthorized";
|
|
||||||
readingsBulkUpdate( $hash, "userState", "invalid" )
|
|
||||||
if ( ReadingsVal($name,"userState","") ne "invalid" );
|
|
||||||
} else {
|
|
||||||
readingsBulkUpdate( $hash, "userState", "valid" )
|
|
||||||
if ( ReadingsVal($name,"userState","") ne "valid" );
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
$state = "limited" if($apiRemaining < 1);
|
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "tokenState", "valid" )
|
|
||||||
if ( ReadingsVal($name,"tokenState","") ne "valid" );
|
|
||||||
readingsBulkUpdate( $hash, "userState", "valid" )
|
|
||||||
if ( ReadingsVal($name,"userState","") ne "valid" );
|
|
||||||
}
|
|
||||||
|
|
||||||
# messages.json
|
# messages.json
|
||||||
if ( $service eq "messages.json" ) {
|
if ( $service eq "messages.json" ) {
|
||||||
@ -474,11 +391,23 @@ sub Pushover_ReceiveCommand($$$) {
|
|||||||
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", ReadingsVal($name, "devices", "all") )
|
readingsBulkUpdate( $hash, "lastDevice", $hash->{DEVICES} )
|
||||||
if ( $values->{device} eq "" );
|
if ( $values->{device} eq "" && defined( $hash->{DEVICES} ) );
|
||||||
|
readingsBulkUpdate( $hash, "lastDevice", "all" )
|
||||||
|
if ( $values->{device} eq "" && !defined( $hash->{DEVICES} ) );
|
||||||
|
|
||||||
if ( ref($return) eq "HASH" ) {
|
if ( ref($return) eq "HASH" ) {
|
||||||
|
|
||||||
|
if ( $return->{status} ne "1" && defined $return->{errors} ) {
|
||||||
|
$values{result} =
|
||||||
|
"Error: " . Dumper( $return->{errors} );
|
||||||
|
$state = "error";
|
||||||
|
}
|
||||||
|
elsif ( $return->{status} ne "1" ) {
|
||||||
|
$values{result} = "Unspecified error";
|
||||||
|
$state = "error";
|
||||||
|
}
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "lastRequest", $return->{request} )
|
readingsBulkUpdate( $hash, "lastRequest", $return->{request} )
|
||||||
if ( defined $return->{request} );
|
if ( defined $return->{request} );
|
||||||
|
|
||||||
@ -498,7 +427,7 @@ sub Pushover_ReceiveCommand($$$) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
readingsBulkUpdate( $hash, "cbDev_" . $values->{cbNr},
|
readingsBulkUpdate( $hash, "cbDev_" . $values->{cbNr},
|
||||||
ReadingsVal($name, "devices", "all") );
|
$hash->{DEVICES} );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( defined $return->{receipt} ) {
|
if ( defined $return->{receipt} ) {
|
||||||
@ -517,6 +446,16 @@ sub Pushover_ReceiveCommand($$$) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# simple error handling if no JSON module was loaded
|
||||||
|
elsif ( $return !~ m/"status":1,/ ) {
|
||||||
|
$state = "error";
|
||||||
|
if ( $return =~ m/"errors":\[(.*)\]/ ) {
|
||||||
|
$values{result} = "Error: " . $1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$values{result} = "Unspecified error";
|
||||||
|
}
|
||||||
|
}
|
||||||
elsif ( $values{expire} ne "" ) {
|
elsif ( $values{expire} ne "" ) {
|
||||||
$values{result} =
|
$values{result} =
|
||||||
"SoftFail: Callback not supported. Please install Perl::JSON";
|
"SoftFail: Callback not supported. Please install Perl::JSON";
|
||||||
@ -525,17 +464,36 @@ sub Pushover_ReceiveCommand($$$) {
|
|||||||
|
|
||||||
# users/validate.json
|
# users/validate.json
|
||||||
elsif ( $service eq "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}));
|
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "devices", $devices )
|
if ( ref($return) eq "HASH" ) {
|
||||||
if ( ReadingsVal($name,"devices","") ne $devices );
|
|
||||||
readingsBulkUpdate( $hash, "group", $group )
|
if ( $return->{status} ne "1" && defined $return->{errors} ) {
|
||||||
if ( ReadingsVal($name,"group","") ne $group );
|
$values{result} =
|
||||||
|
"Error: " . join( ". ", @{ $return->{errors} } ) . ".";
|
||||||
|
$state = "unauthorized";
|
||||||
|
}
|
||||||
|
elsif ( $return->{status} ne "1" ) {
|
||||||
|
$values{result} = "Unspecified error";
|
||||||
|
$state = "unauthorized";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$hash->{DEVICES} = join( ",", @{ $return->{devices} } );
|
||||||
|
$hash->{GROUP} = $return->{group};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# simple error handling if no JSON module was loaded
|
||||||
|
elsif ( $return !~ m/"status":1,/ ) {
|
||||||
|
$state = "unauthorized";
|
||||||
|
if ( $return =~ m/"errors":\[(.*)\]/ ) {
|
||||||
|
$values{result} = "Error: " . $1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$values{result} = "Unspecified error";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "lastResult", $values{result} );
|
readingsBulkUpdate( $hash, "lastResult", $values{result} );
|
||||||
@ -544,33 +502,25 @@ sub Pushover_ReceiveCommand($$$) {
|
|||||||
# Set reading for availability
|
# Set reading for availability
|
||||||
#
|
#
|
||||||
my $available = 0;
|
my $available = 0;
|
||||||
$available = 1 if ( $param->{code} ne "429" && ($state eq "connected" || $state eq "error") );
|
$available = 1 if ( $state eq "connected" );
|
||||||
readingsBulkUpdate( $hash, "available", $available )
|
if ( !defined( $hash->{READINGS}{available}{VAL} )
|
||||||
if ( ReadingsVal($name,"available","") ne $available );
|
|| $hash->{READINGS}{available}{VAL} ne $available )
|
||||||
|
{
|
||||||
|
readingsBulkUpdate( $hash, "available", $available );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($available eq "0") {
|
||||||
|
RemoveInternalTimer($hash);
|
||||||
|
InternalTimer( gettimeofday() + 900, "Pushover_ValidateUser", $hash, 0 )
|
||||||
|
}
|
||||||
|
|
||||||
# Set reading for state
|
# Set reading for state
|
||||||
#
|
#
|
||||||
readingsBulkUpdate( $hash, "state", $state )
|
if ( !defined( $hash->{READINGS}{state}{VAL} )
|
||||||
if ( ReadingsVal($name,"state","") ne $state );
|
|| $hash->{READINGS}{state}{VAL} ne $state )
|
||||||
|
{
|
||||||
# credentials validation loop
|
readingsBulkUpdate( $hash, "state", $state );
|
||||||
#
|
|
||||||
my $nextTimer = "none";
|
|
||||||
|
|
||||||
# if we could not connect, try again in 5 minutes
|
|
||||||
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 after API limit was reset
|
|
||||||
} 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");
|
|
||||||
|
|
||||||
readingsEndUpdate( $hash, 1 );
|
readingsEndUpdate( $hash, 1 );
|
||||||
|
|
||||||
@ -586,18 +536,18 @@ sub Pushover_ValidateUser ($;$) {
|
|||||||
Log3 $name, 5, "Pushover $name: called function Pushover_ValidateUser()";
|
Log3 $name, 5, "Pushover $name: called function Pushover_ValidateUser()";
|
||||||
|
|
||||||
RemoveInternalTimer($hash);
|
RemoveInternalTimer($hash);
|
||||||
|
if (ReadingsVal($name, "available", "0") ne "1") {
|
||||||
if ( AttrVal( $name, "disable", 0 ) == 1 ) {
|
|
||||||
$hash->{VALIDATION_TIMER} = "disabled";
|
|
||||||
RemoveInternalTimer($hash);
|
|
||||||
InternalTimer( gettimeofday() + 900, "Pushover_ValidateUser", $hash, 0 );
|
InternalTimer( gettimeofday() + 900, "Pushover_ValidateUser", $hash, 0 );
|
||||||
return;
|
} else {
|
||||||
|
InternalTimer( gettimeofday() + 21600, "Pushover_ValidateUser", $hash, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif ( $device ne "" ) {
|
return
|
||||||
|
if ( AttrVal( $name, "disable", 0 ) == 1 );
|
||||||
|
|
||||||
|
if ( $device ne "" ) {
|
||||||
Pushover_SendCommand( $hash, "users/validate.json", "device=$device" );
|
Pushover_SendCommand( $hash, "users/validate.json", "device=$device" );
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
Pushover_SendCommand( $hash, "users/validate.json" );
|
Pushover_SendCommand( $hash, "users/validate.json" );
|
||||||
}
|
}
|
||||||
@ -780,7 +730,7 @@ sub Pushover_SetMessage {
|
|||||||
|
|
||||||
$values{cbNr} = int( time() ) + $values{expire};
|
$values{cbNr} = int( time() ) + $values{expire};
|
||||||
my $cbReading = "cb_" . $values{cbNr};
|
my $cbReading = "cb_" . $values{cbNr};
|
||||||
until ( ReadingsVal($name, $cbReading, "") eq "" ) {
|
until ( !defined( $hash->{READINGS}{$cbReading}{VAL} ) ) {
|
||||||
$values{cbNr}++;
|
$values{cbNr}++;
|
||||||
$cbReading = "cb_" . $values{cbNr};
|
$cbReading = "cb_" . $values{cbNr};
|
||||||
}
|
}
|
||||||
@ -848,11 +798,11 @@ sub Pushover_SetMessage {
|
|||||||
. $hash->{NAME}
|
. $hash->{NAME}
|
||||||
. " $key: time="
|
. " $key: time="
|
||||||
. $rBase[1] . " ack="
|
. $rBase[1] . " ack="
|
||||||
. ReadingsVal($name, $rAck, "-")
|
. $hash->{READINGS}{$rAck}{VAL}
|
||||||
. " curTime="
|
. " curTime="
|
||||||
. int( time() );
|
. int( time() );
|
||||||
|
|
||||||
if ( ReadingsVal($name, $rAck, 0) == 1
|
if ( $hash->{READINGS}{$rAck}{VAL} == 1
|
||||||
|| $rBase[1] <= int( time() ) )
|
|| $rBase[1] <= int( time() ) )
|
||||||
{
|
{
|
||||||
delete $hash->{READINGS}{$key};
|
delete $hash->{READINGS}{$key};
|
||||||
@ -972,7 +922,7 @@ sub Pushover_CGI() {
|
|||||||
if ( !defined( $webArgs->{acknowledged_by} )
|
if ( !defined( $webArgs->{acknowledged_by} )
|
||||||
|| $webArgs->{acknowledged_by} ne $hash->{USER_KEY} );
|
|| $webArgs->{acknowledged_by} ne $hash->{USER_KEY} );
|
||||||
|
|
||||||
if ( ReadingsVal($name, $rAck, 1) == 0
|
if ( $hash->{READINGS}{$rAck}{VAL} == 0
|
||||||
&& $rBase[1] > int( time() ) )
|
&& $rBase[1] > int( time() ) )
|
||||||
{
|
{
|
||||||
readingsBeginUpdate($hash);
|
readingsBeginUpdate($hash);
|
||||||
@ -994,19 +944,21 @@ sub Pushover_CGI() {
|
|||||||
my $redirect = "";
|
my $redirect = "";
|
||||||
|
|
||||||
# run FHEM command if desired
|
# run FHEM command if desired
|
||||||
if ( ReadingsVal($name, $rAct, "pushover://") !~ /^[\w-]+:\/\/.*$/ )
|
if ( defined( $hash->{READINGS}{$rAct}{VAL} )
|
||||||
|
&& $hash->{READINGS}{$rAct}{VAL} !~ /^[\w-]+:\/\/.*$/ )
|
||||||
{
|
{
|
||||||
$redirect = "pushover://";
|
$redirect = "pushover://";
|
||||||
|
|
||||||
fhem ReadingsVal($name, $rAct, "");
|
fhem $hash->{READINGS}{$rAct}{VAL};
|
||||||
readingsBulkUpdate( $hash, $rAct,
|
readingsBulkUpdate( $hash, $rAct,
|
||||||
"executed: " . ReadingsVal($name, $rAct, ""));
|
"executed: " . $hash->{READINGS}{$rAct}{VAL} );
|
||||||
}
|
}
|
||||||
|
|
||||||
# redirect to presented URL
|
# redirect to presented URL
|
||||||
if ( ReadingsVal($name, $rAct, "none") =~ /^[\w-]+:\/\/.*$/ )
|
if ( defined( $hash->{READINGS}{$rAct}{VAL} )
|
||||||
|
&& $hash->{READINGS}{$rAct}{VAL} =~ /^[\w-]+:\/\/.*$/ )
|
||||||
{
|
{
|
||||||
$redirect = ReadingsVal($name, $rAct, "");
|
$redirect = $hash->{READINGS}{$rAct}{VAL};
|
||||||
}
|
}
|
||||||
|
|
||||||
readingsEndUpdate( $hash, 1 );
|
readingsEndUpdate( $hash, 1 );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user