Merge branch 'devel' into patch-supportNewSmartLock3
This commit is contained in:
commit
c13ac1014d
133
73_NUKIBridge.pm
133
73_NUKIBridge.pm
@ -2,7 +2,7 @@
|
|||||||
#
|
#
|
||||||
# Developed with Kate
|
# Developed with Kate
|
||||||
#
|
#
|
||||||
# (c) 2016-2020 Copyright: Marko Oldenburg (hemdevelopment at cooltux dot net)
|
# (c) 2016-2021 Copyright: Marko Oldenburg (fhemdevelopment at cooltux dot net)
|
||||||
# All rights reserved
|
# All rights reserved
|
||||||
#
|
#
|
||||||
# This script is free software; you can redistribute it and/or modify
|
# This script is free software; you can redistribute it and/or modify
|
||||||
@ -370,7 +370,8 @@ sub Attr(@) {
|
|||||||
. $hash->{WEBHOOK_URI};
|
. $hash->{WEBHOOK_URI};
|
||||||
|
|
||||||
Log3( $name, 3, "NUKIBridge ($name) - URL ist: $url" );
|
Log3( $name, 3, "NUKIBridge ($name) - URL ist: $url" );
|
||||||
Write( $hash, 'callback/add', $url, undef, undef )
|
# Write( $hash, 'callback/add', $url, undef, undef )
|
||||||
|
Write( $hash, 'callback/add', '{"param":"' . $url . '"}' )
|
||||||
if ($init_done);
|
if ($init_done);
|
||||||
$hash->{WEBHOOK_REGISTER} = 'sent';
|
$hash->{WEBHOOK_REGISTER} = 'sent';
|
||||||
}
|
}
|
||||||
@ -444,54 +445,48 @@ sub Set($@) {
|
|||||||
my ( $hash, $name, $cmd, @args ) = @_;
|
my ( $hash, $name, $cmd, @args ) = @_;
|
||||||
|
|
||||||
my ( $arg, @params ) = @args;
|
my ( $arg, @params ) = @args;
|
||||||
|
my $endpoint;
|
||||||
|
|
||||||
if ( lc($cmd) eq 'getdevicelist' ) {
|
if ( lc($cmd) eq 'getdevicelist' ) {
|
||||||
return 'usage: getDeviceList' if ( @args != 0 );
|
return 'usage: getDeviceList' if ( @args != 0 );
|
||||||
|
|
||||||
Write( $hash, 'list', undef, undef, undef )
|
$endpoint = 'list';
|
||||||
if ( !IsDisabled($name) );
|
|
||||||
return undef;
|
|
||||||
}
|
}
|
||||||
elsif ( $cmd eq 'info' ) {
|
elsif ( $cmd eq 'info' ) {
|
||||||
return 'usage: statusRequest' if ( @args != 0 );
|
return 'usage: statusRequest' if ( @args != 0 );
|
||||||
|
|
||||||
Write( $hash, 'info', undef, undef, undef )
|
$endpoint = 'info';
|
||||||
if ( !IsDisabled($name) );
|
|
||||||
return undef;
|
|
||||||
}
|
}
|
||||||
elsif ( lc($cmd) eq 'fwupdate' ) {
|
elsif ( lc($cmd) eq 'fwupdate' ) {
|
||||||
return 'usage: fwUpdate' if ( @args != 0 );
|
return 'usage: fwUpdate' if ( @args != 0 );
|
||||||
|
|
||||||
Write( $hash, 'fwupdate', undef, undef, undef )
|
$endpoint = 'fwupdate';
|
||||||
if ( !IsDisabled($name) );
|
|
||||||
return undef;
|
|
||||||
}
|
}
|
||||||
elsif ( $cmd eq 'reboot' ) {
|
elsif ( $cmd eq 'reboot' ) {
|
||||||
return 'usage: reboot' if ( @args != 0 );
|
return 'usage: reboot' if ( @args != 0 );
|
||||||
|
|
||||||
Write( $hash, 'reboot', undef, undef, undef )
|
$endpoint = 'reboot';
|
||||||
if ( !IsDisabled($name) );
|
|
||||||
return undef;
|
|
||||||
}
|
}
|
||||||
elsif ( lc($cmd) eq 'clearlog' ) {
|
elsif ( lc($cmd) eq 'clearlog' ) {
|
||||||
return 'usage: clearLog' if ( @args != 0 );
|
return 'usage: clearLog' if ( @args != 0 );
|
||||||
|
|
||||||
Write( $hash, 'clearlog', undef, undef, undef )
|
$endpoint = 'clearlog';
|
||||||
if ( !IsDisabled($name) );
|
|
||||||
}
|
}
|
||||||
elsif ( lc($cmd) eq 'factoryreset' ) {
|
elsif ( lc($cmd) eq 'factoryreset' ) {
|
||||||
return 'usage: clearLog' if ( @args != 0 );
|
return 'usage: clearLog' if ( @args != 0 );
|
||||||
|
|
||||||
Write( $hash, 'factoryReset', undef, undef, undef )
|
$endpoint = 'factoryReset';
|
||||||
if ( !IsDisabled($name) );
|
|
||||||
}
|
}
|
||||||
elsif ( lc($cmd) eq 'callbackremove' ) {
|
elsif ( lc($cmd) eq 'callbackremove' ) {
|
||||||
return 'usage: callbackRemove' if ( @args > 1 );
|
return 'usage: callbackRemove' if ( @args > 1 );
|
||||||
|
|
||||||
my $id = ( @args > 0 ? join( ' ', @args ) : 0 );
|
my $id = ( @args > 0 ? join( ' ', @args ) : 0 );
|
||||||
|
|
||||||
Write( $hash, 'callback/remove', $id, undef, undef )
|
# Write( $hash, 'callback/remove', $id, undef, undef )
|
||||||
|
Write( $hash, 'callback/remove', '{"param":"' . $id . '"}' )
|
||||||
if ( !IsDisabled($name) );
|
if ( !IsDisabled($name) );
|
||||||
|
|
||||||
|
return undef;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
my $list = '';
|
my $list = '';
|
||||||
@ -500,22 +495,26 @@ sub Set($@) {
|
|||||||
if ( ReadingsVal( $name, 'bridgeType', 'Software' ) eq 'Hardware' );
|
if ( ReadingsVal( $name, 'bridgeType', 'Software' ) eq 'Hardware' );
|
||||||
return ( 'Unknown argument ' . $cmd . ', choose one of ' . $list );
|
return ( 'Unknown argument ' . $cmd . ', choose one of ' . $list );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Write( $hash, $endpoint, undef )
|
||||||
|
if ( !IsDisabled($name) );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub Get($@) {
|
sub Get($@) {
|
||||||
my ( $hash, $name, $cmd, @args ) = @_;
|
my ( $hash, $name, $cmd, @args ) = @_;
|
||||||
|
|
||||||
my ( $arg, @params ) = @args;
|
my ( $arg, @params ) = @args;
|
||||||
|
my $endpoint;
|
||||||
|
|
||||||
if ( lc($cmd) eq 'logfile' ) {
|
if ( lc($cmd) eq 'logfile' ) {
|
||||||
return 'usage: logFile' if ( @args != 0 );
|
return 'usage: logFile' if ( @args != 0 );
|
||||||
|
|
||||||
Write( $hash, 'log', undef, undef, undef );
|
$endpoint = 'log';
|
||||||
}
|
}
|
||||||
elsif ( lc($cmd) eq 'callbacklist' ) {
|
elsif ( lc($cmd) eq 'callbacklist' ) {
|
||||||
return 'usage: callbackList' if ( @args != 0 );
|
return 'usage: callbackList' if ( @args != 0 );
|
||||||
|
|
||||||
Write( $hash, 'callback/list', undef, undef, undef );
|
$endpoint = 'callback/list';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
my $list = '';
|
my $list = '';
|
||||||
@ -525,6 +524,8 @@ sub Get($@) {
|
|||||||
|
|
||||||
return 'Unknown argument ' . $cmd . ', choose one of ' . $list;
|
return 'Unknown argument ' . $cmd . ', choose one of ' . $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Write( $hash, $endpoint, undef )
|
||||||
}
|
}
|
||||||
|
|
||||||
sub GetCheckBridgeAlive($) {
|
sub GetCheckBridgeAlive($) {
|
||||||
@ -539,7 +540,7 @@ sub GetCheckBridgeAlive($) {
|
|||||||
and $hash->{helper}->{iowrite} == 0 )
|
and $hash->{helper}->{iowrite} == 0 )
|
||||||
{
|
{
|
||||||
|
|
||||||
Write( $hash, 'info', undef, undef, undef );
|
Write( $hash, 'info', undef);
|
||||||
|
|
||||||
Log3( $name, 4, "NUKIBridge ($name) - run Write" );
|
Log3( $name, 4, "NUKIBridge ($name) - run Write" );
|
||||||
}
|
}
|
||||||
@ -557,7 +558,7 @@ sub FirstRun($) {
|
|||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
RemoveInternalTimer($hash);
|
RemoveInternalTimer($hash);
|
||||||
Write( $hash, 'list', undef, undef, undef )
|
Write( $hash, 'list', undef )
|
||||||
if ( !IsDisabled($name) );
|
if ( !IsDisabled($name) );
|
||||||
InternalTimer( gettimeofday() + 5,
|
InternalTimer( gettimeofday() + 5,
|
||||||
'NUKIBridge_GetCheckBridgeAlive', $hash );
|
'NUKIBridge_GetCheckBridgeAlive', $hash );
|
||||||
@ -566,7 +567,14 @@ sub FirstRun($) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub Write($@) {
|
sub Write($@) {
|
||||||
my ( $hash, $endpoint, $param, $nukiId, $deviceType ) = @_;
|
my ( $hash, $endpoint, $json ) = @_;
|
||||||
|
|
||||||
|
my $decode_json = eval { decode_json($json) }
|
||||||
|
if ( defined($json) );
|
||||||
|
|
||||||
|
my $nukiId = $decode_json->{nukiId} // undef;
|
||||||
|
my $deviceType = $decode_json->{deviceType} // undef;
|
||||||
|
my $param = $decode_json->{param} // undef;
|
||||||
|
|
||||||
my $obj = {
|
my $obj = {
|
||||||
endpoint => $endpoint,
|
endpoint => $endpoint,
|
||||||
@ -911,7 +919,7 @@ sub ResponseProcessing($$$) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
InfoProcessing( $hash, $decode_json )
|
WriteReadings( $hash, $decode_json )
|
||||||
if ( $endpoint eq 'info' );
|
if ( $endpoint eq 'info' );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -980,7 +988,7 @@ matching NukiId at device $name"
|
|||||||
return ( 'text/plain; charset=utf-8', 'Call failure: ' . $request );
|
return ( 'text/plain; charset=utf-8', 'Call failure: ' . $request );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub InfoProcessing($$) {
|
sub WriteReadings($$) {
|
||||||
my ( $hash, $decode_json ) = @_;
|
my ( $hash, $decode_json ) = @_;
|
||||||
|
|
||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
@ -1003,7 +1011,7 @@ sub InfoProcessing($$) {
|
|||||||
readingsBulkUpdate( $hash, 'hardwareId', $decode_json->{ids}{hardwareId} );
|
readingsBulkUpdate( $hash, 'hardwareId', $decode_json->{ids}{hardwareId} );
|
||||||
readingsBulkUpdate( $hash, 'serverId', $decode_json->{ids}{serverId} );
|
readingsBulkUpdate( $hash, 'serverId', $decode_json->{ids}{serverId} );
|
||||||
readingsBulkUpdate( $hash, 'uptime', $decode_json->{uptime} );
|
readingsBulkUpdate( $hash, 'uptime', $decode_json->{uptime} );
|
||||||
readingsBulkUpdate( $hash, 'currentTime', $decode_json->{currentTime} );
|
readingsBulkUpdate( $hash, 'currentGMTime', $decode_json->{currentTime} );
|
||||||
readingsBulkUpdate( $hash, 'serverConnected',
|
readingsBulkUpdate( $hash, 'serverConnected',
|
||||||
$decode_json->{serverConnected} );
|
$decode_json->{serverConnected} );
|
||||||
readingsEndUpdate( $hash, 1 );
|
readingsEndUpdate( $hash, 1 );
|
||||||
@ -1092,6 +1100,72 @@ sub getCallbackList($$) {
|
|||||||
Log3( $name, 4,
|
Log3( $name, 4,
|
||||||
"NUKIBridge ($name) - created Table with log file" );
|
"NUKIBridge ($name) - created Table with log file" );
|
||||||
|
|
||||||
|
my $space = ' ';
|
||||||
|
my $aHref;
|
||||||
|
my $header = '<html>'
|
||||||
|
. '<div style="float: left">Callback List</div>';
|
||||||
|
|
||||||
|
my $ret = $header.'<table width=100%><tr><td>';
|
||||||
|
$ret .= '<table class="block wide">';
|
||||||
|
$ret .= '<tr class="odd">';
|
||||||
|
$ret .= '<td><b>URL</b></td>';
|
||||||
|
$ret .= '<td><b>Remove</b></td>';
|
||||||
|
$ret .= '</tr>';
|
||||||
|
|
||||||
|
if ( scalar( @{ $decode_json->{callbacks} } ) > 0 ) {
|
||||||
|
foreach my $cb ( @{ $decode_json->{callbacks} } ) {
|
||||||
|
$aHref =
|
||||||
|
"<a href=\""
|
||||||
|
. $::FW_httpheader->{host}
|
||||||
|
. "/fhem?cmd=set+"
|
||||||
|
. $name
|
||||||
|
. "+callbackRemove+"
|
||||||
|
. $cb->{id}
|
||||||
|
. $::FW_CSRF
|
||||||
|
. "\"><font color=\"red\"><b>X</b></font></a>";
|
||||||
|
|
||||||
|
$ret .= '<td>' . $cb->{url} . '</td>';
|
||||||
|
$ret .= '<td>'.$aHref.'</td>';
|
||||||
|
$ret .= '</tr>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$ret .= '<td>none</td>';
|
||||||
|
$ret .= '<td>none</td>';
|
||||||
|
$ret .= '<td> </td>';
|
||||||
|
$ret .= '</tr>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$ret .= '</table></td></tr>';
|
||||||
|
$ret .= '</table></html>';
|
||||||
|
|
||||||
|
asyncOutput( $param->{cl}, $ret )
|
||||||
|
if ( $param->{cl} and $param->{cl}{canAsyncOutput} );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub getCallbackList2($$) {
|
||||||
|
my ( $param, $json ) = @_;
|
||||||
|
|
||||||
|
my $hash = $param->{hash};
|
||||||
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
|
my $decode_json = eval { decode_json($json) };
|
||||||
|
if ($@) {
|
||||||
|
Log3( $name, 3, "NUKIBridge ($name) - JSON error while request: $@" );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log3( $name, 4,
|
||||||
|
"NUKIBridge ($name) - Callback data are collected and processed" );
|
||||||
|
|
||||||
|
if ( $param->{cl} and $param->{cl}->{TYPE} eq 'FHEMWEB' ) {
|
||||||
|
if ( ref( $decode_json->{callbacks} ) eq 'ARRAY' ) {
|
||||||
|
Log3( $name, 4,
|
||||||
|
"NUKIBridge ($name) - created Table with Callback List" );
|
||||||
|
|
||||||
|
|
||||||
my $j1 = '<script language=\"javascript\" type=\"text/javascript\">{';
|
my $j1 = '<script language=\"javascript\" type=\"text/javascript\">{';
|
||||||
$j1 .= "function callbackRemove(){FW_cmd(FW_root+'?cmd=get $name callbackList&XHR=1')}";
|
$j1 .= "function callbackRemove(){FW_cmd(FW_root+'?cmd=get $name callbackList&XHR=1')}";
|
||||||
@ -1129,6 +1203,9 @@ sub getCallbackList($$) {
|
|||||||
$ret .= '</table></td></tr>';
|
$ret .= '</table></td></tr>';
|
||||||
$ret .= '</table>';
|
$ret .= '</table>';
|
||||||
|
|
||||||
|
Log3( $name, 4,
|
||||||
|
"NUKIBridge ($name) - Callback List Table created and call asyncOutput Fn" );
|
||||||
|
|
||||||
asyncOutput( $param->{cl}, $header . $ret . $j1 . $footer )
|
asyncOutput( $param->{cl}, $header . $ret . $j1 . $footer )
|
||||||
if ( $param->{cl} and $param->{cl}{canAsyncOutput} );
|
if ( $param->{cl} and $param->{cl}{canAsyncOutput} );
|
||||||
return;
|
return;
|
||||||
@ -1355,7 +1432,7 @@ sub ParseJSON($$) {
|
|||||||
],
|
],
|
||||||
"release_status": "stable",
|
"release_status": "stable",
|
||||||
"license": "GPL_2",
|
"license": "GPL_2",
|
||||||
"version": "v1.9.20",
|
"version": "v1.9.50",
|
||||||
"x_apiversion": "1.9",
|
"x_apiversion": "1.9",
|
||||||
"author": [
|
"author": [
|
||||||
"Marko Oldenburg <leongaultier@gmail.com>"
|
"Marko Oldenburg <leongaultier@gmail.com>"
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#
|
#
|
||||||
# Developed with Kate
|
# Developed with Kate
|
||||||
#
|
#
|
||||||
# (c) 2016-2021 Copyright: Marko Oldenburg (hemdevelopment at cooltux dot net)
|
# (c) 2016-2021 Copyright: Marko Oldenburg (fhemdevelopment at cooltux dot net)
|
||||||
# All rights reserved
|
# All rights reserved
|
||||||
#
|
#
|
||||||
# This script is free software; you can redistribute it and/or modify
|
# This script is free software; you can redistribute it and/or modify
|
||||||
@ -434,8 +434,11 @@ sub Set($$@) {
|
|||||||
|
|
||||||
$hash->{helper}{lockAction} = $lockAction;
|
$hash->{helper}{lockAction} = $lockAction;
|
||||||
|
|
||||||
IOWrite( $hash, 'lockAction', $lockAction, $hash->{NUKIID},
|
# IOWrite( $hash, 'lockAction', $lockAction, $hash->{NUKIID},
|
||||||
$hash->{DEVICETYPE} );
|
# $hash->{DEVICETYPE} );
|
||||||
|
|
||||||
|
IOWrite( $hash, 'lockAction', '{"param":"' . $lockAction
|
||||||
|
. '","nukiId":' . $hash->{NUKIID} . ',"deviceType":' . $hash->{DEVICETYPE} . '}' );
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@ -446,8 +449,12 @@ sub GetUpdate($) {
|
|||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
if ( !IsDisabled($name) ) {
|
if ( !IsDisabled($name) ) {
|
||||||
IOWrite( $hash, 'lockState', undef, $hash->{NUKIID},
|
# IOWrite( $hash, 'lockState', undef, $hash->{NUKIID},
|
||||||
$hash->{DEVICETYPE} );
|
# $hash->{DEVICETYPE} );
|
||||||
|
|
||||||
|
IOWrite( $hash, 'lockState', '{"nukiId":' . $hash->{NUKIID}
|
||||||
|
. ',"deviceType":' . $hash->{DEVICETYPE} . '}' );
|
||||||
|
|
||||||
Log3( $name, 2, "NUKIDevice ($name) - GetUpdate Call IOWrite" );
|
Log3( $name, 2, "NUKIDevice ($name) - GetUpdate Call IOWrite" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -510,7 +517,7 @@ sub Parse($$) {
|
|||||||
return $hash->{NAME};
|
return $hash->{NAME};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Log3( $name, 3,
|
Log3( $name, 4,
|
||||||
"NUKIDevice ($name) - autocreate new device "
|
"NUKIDevice ($name) - autocreate new device "
|
||||||
. makeDeviceName( $decode_json->{name} )
|
. makeDeviceName( $decode_json->{name} )
|
||||||
. " with nukiId $decode_json->{nukiId}, model $decode_json->{deviceType}"
|
. " with nukiId $decode_json->{nukiId}, model $decode_json->{deviceType}"
|
||||||
@ -544,7 +551,10 @@ sub WriteReadings($$) {
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
$state = $hash->{helper}{lockAction};
|
$state = $hash->{helper}{lockAction};
|
||||||
IOWrite( $hash, 'lockState', undef, $hash->{NUKIID} )
|
# IOWrite( $hash, 'lockState', undef, $hash->{NUKIID} )
|
||||||
|
|
||||||
|
IOWrite( $hash, 'lockState', '{"nukiId":' . $hash->{NUKIID}
|
||||||
|
. ',"deviceType":' . $hash->{DEVICETYPE} . '}' )
|
||||||
if (
|
if (
|
||||||
ReadingsVal( $hash->{IODev}->{NAME}, 'bridgeType', 'Software' )
|
ReadingsVal( $hash->{IODev}->{NAME}, 'bridgeType', 'Software' )
|
||||||
eq 'Software' );
|
eq 'Software' );
|
||||||
@ -558,8 +568,10 @@ sub WriteReadings($$) {
|
|||||||
{
|
{
|
||||||
|
|
||||||
$state = $deviceTypes{ $hash->{DEVICETYPE} } . ' response error';
|
$state = $deviceTypes{ $hash->{DEVICETYPE} } . ' response error';
|
||||||
IOWrite( $hash, 'lockState', undef, $hash->{NUKIID},
|
# IOWrite( $hash, 'lockState', undef, $hash->{NUKIID},
|
||||||
$hash->{DEVICETYPE} );
|
# $hash->{DEVICETYPE} );
|
||||||
|
IOWrite( $hash, 'lockState', '{"nukiId":' . $hash->{NUKIID}
|
||||||
|
. ',"deviceType":' . $hash->{DEVICETYPE} . '}' );
|
||||||
}
|
}
|
||||||
|
|
||||||
$decode_json->{'state'} = $state;
|
$decode_json->{'state'} = $state;
|
||||||
@ -757,7 +769,7 @@ sub WriteReadings($$) {
|
|||||||
],
|
],
|
||||||
"release_status": "stable",
|
"release_status": "stable",
|
||||||
"license": "GPL_2",
|
"license": "GPL_2",
|
||||||
"version": "v1.9.20",
|
"version": "v1.9.50",
|
||||||
"author": [
|
"author": [
|
||||||
"Marko Oldenburg <leongaultier@gmail.com>"
|
"Marko Oldenburg <leongaultier@gmail.com>"
|
||||||
],
|
],
|
||||||
|
Loading…
Reference in New Issue
Block a user