mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-08 13:24:56 +00:00
70_Pushover: add reading for availability
git-svn-id: https://svn.fhem.de/fhem/trunk@9180 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
6e7ccd4c3d
commit
e25462eb0f
@ -298,7 +298,7 @@ sub Pushover_ReceiveCommand($$$) {
|
||||
my $name = $hash->{NAME};
|
||||
my $service = $param->{service};
|
||||
my $cmd = $param->{cmd};
|
||||
my $state = ReadingsVal( $name, "state", "" );
|
||||
my $state = ReadingsVal( $name, "state", "initialized" );
|
||||
my $values = $param->{type};
|
||||
my $return;
|
||||
|
||||
@ -369,9 +369,10 @@ sub Pushover_ReceiveCommand($$$) {
|
||||
# process return data
|
||||
#
|
||||
|
||||
$values{result} = "ok";
|
||||
|
||||
# messages.json
|
||||
if ( $service eq "messages.json" ) {
|
||||
$values{result} = "ok";
|
||||
|
||||
readingsBulkUpdate( $hash, "lastTitle", $values->{title} );
|
||||
readingsBulkUpdate( $hash, "lastMessage", $values->{message} );
|
||||
@ -455,13 +456,12 @@ sub Pushover_ReceiveCommand($$$) {
|
||||
|
||||
# users/validate.json
|
||||
elsif ( $service eq "users/validate.json" ) {
|
||||
$values{result} = "ok";
|
||||
|
||||
if ( ref($return) eq "HASH" ) {
|
||||
|
||||
if ( $return->{status} ne "1" && defined $return->{errors} ) {
|
||||
$values{result} =
|
||||
"Error: " . Dumper( $return->{errors} );
|
||||
"Error: " . join( ". ", @{ $return->{errors} } ) . ".";
|
||||
$state = "unauthorized";
|
||||
}
|
||||
elsif ( $return->{status} ne "1" ) {
|
||||
@ -486,10 +486,19 @@ sub Pushover_ReceiveCommand($$$) {
|
||||
}
|
||||
}
|
||||
|
||||
Pushover_SendCommand( $hash, "users/validate.json", $cmd );
|
||||
}
|
||||
|
||||
readingsBulkUpdate( $hash, "lastResult", $values->{result} );
|
||||
readingsBulkUpdate( $hash, "lastResult", $values{result} );
|
||||
}
|
||||
|
||||
# Set reading for availability
|
||||
#
|
||||
my $available = 0;
|
||||
$available = 1 if ( $state eq "connected" );
|
||||
if ( !defined( $hash->{READINGS}{available}{VAL} )
|
||||
|| $hash->{READINGS}{available}{VAL} ne $available )
|
||||
{
|
||||
readingsBulkUpdate( $hash, "available", $available );
|
||||
}
|
||||
|
||||
# Set reading for state
|
||||
@ -508,7 +517,10 @@ sub Pushover_ReceiveCommand($$$) {
|
||||
#------------------------------------------------------------------------------
|
||||
sub Pushover_ValidateUser ($;$) {
|
||||
my ( $hash, $update ) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
my $name = $hash->{NAME};
|
||||
my $token = $hash->{APP_TOKEN};
|
||||
my $user = $hash->{USER_KEY};
|
||||
my $device = AttrVal( $name, "device", "" );
|
||||
|
||||
Log3 $name, 5, "Pushover $name: called function Pushover_ValidateUser()";
|
||||
|
||||
@ -518,11 +530,12 @@ sub Pushover_ValidateUser ($;$) {
|
||||
return
|
||||
if ( AttrVal( $name, "disable", 0 ) == 1 );
|
||||
|
||||
my $cmd = "token=" . $token . "&user=" . $user;
|
||||
$cmd .= "&" . AttrVal( $hash, "device", "" )
|
||||
if ( AttrVal( $hash, "device", "" ) ne "" );
|
||||
|
||||
Pushover_SendCommand( $hash, "users/validate.json", $cmd );
|
||||
if ( $device ne "" ) {
|
||||
Pushover_SendCommand( $hash, "users/validate.json", "device=$device" );
|
||||
}
|
||||
else {
|
||||
Pushover_SendCommand( $hash, "users/validate.json" );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user