2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-16 23:06:05 +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:
jpawlowski 2015-08-30 18:27:34 +00:00
parent 6e7ccd4c3d
commit e25462eb0f

View File

@ -298,7 +298,7 @@ sub Pushover_ReceiveCommand($$$) {
my $name = $hash->{NAME}; my $name = $hash->{NAME};
my $service = $param->{service}; my $service = $param->{service};
my $cmd = $param->{cmd}; my $cmd = $param->{cmd};
my $state = ReadingsVal( $name, "state", "" ); my $state = ReadingsVal( $name, "state", "initialized" );
my $values = $param->{type}; my $values = $param->{type};
my $return; my $return;
@ -369,9 +369,10 @@ sub Pushover_ReceiveCommand($$$) {
# process return data # process return data
# #
$values{result} = "ok";
# messages.json # messages.json
if ( $service eq "messages.json" ) { if ( $service eq "messages.json" ) {
$values{result} = "ok";
readingsBulkUpdate( $hash, "lastTitle", $values->{title} ); readingsBulkUpdate( $hash, "lastTitle", $values->{title} );
readingsBulkUpdate( $hash, "lastMessage", $values->{message} ); readingsBulkUpdate( $hash, "lastMessage", $values->{message} );
@ -455,13 +456,12 @@ sub Pushover_ReceiveCommand($$$) {
# users/validate.json # users/validate.json
elsif ( $service eq "users/validate.json" ) { elsif ( $service eq "users/validate.json" ) {
$values{result} = "ok";
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: " . join( ". ", @{ $return->{errors} } ) . ".";
$state = "unauthorized"; $state = "unauthorized";
} }
elsif ( $return->{status} ne "1" ) { 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 # Set reading for state
@ -508,7 +517,10 @@ sub Pushover_ReceiveCommand($$$) {
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
sub Pushover_ValidateUser ($;$) { sub Pushover_ValidateUser ($;$) {
my ( $hash, $update ) = @_; 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()"; Log3 $name, 5, "Pushover $name: called function Pushover_ValidateUser()";
@ -518,11 +530,12 @@ sub Pushover_ValidateUser ($;$) {
return return
if ( AttrVal( $name, "disable", 0 ) == 1 ); if ( AttrVal( $name, "disable", 0 ) == 1 );
my $cmd = "token=" . $token . "&user=" . $user; if ( $device ne "" ) {
$cmd .= "&" . AttrVal( $hash, "device", "" ) Pushover_SendCommand( $hash, "users/validate.json", "device=$device" );
if ( AttrVal( $hash, "device", "" ) ne "" ); }
else {
Pushover_SendCommand( $hash, "users/validate.json", $cmd ); Pushover_SendCommand( $hash, "users/validate.json" );
}
return; return;
} }