Commandref für Callback und neue Readings der Bridge an gepasst
This commit is contained in:
parent
35d8a87efc
commit
e424250cc1
144
73_NUKIBridge.pm
144
73_NUKIBridge.pm
@ -72,16 +72,16 @@ sub NUKIBridge_Initialize($) {
|
|||||||
# Consumer
|
# Consumer
|
||||||
$hash->{SetFn} = "NUKIBridge_Set";
|
$hash->{SetFn} = "NUKIBridge_Set";
|
||||||
$hash->{GetFn} = "NUKIBridge_Get";
|
$hash->{GetFn} = "NUKIBridge_Get";
|
||||||
$hash->{DefFn} = "NUKIBridge_Define";
|
$hash->{DefFn} = "NUKIBridge_Define";
|
||||||
$hash->{UndefFn} = "NUKIBridge_Undef";
|
$hash->{UndefFn} = "NUKIBridge_Undef";
|
||||||
$hash->{AttrFn} = "NUKIBridge_Attr";
|
$hash->{AttrFn} = "NUKIBridge_Attr";
|
||||||
$hash->{AttrList} = "disable:1 ".
|
$hash->{AttrList} = "disable:1 ".
|
||||||
$readingFnAttributes;
|
$readingFnAttributes;
|
||||||
|
|
||||||
|
|
||||||
foreach my $d(sort keys %{$modules{NUKIBridge}{defptr}}) {
|
foreach my $d(sort keys %{$modules{NUKIBridge}{defptr}}) {
|
||||||
my $hash = $modules{NUKIBridge}{defptr}{$d};
|
my $hash = $modules{NUKIBridge}{defptr}{$d};
|
||||||
$hash->{VERSION} = $version;
|
$hash->{VERSION} = $version;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,15 +103,16 @@ sub NUKIBridge_Define($$) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
my $name = $a[0];
|
my $name = $a[0];
|
||||||
my $host = $a[2];
|
my $host = $a[2];
|
||||||
my $token = $a[3];
|
my $token = $a[3];
|
||||||
my $port = 8080;
|
my $port = 8080;
|
||||||
|
|
||||||
$hash->{HOST} = $host;
|
$hash->{HOST} = $host;
|
||||||
$hash->{PORT} = $port;
|
$hash->{PORT} = $port;
|
||||||
$hash->{TOKEN} = $token;
|
$hash->{TOKEN} = $token;
|
||||||
$hash->{VERSION} = $version;
|
$hash->{VERSION} = $version;
|
||||||
|
$hash->{helper}{aliveCount} = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -157,23 +158,23 @@ sub NUKIBridge_Attr(@) {
|
|||||||
|
|
||||||
if( $attrName eq "disable" ) {
|
if( $attrName eq "disable" ) {
|
||||||
if( $cmd eq "set" and $attrVal eq "1" ) {
|
if( $cmd eq "set" and $attrVal eq "1" ) {
|
||||||
readingsSingleUpdate ( $hash, "state", "disabled", 1 );
|
readingsSingleUpdate ( $hash, "state", "disabled", 1 );
|
||||||
Log3 $name, 3, "NUKIBridge ($name) - disabled";
|
Log3 $name, 3, "NUKIBridge ($name) - disabled";
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif( $cmd eq "del" ) {
|
elsif( $cmd eq "del" ) {
|
||||||
readingsSingleUpdate ( $hash, "state", "active", 1 );
|
readingsSingleUpdate ( $hash, "state", "active", 1 );
|
||||||
Log3 $name, 3, "NUKIBridge ($name) - enabled";
|
Log3 $name, 3, "NUKIBridge ($name) - enabled";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $attrName eq "disabledForIntervals" ) {
|
if( $attrName eq "disabledForIntervals" ) {
|
||||||
if( $cmd eq "set" ) {
|
if( $cmd eq "set" ) {
|
||||||
Log3 $name, 3, "NUKIBridge ($name) - enable disabledForIntervals";
|
Log3 $name, 3, "NUKIBridge ($name) - enable disabledForIntervals";
|
||||||
readingsSingleUpdate ( $hash, "state", "Unknown", 1 );
|
readingsSingleUpdate ( $hash, "state", "Unknown", 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
elsif( $cmd eq "del" ) {
|
elsif( $cmd eq "del" ) {
|
||||||
readingsSingleUpdate ( $hash, "state", "active", 1 );
|
readingsSingleUpdate ( $hash, "state", "active", 1 );
|
||||||
Log3 $name, 3, "NUKIBridge ($name) - delete disabledForIntervals";
|
Log3 $name, 3, "NUKIBridge ($name) - delete disabledForIntervals";
|
||||||
}
|
}
|
||||||
@ -205,28 +206,28 @@ sub NUKIBridge_Set($@) {
|
|||||||
} elsif($cmd eq 'fwUpdate') {
|
} elsif($cmd eq 'fwUpdate') {
|
||||||
return "usage: fwUpdate" if( @args != 0 );
|
return "usage: fwUpdate" if( @args != 0 );
|
||||||
|
|
||||||
NUKIBridge_CallBlocking($hash,"fwupdate",undef);
|
NUKIBridge_CallBlocking($hash,"fwupdate",undef) if( !IsDisabled($name) );
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
|
|
||||||
} elsif($cmd eq 'reboot') {
|
} elsif($cmd eq 'reboot') {
|
||||||
return "usage: reboot" if( @args != 0 );
|
return "usage: reboot" if( @args != 0 );
|
||||||
|
|
||||||
NUKIBridge_CallBlocking($hash,"reboot",undef);
|
NUKIBridge_CallBlocking($hash,"reboot",undef) if( !IsDisabled($name) );
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
|
|
||||||
} elsif($cmd eq 'clearLog') {
|
} elsif($cmd eq 'clearLog') {
|
||||||
return "usage: clearLog" if( @args != 0 );
|
return "usage: clearLog" if( @args != 0 );
|
||||||
|
|
||||||
NUKIBridge_CallBlocking($hash,"clearlog",undef);
|
NUKIBridge_CallBlocking($hash,"clearlog",undef) if( !IsDisabled($name) );
|
||||||
|
|
||||||
} elsif($cmd eq 'callbackRemove') {
|
} elsif($cmd eq 'callbackRemove') {
|
||||||
return "usage: callbackRemove" if( @args != 1 );
|
return "usage: callbackRemove" if( @args != 1 );
|
||||||
my $id = "id=" . join( " ", @args );
|
my $id = "id=" . join( " ", @args );
|
||||||
|
|
||||||
my $resp = NUKIBridge_CallBlocking($hash,"callback/remove",$id);
|
my $resp = NUKIBridge_CallBlocking($hash,"callback/remove",$id) if( !IsDisabled($name) );
|
||||||
if( $resp->{success} eq "true" ) {
|
if( $resp->{success} eq "true" and !IsDisabled($name) ) {
|
||||||
return "Success Callback $id removed";
|
return "Success Callback $id removed";
|
||||||
} else {
|
} else {
|
||||||
return "remove Callback failed";
|
return "remove Callback failed";
|
||||||
@ -247,12 +248,12 @@ sub NUKIBridge_Get($@) {
|
|||||||
if($cmd eq 'logFile') {
|
if($cmd eq 'logFile') {
|
||||||
return "usage: logFile" if( @args != 0 );
|
return "usage: logFile" if( @args != 0 );
|
||||||
|
|
||||||
NUKIBridge_getLogfile($hash);
|
NUKIBridge_getLogfile($hash) if( !IsDisabled($name) );
|
||||||
|
|
||||||
} elsif($cmd eq 'callbackList') {
|
} elsif($cmd eq 'callbackList') {
|
||||||
return "usage: callbackList" if( @args != 0 );
|
return "usage: callbackList" if( @args != 0 );
|
||||||
|
|
||||||
NUKIBridge_getCallbackList($hash);
|
NUKIBridge_getCallbackList($hash) if( !IsDisabled($name) );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
my $list = "logFile:noArg callbackList:noArg";
|
my $list = "logFile:noArg callbackList:noArg";
|
||||||
@ -273,7 +274,7 @@ sub NUKIBridge_GetCheckBridgeAlive($) {
|
|||||||
|
|
||||||
NUKIBridge_Call($hash,$hash,"alive",undef,undef);
|
NUKIBridge_Call($hash,$hash,"alive",undef,undef);
|
||||||
|
|
||||||
InternalTimer( gettimeofday()+30+int(rand(13)), "NUKIBridge_GetCheckBridgeAlive", $hash, 1 );
|
InternalTimer( gettimeofday()+17+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";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -300,7 +301,6 @@ sub NUKIBridge_Call($$$$$) {
|
|||||||
my $port = $hash->{PORT};
|
my $port = $hash->{PORT};
|
||||||
my $token = $hash->{TOKEN};
|
my $token = $hash->{TOKEN};
|
||||||
|
|
||||||
return "Only single call to Bridge, please try again later" if( $hash->{helper}{BRIDGE_CALL} );
|
|
||||||
|
|
||||||
my $uri = "http://" . $hash->{HOST} . ":" . $port;
|
my $uri = "http://" . $hash->{HOST} . ":" . $port;
|
||||||
$uri .= "/" . $path if( defined $path);
|
$uri .= "/" . $path if( defined $path);
|
||||||
@ -309,19 +309,18 @@ sub NUKIBridge_Call($$$$$) {
|
|||||||
$uri .= "&url=" . $lockAction if( defined($lockAction) and $path eq "callback/add" );
|
$uri .= "&url=" . $lockAction if( defined($lockAction) and $path eq "callback/add" );
|
||||||
$uri .= "&nukiId=" . $nukiId if( defined($nukiId) );
|
$uri .= "&nukiId=" . $nukiId if( defined($nukiId) );
|
||||||
|
|
||||||
$hash->{helper}{BRIDGE_CALL} = 1;
|
|
||||||
|
|
||||||
HttpUtils_NonblockingGet(
|
HttpUtils_NonblockingGet(
|
||||||
{
|
{
|
||||||
url => $uri,
|
url => $uri,
|
||||||
timeout => 30,
|
timeout => 30,
|
||||||
hash => $hash,
|
hash => $hash,
|
||||||
chash => $chash,
|
chash => $chash,
|
||||||
endpoint => $path,
|
endpoint => $path,
|
||||||
header => "Accept: application/json",
|
header => "Accept: application/json",
|
||||||
method => "GET",
|
method => "GET",
|
||||||
callback => \&NUKIBridge_Distribution,
|
callback => \&NUKIBridge_Distribution,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
Log3 $name, 4, "NUKIBridge ($name) - Send HTTP POST with URL $uri";
|
Log3 $name, 4, "NUKIBridge ($name) - Send HTTP POST with URL $uri";
|
||||||
@ -335,22 +334,21 @@ sub NUKIBridge_Distribution($$$) {
|
|||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
my $host = $hash->{HOST};
|
my $host = $hash->{HOST};
|
||||||
|
|
||||||
delete $hash->{helper}{BRIDGE_CALL};
|
|
||||||
|
|
||||||
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 "alive") {
|
||||||
readingsBulkUpdate( $hash, "state", "not connected");
|
readingsBulkUpdate( $hash, "state", "not connected") if( $hash->{helper}{aliveCount} > 1 );
|
||||||
|
$hash->{helper}{aliveCount} = $hash->{helper}{aliveCount} + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
readingsBulkUpdate( $hash, "lastError", $err ) if( ReadingsVal($name,"state","not connected") eq "not connected" );
|
readingsBulkUpdate( $hash, "lastError", $err ) if( ReadingsVal($name,"state","not connected") eq "not connected" );
|
||||||
Log3 $name, 4, "NUKIBridge ($name) - error while requesting: $err";
|
Log3 $name, 4, "NUKIBridge ($name) - error while requesting: $err";
|
||||||
readingsEndUpdate( $hash, 1 );
|
readingsEndUpdate( $hash, 1 );
|
||||||
return $err;
|
return $err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $json eq "" and exists( $param->{code} ) && $param->{code} ne 200 ) {
|
if( $json eq "" and exists( $param->{code} ) && $param->{code} ne 200 ) {
|
||||||
@ -360,14 +358,15 @@ sub NUKIBridge_Distribution($$$) {
|
|||||||
Log3 $name, 5, "NUKIBridge ($name) - Bridge ist online";
|
Log3 $name, 5, "NUKIBridge ($name) - Bridge ist online";
|
||||||
|
|
||||||
readingsEndUpdate( $hash, 1 );
|
readingsEndUpdate( $hash, 1 );
|
||||||
|
$hash->{helper}{aliveCount} = 0;
|
||||||
return;
|
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";
|
||||||
|
|
||||||
readingsEndUpdate( $hash, 1 );
|
readingsEndUpdate( $hash, 1 );
|
||||||
return "received http code ".$param->{code}." without any data after requesting";
|
return "received http code ".$param->{code}." without any data after requesting";
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ( $json =~ /Error/i ) and exists( $param->{code} ) ) {
|
if( ( $json =~ /Error/i ) and exists( $param->{code} ) ) {
|
||||||
@ -381,13 +380,13 @@ sub NUKIBridge_Distribution($$$) {
|
|||||||
NUKIDevice_Parse($param->{chash},$param->{code}) if( $param->{code} eq 400 and $hash != $param->{chash} );
|
NUKIDevice_Parse($param->{chash},$param->{code}) if( $param->{code} eq 400 and $hash != $param->{chash} );
|
||||||
|
|
||||||
|
|
||||||
Log3 $name, 4, "NUKIBridge ($name) - invalid API token" if( $param->{code} eq 401 );
|
Log3 $name, 4, "NUKIBridge ($name) - invalid API token" if( $param->{code} eq 401 );
|
||||||
Log3 $name, 4, "NUKIBridge ($name) - nukiId is not known" if( $param->{code} eq 404 );
|
Log3 $name, 4, "NUKIBridge ($name) - nukiId is not known" if( $param->{code} eq 404 );
|
||||||
Log3 $name, 4, "NUKIBridge ($name) - action is undefined" if( $param->{code} eq 400 and $hash == $param->{chash} );
|
Log3 $name, 4, "NUKIBridge ($name) - action is undefined" if( $param->{code} eq 400 and $hash == $param->{chash} );
|
||||||
|
|
||||||
|
|
||||||
######### Zum testen da ich kein Nuki Smartlock habe ############
|
######### Zum testen da ich kein Nuki Smartlock habe ############
|
||||||
#if ( $param->{code} eq 404 ) {
|
#if ( $param->{code} eq 404 ) {
|
||||||
# if( defined($param->{chash}->{helper}{lockAction}) ) {
|
# if( defined($param->{chash}->{helper}{lockAction}) ) {
|
||||||
# Log3 $name, 3, "NUKIBridge ($name) - Test JSON String for lockAction";
|
# Log3 $name, 3, "NUKIBridge ($name) - Test JSON String for lockAction";
|
||||||
# $json = '{"success": true, "batteryCritical": false}';
|
# $json = '{"success": true, "batteryCritical": false}';
|
||||||
@ -400,7 +399,7 @@ sub NUKIBridge_Distribution($$$) {
|
|||||||
|
|
||||||
|
|
||||||
readingsEndUpdate( $hash, 1 );
|
readingsEndUpdate( $hash, 1 );
|
||||||
return $param->{code};
|
return $param->{code};
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $hash == $param->{chash} ) {
|
if( $hash == $param->{chash} ) {
|
||||||
@ -557,8 +556,9 @@ sub NUKIBridge_getLogfile($) {
|
|||||||
$ret .= "<td><b>Type</b></td>";
|
$ret .= "<td><b>Type</b></td>";
|
||||||
$ret .= '</tr>';
|
$ret .= '</tr>';
|
||||||
|
|
||||||
|
|
||||||
foreach my $logs (@{$decode_json}) {
|
foreach my $logs (@{$decode_json}) {
|
||||||
|
|
||||||
$ret .= "<td>$logs->{timestamp}</td>";
|
$ret .= "<td>$logs->{timestamp}</td>";
|
||||||
$ret .= "<td> </td>";
|
$ret .= "<td> </td>";
|
||||||
$ret .= "<td>$logs->{type}</td>";
|
$ret .= "<td>$logs->{type}</td>";
|
||||||
@ -620,14 +620,12 @@ sub NUKIBridge_CallBlocking($$$) {
|
|||||||
my $port = $hash->{PORT};
|
my $port = $hash->{PORT};
|
||||||
my $token = $hash->{TOKEN};
|
my $token = $hash->{TOKEN};
|
||||||
|
|
||||||
return "Only single call to Bridge, please try again later" if( $hash->{helper}{BRIDGE_CALL} );
|
|
||||||
|
|
||||||
my $url = "http://" . $hash->{HOST} . ":" . $port;
|
my $url = "http://" . $hash->{HOST} . ":" . $port;
|
||||||
$url .= "/" . $path if( defined $path);
|
$url .= "/" . $path if( defined $path);
|
||||||
$url .= "?token=" . $token if( defined($token) );
|
$url .= "?token=" . $token if( defined($token) );
|
||||||
$url .= "&" . $obj if( defined($obj) );
|
$url .= "&" . $obj if( defined($obj) );
|
||||||
|
|
||||||
$hash->{helper}{BRIDGE_CALL} = 1;
|
|
||||||
|
|
||||||
my($err,$data) = HttpUtils_BlockingGet({
|
my($err,$data) = HttpUtils_BlockingGet({
|
||||||
url => $url,
|
url => $url,
|
||||||
@ -635,8 +633,7 @@ sub NUKIBridge_CallBlocking($$$) {
|
|||||||
method => "GET",
|
method => "GET",
|
||||||
header => "Content-Type: application/json",
|
header => "Content-Type: application/json",
|
||||||
});
|
});
|
||||||
|
|
||||||
delete $hash->{helper}{BRIDGE_CALL};
|
|
||||||
|
|
||||||
if( !$data ) {
|
if( !$data ) {
|
||||||
Log3 $name, 3, "NUKIDevice ($name) - empty answer received for $url";
|
Log3 $name, 3, "NUKIDevice ($name) - empty answer received for $url";
|
||||||
@ -753,6 +750,15 @@ sub NUKIBridge_CallBlocking($$$) {
|
|||||||
<li>0_name - Name des ersten gefunden Nuki Smartlocks</li>
|
<li>0_name - Name des ersten gefunden Nuki Smartlocks</li>
|
||||||
<li>smartlockCount - Anzahl aller gefundenen Smartlock</li>
|
<li>smartlockCount - Anzahl aller gefundenen Smartlock</li>
|
||||||
<li>bridgeAPI - API Version der Bridge</li>
|
<li>bridgeAPI - API Version der Bridge</li>
|
||||||
|
<li>bridgeType - Hardware oder Software/App Bridge</li>
|
||||||
|
<li>currentTime - aktuelle Zeit auf der Bridge zum zeitpunkt des Info holens</li>
|
||||||
|
<li>firmwareVersion - aktuell auf der Bridge verwendete Firmwareversion</li>
|
||||||
|
<li>hardwareId - ID der Hardware Bridge</li>
|
||||||
|
<li>lastError - gibt die letzte HTTP Errormeldung wieder</li>
|
||||||
|
<li>serverConnected - true/false gibt an ob die Hardwarebridge Verbindung zur Nuki-Cloude hat.</li>
|
||||||
|
<li>serverId - gibt die ID des Cloudeservers wieder</li>
|
||||||
|
<li>uptime - Uptime der Bridge in Sekunden</li>
|
||||||
|
<li>wifiFirmwareVersion- Firmwareversion des Wifi Modules der Bridge</li>
|
||||||
<br>
|
<br>
|
||||||
Die vorangestellte Zahl ist forlaufend und gibt beginnend bei 0 die Eigenschaften <b>Eines</b> Smartlocks wieder.
|
Die vorangestellte Zahl ist forlaufend und gibt beginnend bei 0 die Eigenschaften <b>Eines</b> Smartlocks wieder.
|
||||||
</ul>
|
</ul>
|
||||||
@ -761,7 +767,19 @@ sub NUKIBridge_CallBlocking($$$) {
|
|||||||
<b>Set</b>
|
<b>Set</b>
|
||||||
<ul>
|
<ul>
|
||||||
<li>autocreate - Veranlasst ein erneutes Einlesen aller Smartlocks von der Bridge und falls noch nicht in FHEM vorhanden das autimatische anlegen.</li>
|
<li>autocreate - Veranlasst ein erneutes Einlesen aller Smartlocks von der Bridge und falls noch nicht in FHEM vorhanden das autimatische anlegen.</li>
|
||||||
<li>statusRequest - startet einen checkAlive der Bridge, es wird festgestellt ob die Bridge noch online ist</li>
|
<li>callbackRemove - Löschen einer Callback Instanz auf der Bridge. Die Instanz ID kann mittels get callbackList ermittelt werden</li>
|
||||||
|
<li>clearLog - löscht das Logfile auf der Bridge</li>
|
||||||
|
<li>fwUpdate - schaut nach einer neueren Firmware und installiert diese sofern vorhanden</li>
|
||||||
|
<li>info - holt aktuellen Informationen über die Bridge</li>
|
||||||
|
<li>reboot - veranlässt ein reboot der Bridge</li>
|
||||||
|
<br>
|
||||||
|
</ul>
|
||||||
|
<br><br>
|
||||||
|
<a name="NUKIBridgeget"></a>
|
||||||
|
<b>Get</b>
|
||||||
|
<ul>
|
||||||
|
<li>callbackList - Gibt die Liste der eingetragenen Callback URL's wieder. Die Bridge nimmt maximal 3 auf.</li>
|
||||||
|
<li>logFile - Zeigt das Logfile der Bridge an</li>
|
||||||
<br>
|
<br>
|
||||||
</ul>
|
</ul>
|
||||||
<br><br>
|
<br><br>
|
||||||
|
@ -42,25 +42,24 @@ sub NUKIDevice_Initialize($) {
|
|||||||
|
|
||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
|
|
||||||
$hash->{SetFn} = "NUKIDevice_Set";
|
$hash->{SetFn} = "NUKIDevice_Set";
|
||||||
$hash->{DefFn} = "NUKIDevice_Define";
|
$hash->{DefFn} = "NUKIDevice_Define";
|
||||||
$hash->{UndefFn} = "NUKIDevice_Undef";
|
$hash->{UndefFn} = "NUKIDevice_Undef";
|
||||||
$hash->{AttrFn} = "NUKIDevice_Attr";
|
$hash->{AttrFn} = "NUKIDevice_Attr";
|
||||||
|
|
||||||
my $webhookFWinstance = join( ",", devspec2array('TYPE=FHEMWEB:FILTER=TEMPORARY!=1') );
|
my $webhookFWinstance = join( ",", devspec2array('TYPE=FHEMWEB:FILTER=TEMPORARY!=1') );
|
||||||
|
|
||||||
$hash->{AttrList} = "IODev ".
|
$hash->{AttrList} = "IODev ".
|
||||||
"disable:1 ".
|
"disable:1 ".
|
||||||
"webhookFWinstance:$webhookFWinstance ".
|
"webhookFWinstance:$webhookFWinstance ".
|
||||||
"webhookHttpHostname ".
|
"webhookHttpHostname ".
|
||||||
"webhookPort ".
|
|
||||||
$readingFnAttributes;
|
$readingFnAttributes;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
foreach my $d(sort keys %{$modules{NUKIDevice}{defptr}}) {
|
foreach my $d(sort keys %{$modules{NUKIDevice}{defptr}}) {
|
||||||
my $hash = $modules{NUKIDevice}{defptr}{$d};
|
my $hash = $modules{NUKIDevice}{defptr}{$d};
|
||||||
$hash->{VERSION} = $version;
|
$hash->{VERSION} = $version;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,8 +86,8 @@ sub NUKIDevice_Define($$) {
|
|||||||
|
|
||||||
my ($name,$nukiId) = @a;
|
my ($name,$nukiId) = @a;
|
||||||
|
|
||||||
$hash->{NUKIID} = $nukiId;
|
$hash->{NUKIID} = $nukiId;
|
||||||
$hash->{VERSION} = $version;
|
$hash->{VERSION} = $version;
|
||||||
$hash->{STATE} = 'Initialized';
|
$hash->{STATE} = 'Initialized';
|
||||||
my $infix = "NUKIDevice";
|
my $infix = "NUKIDevice";
|
||||||
|
|
||||||
@ -167,24 +166,26 @@ sub NUKIDevice_Attr(@) {
|
|||||||
my $token = $hash->{IODev}->{TOKEN};
|
my $token = $hash->{IODev}->{TOKEN};
|
||||||
|
|
||||||
if( $attrName eq "disable" ) {
|
if( $attrName eq "disable" ) {
|
||||||
if( $cmd eq "set" ) {
|
if( $cmd eq "set" and $attrVal eq "1" ) {
|
||||||
if( $attrVal eq "0" ) {
|
readingsSingleUpdate ( $hash, "state", "disabled", 1 );
|
||||||
RemoveInternalTimer( $hash );
|
Log3 $name, 3, "NUKIDevice ($name) - disabled";
|
||||||
InternalTimer( gettimeofday()+2, "NUKIDevice_GetUpdateInternalTimer", $hash, 0 );
|
}
|
||||||
readingsSingleUpdate ( $hash, "state", "Initialized", 1 );
|
|
||||||
Log3 $name, 3, "NUKIDevice ($name) - enabled";
|
elsif( $cmd eq "del" ) {
|
||||||
} else {
|
readingsSingleUpdate ( $hash, "state", "active", 1 );
|
||||||
readingsSingleUpdate ( $hash, "state", "disabled", 1 );
|
Log3 $name, 3, "NUKIDevice ($name) - enabled";
|
||||||
RemoveInternalTimer( $hash );
|
}
|
||||||
Log3 $name, 3, "NUKIDevice ($name) - disabled";
|
}
|
||||||
}
|
|
||||||
|
if( $attrName eq "disabledForIntervals" ) {
|
||||||
} else {
|
if( $cmd eq "set" ) {
|
||||||
|
Log3 $name, 3, "NUKIDevice ($name) - enable disabledForIntervals";
|
||||||
RemoveInternalTimer( $hash );
|
readingsSingleUpdate ( $hash, "state", "Unknown", 1 );
|
||||||
InternalTimer( gettimeofday()+2, "NUKIDevice_GetUpdateInternalTimer", $hash, 0 );
|
}
|
||||||
readingsSingleUpdate ( $hash, "state", "Initialized", 1 );
|
|
||||||
Log3 $name, 3, "NUKIDevice ($name) - enabled";
|
elsif( $cmd eq "del" ) {
|
||||||
|
readingsSingleUpdate ( $hash, "state", "active", 1 );
|
||||||
|
Log3 $name, 3, "NUKIDevice ($name) - delete disabledForIntervals";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,7 +252,7 @@ sub NUKIDevice_removeExtension($) {
|
|||||||
|
|
||||||
my ($link) = @_;
|
my ($link) = @_;
|
||||||
|
|
||||||
my $url = "?/$link";
|
my $url = "/$link";
|
||||||
my $name = $data{FWEXT}{$url}{deviceName};
|
my $name = $data{FWEXT}{$url}{deviceName};
|
||||||
|
|
||||||
Log3 $name, 2, "NUKIDevice ($name) - Unregistering NUKIDevice for webhook URL $url...";
|
Log3 $name, 2, "NUKIDevice ($name) - Unregistering NUKIDevice for webhook URL $url...";
|
||||||
@ -294,28 +295,11 @@ sub NUKIDevice_Set($$@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$hash->{helper}{lockAction} = $lockAction;
|
$hash->{helper}{lockAction} = $lockAction;
|
||||||
NUKIDevice_ReadFromNUKIBridge($hash,"lockAction",$lockAction,$hash->{NUKIID} );
|
NUKIDevice_ReadFromNUKIBridge($hash,"lockAction",$lockAction,$hash->{NUKIID} ) if( !IsDisabled($name) );
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub NUKIDevice_GetUpdateTimer($) {
|
|
||||||
|
|
||||||
my ($hash) = @_;
|
|
||||||
my $name = $hash->{NAME};
|
|
||||||
|
|
||||||
|
|
||||||
RemoveInternalTimer($hash);
|
|
||||||
|
|
||||||
if( !IsDisabled($name) ) {
|
|
||||||
NUKIDevice_ReadFromNUKIBridge($hash, "lockState", undef, $hash->{NUKIID} );
|
|
||||||
Log3 $name, 5, "NUKIDevice ($name) - NUKIDevice_GetUpdateTimer Call NUKIDevice_ReadFromNUKIBridge";
|
|
||||||
InternalTimer( gettimeofday()+12+int(rand(18)), "NUKIDevice_GetUpdateTimer", $hash, 1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
return undef;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub NUKIDevice_GetUpdate($) {
|
sub NUKIDevice_GetUpdate($) {
|
||||||
|
|
||||||
my ($hash) = @_;
|
my ($hash) = @_;
|
||||||
@ -469,7 +453,9 @@ sub NUKIDevice_CGI() {
|
|||||||
my $name;
|
my $name;
|
||||||
my $nukiId;
|
my $nukiId;
|
||||||
|
|
||||||
# data received Testaufruf: wget --post-data '{"nukiId": 102844, "state": 1,"stateName": "locked", "batteryCritical": false}' http://10.6.6.20:8083/fhem/NUKIDevice-102844
|
# data received
|
||||||
|
# Testaufruf: 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);
|
||||||
printf "\n\nHTTP Header: $header\n\n";
|
printf "\n\nHTTP Header: $header\n\n";
|
||||||
@ -576,6 +562,8 @@ sub NUKIDevice_CGI() {
|
|||||||
<b>Attributes</b>
|
<b>Attributes</b>
|
||||||
<ul>
|
<ul>
|
||||||
<li>disable - disables the Nuki device</li>
|
<li>disable - disables the Nuki device</li>
|
||||||
|
<li>webhookFWinstance - zu verwendene Webinstanz für den Callbackaufruf</li>
|
||||||
|
<li>webhookHttpHostname - IP oder FQDN vom FHEM Server für den Callbackaufruf</li>
|
||||||
<br>
|
<br>
|
||||||
</ul>
|
</ul>
|
||||||
</ul>
|
</ul>
|
||||||
|
Loading…
Reference in New Issue
Block a user