remove lockState Timer

This commit is contained in:
Marko Oldenburg 2017-01-10 21:02:39 +01:00
parent 27d426de73
commit f2c61e6c72
2 changed files with 16 additions and 88 deletions

View File

@ -46,7 +46,7 @@ use JSON;
use HttpUtils; use HttpUtils;
my $version = "0.4.5patch1"; my $version = "0.4.5";
@ -113,7 +113,6 @@ sub NUKIBridge_Define($$) {
$hash->{TOKEN} = $token; $hash->{TOKEN} = $token;
$hash->{VERSION} = $version; $hash->{VERSION} = $version;
$hash->{helper}{aliveCount} = 0; $hash->{helper}{aliveCount} = 0;
$hash->{helper}{checkLockState} = 0;
@ -166,7 +165,6 @@ sub NUKIBridge_Attr(@) {
elsif( $cmd eq "del" ) { elsif( $cmd eq "del" ) {
readingsSingleUpdate ( $hash, "state", "active", 1 ); readingsSingleUpdate ( $hash, "state", "active", 1 );
InternalTimer( gettimeofday()+5, 'NUKIBridge_GetCheckBridgeAlive', $hash, 1 ); InternalTimer( gettimeofday()+5, 'NUKIBridge_GetCheckBridgeAlive', $hash, 1 );
InternalTimer( gettimeofday()+10, 'NUKIBridge_LockStateTimer', $hash, 1 );
Log3 $name, 3, "NUKIBridge ($name) - enabled"; Log3 $name, 3, "NUKIBridge ($name) - enabled";
} }
} }
@ -180,7 +178,6 @@ sub NUKIBridge_Attr(@) {
elsif( $cmd eq "del" ) { elsif( $cmd eq "del" ) {
readingsSingleUpdate ( $hash, "state", "active", 1 ); readingsSingleUpdate ( $hash, "state", "active", 1 );
InternalTimer( gettimeofday()+5, 'NUKIBridge_GetCheckBridgeAlive', $hash, 1 ); InternalTimer( gettimeofday()+5, 'NUKIBridge_GetCheckBridgeAlive', $hash, 1 );
InternalTimer( gettimeofday()+10, 'NUKIBridge_LockStateTimer', $hash, 1 );
Log3 $name, 3, "NUKIBridge ($name) - delete disabledForIntervals"; Log3 $name, 3, "NUKIBridge ($name) - delete disabledForIntervals";
} }
} }
@ -240,11 +237,10 @@ sub NUKIBridge_Set($@) {
} else { } else {
my $list = ""; my $list = "";
$list .= "info:noArg autocreate:noArg "; $list .= "info:noArg autocreate:noArg callbackRemove:0,1,2 ";
$list .= "clearLog:noArg fwUpdate:noArg reboot:noArg callbackRemove:0,1,2" if( ReadingsVal($name,'bridgeType','Software') eq 'Hardware' ); $list .= "clearLog:noArg fwUpdate:noArg reboot:noArg" if( ReadingsVal($name,'bridgeType','Software') eq 'Hardware' );
return "Unknown argument $cmd, choose one of $list"; return "Unknown argument $cmd, choose one of $list";
} }
} }
sub NUKIBridge_Get($@) { sub NUKIBridge_Get($@) {
@ -264,10 +260,10 @@ sub NUKIBridge_Get($@) {
} else { } else {
my $list = ""; my $list = "";
$list .= "logFile:noArg callbackList:noArg" if( ReadingsVal($name,'bridgeType','Software') eq 'Hardware' ); $list .= "callbackList:noArg ";
$list .= "logFile:noArg" if( ReadingsVal($name,'bridgeType','Software') eq 'Hardware' );
return "Unknown argument $cmd, choose one of $list"; return "Unknown argument $cmd, choose one of $list";
} }
} }
sub NUKIBridge_GetCheckBridgeAlive($) { sub NUKIBridge_GetCheckBridgeAlive($) {
@ -275,7 +271,7 @@ sub NUKIBridge_GetCheckBridgeAlive($) {
my ($hash) = @_; my ($hash) = @_;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
RemoveInternalTimer($hash,'NUKIBridge_GetCheckBridgeAlive'); RemoveInternalTimer($hash);
Log3 $name, 4, "NUKIBridge ($name) - NUKIBridge_GetCheckBridgeAlive"; Log3 $name, 4, "NUKIBridge ($name) - NUKIBridge_GetCheckBridgeAlive";
if( !IsDisabled($name) ) { if( !IsDisabled($name) ) {
@ -293,10 +289,9 @@ sub NUKIBridge_firstRun($) {
my $name = $hash->{NAME}; my $name = $hash->{NAME};
RemoveInternalTimer($hash,'NUKIBridge_firstRun'); RemoveInternalTimer($hash);
NUKIBridge_Call($hash,$hash,'list',undef,undef) if( !IsDisabled($name) ); NUKIBridge_Call($hash,$hash,'list',undef,undef) if( !IsDisabled($name) );
InternalTimer( gettimeofday()+15, 'NUKIBridge_GetCheckBridgeAlive', $hash, 1 ); InternalTimer( gettimeofday()+15, 'NUKIBridge_GetCheckBridgeAlive', $hash, 1 );
InternalTimer( gettimeofday()+60, 'NUKIBridge_LockStateTimer', $hash, 1 );
return undef; return undef;
} }
@ -442,14 +437,7 @@ sub NUKIBridge_ResponseProcessing($$$) {
$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" and $hash->{helper}{checkLockState} == 1 ) { if( ref($decode_json) eq "ARRAY" and scalar(@{$decode_json}) > 0 and $path eq "list" ) {
NUKIBridge_LockStateResponse($hash,$json);
$hash->{helper}{checkLockState} = 0;
Log3 $name, 5, "NUKIBridge ($name) - Run NUKIBridge_LockStateResponse with Path:$path and JSON-Data: $json";
}
elsif( ref($decode_json) eq "ARRAY" and scalar(@{$decode_json}) > 0 and $path eq "list" and $hash->{helper}{checkLockState} == 0 ) {
NUKIBridge_Autocreate($hash,$decode_json); NUKIBridge_Autocreate($hash,$decode_json);
NUKIBridge_Call($hash,$hash,"info",undef,undef) if( !IsDisabled($name) ); NUKIBridge_Call($hash,$hash,"info",undef,undef) if( !IsDisabled($name) );
@ -570,11 +558,11 @@ sub NUKIBridge_getLogfile($) {
my $decode_json = NUKIBridge_CallBlocking($hash,"log",undef); my $decode_json = NUKIBridge_CallBlocking($hash,"log",undef);
Log3 $name, 4, "NUKIBridge ($name) - Log Daten werden geholt und aufbereitet"; Log3 $name, 4, "NUKIBridge ($name) - Log data are collected and processed";
if( ref($decode_json) eq "ARRAY" and scalar(@{$decode_json}) > 0 ) { if( ref($decode_json) eq "ARRAY" and scalar(@{$decode_json}) > 0 ) {
Log3 $name, 4, "NUKIBridge ($name) - Tabelle mit Logdaten wird aufgebaut"; Log3 $name, 4, "NUKIBridge ($name) - created Table with log file";
my $ret = '<html><table width=100%><tr><td>'; my $ret = '<html><table width=100%><tr><td>';
$ret .= '<table class="block wide">'; $ret .= '<table class="block wide">';
@ -621,10 +609,10 @@ sub NUKIBridge_getCallbackList($) {
my $decode_json = NUKIBridge_CallBlocking($hash,"callback/list",undef); my $decode_json = NUKIBridge_CallBlocking($hash,"callback/list",undef);
Log3 $name, 4, "NUKIBridge ($name) - Callback Daten werden geholt und aufbereitet"; Log3 $name, 4, "NUKIBridge ($name) - Callback data is collected and processed";
if( ref($decode_json->{callbacks}) eq "ARRAY" and scalar(@{$decode_json->{callbacks}}) > 0 ) { if( ref($decode_json->{callbacks}) eq "ARRAY" and scalar(@{$decode_json->{callbacks}}) > 0 ) {
Log3 $name, 4, "NUKIBridge ($name) - Tabelle mit Logdaten wird aufgebaut"; Log3 $name, 4, "NUKIBridge ($name) - created Table with log file";
my $ret = '<html><table width=100%><tr><td>'; my $ret = '<html><table width=100%><tr><td>';
@ -650,7 +638,7 @@ sub NUKIBridge_getCallbackList($) {
return $ret; return $ret;
} }
return "Keine Callback Daten vorhanden oder Fehler bei der Verarbeitung"; return "No callback data available or error during processing";
} }
sub NUKIBridge_CallBlocking($$$) { sub NUKIBridge_CallBlocking($$$) {
@ -693,74 +681,16 @@ sub NUKIBridge_CallBlocking($$$) {
return undef if( !$decode_json ); return undef if( !$decode_json );
Log3 $name, 5, "NUKIBridge ($name) - Data: $data"; Log3 $name, 5, "NUKIBridge ($name) - Data: $data";
Log3 $name, 4, "NUKIBridge ($name) - Blocking HTTP Abfrage beendet"; Log3 $name, 4, "NUKIBridge ($name) - Blocking HTTP Query finished";
return ($decode_json); return ($decode_json);
} }
sub NUKIBridge_LockStateTimer($) {
my ($hash) = @_;
my $name = $hash->{NAME};
RemoveInternalTimer($hash,'NUKIBridge_LockStateTimer');
Log3 $name, 4, "NUKIBridge ($name) - NUKIBridge_LockStateTimer";
if( !IsDisabled($name) and ReadingsVal($name,'bridgeType','Hardware') eq 'Software' ) {
if( ReadingsVal($name,'smartlockCount',0) > 0 and $hash->{helper}{checkLockState} == 0 ) {
NUKIBridge_Call($hash,$hash,'list',undef,undef) if( ReadingsVal($name,'state','not connected') eq "connected" );
$hash->{helper}{checkLockState} = 1 ;
}
InternalTimer( gettimeofday()+7, 'NUKIBridge_LockStateTimer', $hash, 1 );
Log3 $name, 4, "NUKIBridge ($name) - Call InternalTimer for NUKIBridge_LockStateTimer";
}
}
sub NUKIBridge_LockStateResponse($$) {
my ($hash,$json) = @_;
my $name = $hash->{NAME};
my $nukiId;
my $nukiSmartlock;
my $decode_json;
my %response_hash;
my $dname;
my $dhash;
$decode_json = decode_json($json);
foreach $nukiSmartlock (@{$decode_json}) {
if( ref($nukiSmartlock->{lastKnownState}) eq "HASH" ) {
if ( defined( $modules{NUKIDevice}{defptr} ) ) {
while ( my ( $key, $value ) = each %{ $modules{NUKIDevice}{defptr} } ) {
$dhash = $modules{NUKIDevice}{defptr}{$key};
$dname = $dhash->{NAME};
$nukiId = InternalVal( $dname, "NUKIID", undef );
next if ( !$nukiId or $nukiId ne $nukiSmartlock->{nukiId} );
Log3 $name, 4, "NUKIDevice ($dname) - Received LockState for matching NukiID $nukiId at device $dname";
%response_hash = ('state'=>$nukiSmartlock->{lastKnownState}{state}, 'stateName'=>$nukiSmartlock->{lastKnownState}{stateName},'batteryCritical'=>$nukiSmartlock->{lastKnownState}{batteryCritical},'timestamp'=>$nukiSmartlock->{lastKnownState}{timestamp});
NUKIDevice_Parse($dhash,encode_json \%response_hash);
}
}
}
}
}
1; 1;
=pod =pod
=item device =item device
=item summary Modul to control the Nuki Smartlock's over the Nuki Bridge. =item summary Modul to control the Nuki Smartlock's over the Nuki Bridge.

View File

@ -31,9 +31,9 @@ package main;
use strict; use strict;
use warnings; use warnings;
use JSON; use JSON;
#use Time::HiRes qw(gettimeofday);
my $version = "0.4.5patch1";
my $version = "0.4.5";
@ -192,8 +192,6 @@ 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} );