70_Pushover: use readingsBulkUpdateIfChanged()
git-svn-id: https://svn.fhem.de/fhem/trunk@13045 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
@@ -402,21 +402,18 @@ sub Pushover_ReceiveCommand($$$) {
|
|||||||
if ( $param->{httpheader} =~ m/X-Limit-App-Limit:[\s\t]*(.*)[\s\t\n]*/ )
|
if ( $param->{httpheader} =~ m/X-Limit-App-Limit:[\s\t]*(.*)[\s\t\n]*/ )
|
||||||
{
|
{
|
||||||
$apiLimit = $1;
|
$apiLimit = $1;
|
||||||
readingsBulkUpdate( $hash, "apiLimit", $1 )
|
readingsBulkUpdateIfChanged( $hash, "apiLimit", $1 ),;
|
||||||
if ( ReadingsVal( $name, "apiLimit", "" ) ne $1 );
|
|
||||||
}
|
}
|
||||||
if ( $param->{httpheader} =~
|
if ( $param->{httpheader} =~
|
||||||
m/X-Limit-App-Remaining:[\s\t]*(.*)[\s\t\n]*/ )
|
m/X-Limit-App-Remaining:[\s\t]*(.*)[\s\t\n]*/ )
|
||||||
{
|
{
|
||||||
$apiRemaining = $1;
|
$apiRemaining = $1;
|
||||||
readingsBulkUpdate( $hash, "apiRemaining", $1 )
|
readingsBulkUpdateIfChanged( $hash, "apiRemaining", $1 );
|
||||||
if ( ReadingsVal( $name, "apiRemaining", "" ) ne $1 );
|
|
||||||
}
|
}
|
||||||
if ( $param->{httpheader} =~ m/X-Limit-App-Reset:[\s\t]*(.*)[\s\t\n]*/ )
|
if ( $param->{httpheader} =~ m/X-Limit-App-Reset:[\s\t]*(.*)[\s\t\n]*/ )
|
||||||
{
|
{
|
||||||
$apiReset = $1;
|
$apiReset = $1;
|
||||||
readingsBulkUpdate( $hash, "apiReset", $1 )
|
readingsBulkUpdateIfChanged( $hash, "apiReset", $1 );
|
||||||
if ( ReadingsVal( $name, "apiReset", "" ) ne $1 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Server error
|
# Server error
|
||||||
@@ -449,28 +446,22 @@ sub Pushover_ReceiveCommand($$$) {
|
|||||||
|
|
||||||
if ( ref($return) eq "HASH" && defined( $return->{token} ) ) {
|
if ( ref($return) eq "HASH" && defined( $return->{token} ) ) {
|
||||||
$state = "unauthorized";
|
$state = "unauthorized";
|
||||||
readingsBulkUpdate( $hash, "tokenState", $return->{token} )
|
readingsBulkUpdate( $hash, "tokenState", $return->{token} );
|
||||||
if (
|
|
||||||
ReadingsVal( $name, "tokenState", "" ) ne $return->{token}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
elsif ( ref($return) ne "HASH" && $return =~ m/"token":"invalid"/ )
|
elsif ( ref($return) ne "HASH" && $return =~ m/"token":"invalid"/ )
|
||||||
{
|
{
|
||||||
$state = "unauthorized";
|
$state = "unauthorized";
|
||||||
readingsBulkUpdate( $hash, "tokenState", "invalid" )
|
readingsBulkUpdate( $hash, "tokenState", "invalid" );
|
||||||
if ( ReadingsVal( $name, "tokenState", "" ) ne "invalid" );
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
readingsBulkUpdate( $hash, "tokenState", "valid" )
|
readingsBulkUpdateIfChanged( $hash, "tokenState", "valid" );
|
||||||
if ( ReadingsVal( $name, "tokenState", "" ) ne "valid" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ref($return) eq "HASH" && defined( $return->{user} ) ) {
|
if ( ref($return) eq "HASH" && defined( $return->{user} ) ) {
|
||||||
|
|
||||||
$state = "unauthorized" if ( !defined( $values->{USER_KEY} ) );
|
$state = "unauthorized" if ( !defined( $values->{USER_KEY} ) );
|
||||||
readingsBulkUpdate( $hash, "userState", $return->{user} )
|
readingsBulkUpdate( $hash, "userState", $return->{user} )
|
||||||
if ( ReadingsVal( $name, "userState", "" ) ne $return->{user}
|
if ( !defined( $values->{USER_KEY} ) );
|
||||||
&& !defined( $values->{USER_KEY} ) );
|
|
||||||
|
|
||||||
$hash->{helper}{FAILED_USERKEYS}{ $values->{USER_KEY} } =
|
$hash->{helper}{FAILED_USERKEYS}{ $values->{USER_KEY} } =
|
||||||
"USERKEY "
|
"USERKEY "
|
||||||
@@ -484,8 +475,7 @@ sub Pushover_ReceiveCommand($$$) {
|
|||||||
|
|
||||||
$state = "unauthorized" if ( !defined( $values->{USER_KEY} ) );
|
$state = "unauthorized" if ( !defined( $values->{USER_KEY} ) );
|
||||||
readingsBulkUpdate( $hash, "userState", "invalid" )
|
readingsBulkUpdate( $hash, "userState", "invalid" )
|
||||||
if ( ReadingsVal( $name, "userState", "" ) ne "invalid"
|
if ( !defined( $values->{USER_KEY} ) );
|
||||||
&& !defined( $values->{USER_KEY} ) );
|
|
||||||
|
|
||||||
$hash->{helper}{FAILED_USERKEYS}{ $values->{USER_KEY} } =
|
$hash->{helper}{FAILED_USERKEYS}{ $values->{USER_KEY} } =
|
||||||
"USERKEY "
|
"USERKEY "
|
||||||
@@ -497,9 +487,8 @@ sub Pushover_ReceiveCommand($$$) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "userState", "valid" )
|
readingsBulkUpdateIfChanged( $hash, "userState", "valid" )
|
||||||
if ( ReadingsVal( $name, "userState", "" ) ne "valid"
|
if ( !defined( $values->{USER_KEY} ) );
|
||||||
&& !defined( $values->{USER_KEY} ) );
|
|
||||||
|
|
||||||
delete $hash->{helper}{FAILED_USERKEYS}{ $values->{USER_KEY} }
|
delete $hash->{helper}{FAILED_USERKEYS}{ $values->{USER_KEY} }
|
||||||
if (
|
if (
|
||||||
@@ -515,12 +504,10 @@ sub Pushover_ReceiveCommand($$$) {
|
|||||||
else {
|
else {
|
||||||
$state = "limited" if ( $apiRemaining < 1 );
|
$state = "limited" if ( $apiRemaining < 1 );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "tokenState", "valid" )
|
readingsBulkUpdateIfChanged( $hash, "tokenState", "valid" )
|
||||||
if ( ReadingsVal( $name, "tokenState", "" ) ne "valid"
|
if ( !defined( $values->{USER_KEY} ) );
|
||||||
&& !defined( $values->{USER_KEY} ) );
|
readingsBulkUpdateIfChanged( $hash, "userState", "valid" )
|
||||||
readingsBulkUpdate( $hash, "userState", "valid" )
|
if ( !defined( $values->{USER_KEY} ) );
|
||||||
if ( ReadingsVal( $name, "userState", "" ) ne "valid"
|
|
||||||
&& !defined( $values->{USER_KEY} ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# messages.json
|
# messages.json
|
||||||
@@ -627,10 +614,8 @@ sub Pushover_ReceiveCommand($$$) {
|
|||||||
if ( defined( $return->{devices} ) );
|
if ( defined( $return->{devices} ) );
|
||||||
$group = $return->{group} if ( defined( $return->{group} ) );
|
$group = $return->{group} if ( defined( $return->{group} ) );
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "devices", $devices )
|
readingsBulkUpdateIfChanged( $hash, "devices", $devices );
|
||||||
if ( ReadingsVal( $name, "devices", "" ) ne $devices );
|
readingsBulkUpdateIfChanged( $hash, "group", $group );
|
||||||
readingsBulkUpdate( $hash, "group", $group )
|
|
||||||
if ( ReadingsVal( $name, "group", "" ) ne $group );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -643,13 +628,11 @@ sub Pushover_ReceiveCommand($$$) {
|
|||||||
$available = 1
|
$available = 1
|
||||||
if ( $param->{code} ne "429"
|
if ( $param->{code} ne "429"
|
||||||
&& ( $state eq "connected" || $state eq "error" ) );
|
&& ( $state eq "connected" || $state eq "error" ) );
|
||||||
readingsBulkUpdate( $hash, "available", $available )
|
readingsBulkUpdateIfChanged( $hash, "available", $available );
|
||||||
if ( ReadingsVal( $name, "available", "" ) ne $available );
|
|
||||||
|
|
||||||
# Set reading for state
|
# Set reading for state
|
||||||
#
|
#
|
||||||
readingsBulkUpdate( $hash, "state", $state )
|
readingsBulkUpdateIfChanged( $hash, "state", $state );
|
||||||
if ( ReadingsVal( $name, "state", "" ) ne $state );
|
|
||||||
|
|
||||||
# credentials validation loop
|
# credentials validation loop
|
||||||
#
|
#
|
||||||
|
|||||||
Reference in New Issue
Block a user