2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-19 12:46:03 +00:00

73_NUKIBridge: 74_NUKIDevice fix lockState with App Bridge

git-svn-id: https://svn.fhem.de/fhem/trunk@13005 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
LeonGaultier 2017-01-07 21:16:52 +00:00
parent 4ff65d8521
commit 3825e73a0e
3 changed files with 84 additions and 28 deletions

View File

@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it. # Do not insert empty lines here, update check depends on it.
- bugfix: 73_NUKIBridge/74_NUKIDevice fix lockState with App Bridge
- bugfix: 14_CUL_TCM97001: fix KW9010 sensor - bugfix: 14_CUL_TCM97001: fix KW9010 sensor
- feature: 70_Pushover: add new msg set syntax and introduce - feature: 70_Pushover: add new msg set syntax and introduce
Apple Watch glance support Apple Watch glance support

View File

@ -46,7 +46,7 @@ use JSON;
use HttpUtils; use HttpUtils;
my $version = "0.4.0"; my $version = "0.4.4";
@ -164,6 +164,7 @@ sub NUKIBridge_Attr(@) {
elsif( $cmd eq "del" ) { elsif( $cmd eq "del" ) {
readingsSingleUpdate ( $hash, "state", "active", 1 ); readingsSingleUpdate ( $hash, "state", "active", 1 );
NUKIBridge_GetCheckBridgeAlive($hash);
Log3 $name, 3, "NUKIBridge ($name) - enabled"; Log3 $name, 3, "NUKIBridge ($name) - enabled";
} }
} }
@ -176,6 +177,7 @@ sub NUKIBridge_Attr(@) {
elsif( $cmd eq "del" ) { elsif( $cmd eq "del" ) {
readingsSingleUpdate ( $hash, "state", "active", 1 ); readingsSingleUpdate ( $hash, "state", "active", 1 );
NUKIBridge_GetCheckBridgeAlive($hash);
Log3 $name, 3, "NUKIBridge ($name) - delete disabledForIntervals"; Log3 $name, 3, "NUKIBridge ($name) - delete disabledForIntervals";
} }
} }
@ -234,7 +236,9 @@ sub NUKIBridge_Set($@) {
} }
} else { } else {
my $list = "info:noArg autocreate:noArg clearLog:noArg fwUpdate:noArg reboot:noArg callbackRemove:0,1,2"; my $list = "";
$list .= "info:noArg autocreate:noArg ";
$list .= "clearLog:noArg fwUpdate:noArg reboot:noArg callbackRemove:0,1,2" if( ReadingsVal($name,'bridgeType','Software') eq 'Hardware' );
return "Unknown argument $cmd, choose one of $list"; return "Unknown argument $cmd, choose one of $list";
} }
@ -256,7 +260,8 @@ sub NUKIBridge_Get($@) {
NUKIBridge_getCallbackList($hash) if( !IsDisabled($name) ); NUKIBridge_getCallbackList($hash) if( !IsDisabled($name) );
} else { } else {
my $list = "logFile:noArg callbackList:noArg"; my $list = "";
$list .= "logFile:noArg callbackList:noArg" if( ReadingsVal($name,'bridgeType','Software') eq 'Hardware' );
return "Unknown argument $cmd, choose one of $list"; return "Unknown argument $cmd, choose one of $list";
} }
@ -272,9 +277,9 @@ sub NUKIBridge_GetCheckBridgeAlive($) {
if( !IsDisabled($name) ) { if( !IsDisabled($name) ) {
NUKIBridge_Call($hash,$hash,"alive",undef,undef); NUKIBridge_Call($hash,$hash,"info",undef,undef);
InternalTimer( gettimeofday()+17+int(rand(15)), "NUKIBridge_GetCheckBridgeAlive", $hash, 1 ); InternalTimer( gettimeofday()+15+int(rand(15)), "NUKIBridge_GetCheckBridgeAlive", $hash, 1 );
Log3 $name, 4, "NUKIBridge ($name) - Call InternalTimer for NUKIBridge_GetCheckBridgeAlive"; Log3 $name, 4, "NUKIBridge ($name) - Call InternalTimer for NUKIBridge_GetCheckBridgeAlive";
} }
} }
@ -335,12 +340,17 @@ sub NUKIBridge_Distribution($$$) {
my $host = $hash->{HOST}; my $host = $hash->{HOST};
Log3 $name, 5, "NUKIBridge ($name) - Response JSON: $json";
Log3 $name, 5, "NUKIBridge ($name) - Response ERROR: $err";
Log3 $name, 5, "NUKIBridge ($name) - Response CODE: $param->{code}";
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
if( defined( $err ) ) { if( defined( $err ) ) {
if ( $err ne "" ) { if ( $err ne "" ) {
if ($param->{endpoint} eq "alive") { if ($param->{endpoint} eq "info") {
readingsBulkUpdate( $hash, "state", "not connected") if( $hash->{helper}{aliveCount} > 1 ); readingsBulkUpdate( $hash, "state", "not connected") if( $hash->{helper}{aliveCount} > 1 );
Log3 $name, 5, "NUKIBridge ($name) - Bridge ist offline";
$hash->{helper}{aliveCount} = $hash->{helper}{aliveCount} + 1; $hash->{helper}{aliveCount} = $hash->{helper}{aliveCount} + 1;
} }
@ -351,16 +361,7 @@ sub NUKIBridge_Distribution($$$) {
} }
} }
if( $json eq "" and exists( $param->{code} ) && $param->{code} ne 200 ) { if( $json eq "" and exists( $param->{code} ) and $param->{code} ne 200 ) {
if( $param->{endpoint} eq "alive") {
readingsBulkUpdate( $hash, "state", "connected" );
Log3 $name, 5, "NUKIBridge ($name) - Bridge ist online";
readingsEndUpdate( $hash, 1 );
$hash->{helper}{aliveCount} = 0;
return;
}
readingsBulkUpdate( $hash, "lastError", "Internal error, " .$param->{code} ); readingsBulkUpdate( $hash, "lastError", "Internal error, " .$param->{code} );
Log3 $name, 4, "NUKIBridge ($name) - received http code " .$param->{code}." without any data after requesting"; Log3 $name, 4, "NUKIBridge ($name) - received http code " .$param->{code}." without any data after requesting";
@ -424,6 +425,17 @@ sub NUKIBridge_ResponseProcessing($$$) {
my $decode_json; my $decode_json;
if( !$json ) {
Log3 $name, 3, "NUKIBridge ($name) - empty answer received";
return undef;
} elsif( $json =~ m'HTTP/1.1 200 OK' ) {
Log3 $name, 4, "NUKIBridge ($name) - empty answer received";
return undef;
} elsif( $json !~ m/^[\[{].*[}\]]$/ ) {
Log3 $name, 3, "NUKIBridge ($name) - invalid json detected: $json";
return "NUKIBridge ($name) - invalid json detected: $json";
}
$decode_json = decode_json($json); $decode_json = decode_json($json);
if( ref($decode_json) eq "ARRAY" and scalar(@{$decode_json}) > 0 and $path eq "list" ) { if( ref($decode_json) eq "ARRAY" and scalar(@{$decode_json}) > 0 and $path eq "list" ) {
@ -433,6 +445,13 @@ sub NUKIBridge_ResponseProcessing($$$) {
} }
elsif( $path eq "info" ) { elsif( $path eq "info" ) {
readingsBeginUpdate( $hash );
readingsBulkUpdate( $hash, "state", "connected" );
Log3 $name, 5, "NUKIBridge ($name) - Bridge ist online";
readingsEndUpdate( $hash, 1 );
$hash->{helper}{aliveCount} = 0;
NUKIBridge_InfoProcessing($hash,$decode_json); NUKIBridge_InfoProcessing($hash,$decode_json);
} else { } else {
@ -682,7 +701,6 @@ sub NUKIBridge_CallBlocking($$$) {
=begin html =begin html
timestamp
<a name="NUKIBridge"></a> <a name="NUKIBridge"></a>
<h3>NUKIBridge</h3> <h3>NUKIBridge</h3>
<ul> <ul>

View File

@ -33,7 +33,7 @@ use warnings;
use JSON; use JSON;
#use Time::HiRes qw(gettimeofday); #use Time::HiRes qw(gettimeofday);
my $version = "0.4.1"; my $version = "0.4.4";
@ -192,6 +192,8 @@ sub NUKIDevice_Attr(@) {
###################### ######################
#### webhook ######### #### webhook #########
return "$attrName can only use with hardware bridge" if( ($attrName eq "webhookHttpHostname" or $attrName eq "webhookFWinstance") and ReadingsVal($hash->{IODev}->{NAME},'bridgeType','Software') eq 'Software' );
return "Invalid value for attribute $attrName: can only by FQDN or IPv4 or IPv6 address" if ( $attrVal && $attrName eq "webhookHttpHostname" && $attrVal !~ /^([A-Za-z_.0-9]+\.[A-Za-z_.0-9]+)|[0-9:]+$/ ); return "Invalid value for attribute $attrName: can only by FQDN or IPv4 or IPv6 address" if ( $attrVal && $attrName eq "webhookHttpHostname" && $attrVal !~ /^([A-Za-z_.0-9]+\.[A-Za-z_.0-9]+)|[0-9:]+$/ );
return "Invalid value for attribute $attrName: needs to be different from the defined name/address of your Smartlock, we need to know how Smartlock can connect back to FHEM here!" if ( $attrVal && $attrName eq "webhookHttpHostname" && $attrVal eq $hash->{DeviceName} ); return "Invalid value for attribute $attrName: needs to be different from the defined name/address of your Smartlock, we need to know how Smartlock can connect back to FHEM here!" if ( $attrVal && $attrName eq "webhookHttpHostname" && $attrVal eq $hash->{DeviceName} );
@ -358,6 +360,17 @@ sub NUKIDevice_Parse($$) {
######################################### #########################################
####### Errorhandling ############# ####### Errorhandling #############
if( !$result ) {
Log3 $name, 3, "NUKIDevice ($name) - empty answer received";
return undef;
} elsif( $result =~ m'HTTP/1.1 200 OK' ) {
Log3 $name, 4, "NUKIDevice ($name) - empty answer received";
return undef;
} elsif( $result !~ m/^[\[{].*[}\]]$/ ) {
Log3 $name, 3, "NUKIDevice ($name) - invalid json detected: $result";
return "NUKIDevice ($name) - invalid json detected: $result";
}
if( $result =~ /\d{3}/ ) { if( $result =~ /\d{3}/ ) {
if( $result eq 400 ) { if( $result eq 400 ) {
readingsSingleUpdate( $hash, "state", "action is undefined", 1 ); readingsSingleUpdate( $hash, "state", "action is undefined", 1 );
@ -394,12 +407,10 @@ sub NUKIDevice_WriteReadings($$) {
my $name = $hash->{NAME}; my $name = $hash->{NAME};
############################ ############################
#### Status des Smartlock #### Status des Smartlock
readingsBeginUpdate($hash);
my $battery; my $battery;
if( defined($decode_json->{batteryCritical}) ) { if( defined($decode_json->{batteryCritical}) ) {
if( $decode_json->{batteryCritical} eq "false" or $decode_json->{batteryCritical} == 0 ) { if( $decode_json->{batteryCritical} eq "false" or $decode_json->{batteryCritical} == 0 ) {
@ -411,23 +422,33 @@ sub NUKIDevice_WriteReadings($$) {
} }
} }
readingsBeginUpdate($hash);
if( defined($hash->{helper}{lockAction}) ) { if( defined($hash->{helper}{lockAction}) ) {
my ($state,$lockState); my ($state,$lockState);
$state = $hash->{helper}{lockAction} if( $decode_json->{success} eq "true" );
$state = "error" if( $decode_json->{success} eq "false" );
$lockState = $hash->{helper}{lockAction} if( $decode_json->{success} eq "true" );
if( $decode_json->{success} eq "true" ) {
$state = $hash->{helper}{lockAction};
$lockState = $hash->{helper}{lockAction};
NUKIDevice_ReadFromNUKIBridge($hash, "lockState", undef, $hash->{NUKIID} ) if( ReadingsVal($hash->{IODev}->{NAME},'bridgeType','Software') eq 'Software' );
} elsif ( $decode_json->{success} eq "false" ) {
$state = "error";
NUKIDevice_ReadFromNUKIBridge($hash, "lockState", undef, $hash->{NUKIID} );
}
readingsBulkUpdate( $hash, "state", $state ); readingsBulkUpdate( $hash, "state", $state );
readingsBulkUpdate( $hash, "lockState", $lockState ); readingsBulkUpdate( $hash, "lockState", $lockState );
readingsBulkUpdate( $hash, "success", $decode_json->{success} ); readingsBulkUpdate( $hash, "success", $decode_json->{success} );
readingsBulkUpdate( $hash, "batteryCritical", $decode_json->{batteryCritical} );
readingsBulkUpdate( $hash, "battery", $battery );
delete $hash->{helper}{lockAction}; delete $hash->{helper}{lockAction};
Log3 $name, 5, "NUKIDevice ($name) - readings set for $name"; Log3 $name, 5, "NUKIDevice ($name) - lockAction readings set for $name";
} else { } else {
@ -442,6 +463,7 @@ sub NUKIDevice_WriteReadings($$) {
readingsEndUpdate( $hash, 1 ); readingsEndUpdate( $hash, 1 );
return undef; return undef;
} }
@ -453,13 +475,28 @@ sub NUKIDevice_CGI() {
my $name; my $name;
my $nukiId; my $nukiId;
# data received # data received
# Testaufruf: wget --post-data '{"nukiId": 123456, "state": 1,"stateName": "locked", "batteryCritical": false}' http://10.6.6.20:8083/fhem/NUKIDevice-123456 # Testaufruf:
# curl --data '{"nukiId": 123456, "state": 1,"stateName": "locked", "batteryCritical": false}' http://10.6.6.20:8083/fhem/NUKIDevice-123456
# wget --post-data '{"nukiId": 123456, "state": 1,"stateName": "locked", "batteryCritical": false}' http://10.6.6.20:8083/fhem/NUKIDevice-123456
my $header = join("\n", @FW_httpheader); my $header = join("\n", @FW_httpheader);
my ($first,$json) = split("&",$request,2); my ($first,$json) = split("&",$request,2);
if( !$json ) {
Log3 $name, 3, "NUKIDevice ($name) - empty answer received";
return undef;
} elsif( $json =~ m'HTTP/1.1 200 OK' ) {
Log3 $name, 4, "NUKIDevice ($name) - empty answer received";
return undef;
} elsif( $json !~ m/^[\[{].*[}\]]$/ ) {
Log3 $name, 3, "NUKIDevice ($name) - invalid json detected: $json";
return "NUKIDevice ($name) - invalid json detected: $json";
}
my $decode_json = decode_json($json); my $decode_json = decode_json($json);