patch-discoveryAuthorization #14

Merged
marko merged 2 commits from patch-discoveryAuthorization into devel 2021-11-28 06:32:16 +00:00
3 changed files with 57 additions and 39 deletions

View File

@ -1,4 +1,4 @@
UPD 2021-11-27_22:52:03 9217 FHEM/73_NUKIBridge.pm UPD 2021-11-28_00:29:42 9217 FHEM/73_NUKIBridge.pm
UPD 2021-11-27_21:36:27 7569 FHEM/74_NUKIDevice.pm UPD 2021-11-28_00:29:54 7569 FHEM/74_NUKIDevice.pm
UPD 2021-11-27_22:52:20 40367 lib/FHEM/Devices/Nuki/Bridge.pm UPD 2021-11-28_00:30:36 41129 lib/FHEM/Devices/Nuki/Bridge.pm
UPD 2021-11-27_22:56:00 15826 lib/FHEM/Devices/Nuki/Device.pm UPD 2021-11-28_00:30:50 15802 lib/FHEM/Devices/Nuki/Device.pm

View File

@ -146,10 +146,6 @@ sub Define {
my ( $name, undef, $host, $token ) = split( m{\s+}xms, $def ); my ( $name, undef, $host, $token ) = split( m{\s+}xms, $def );
# return ('too few parameters: define <name> NUKIBridge <HOST> <TOKEN>')
# if ( !defined($host)
# || !defined($token) );
my $port = ::AttrVal( $name, 'port', 8080 ); my $port = ::AttrVal( $name, 'port', 8080 );
my $infix = 'NUKIBridge'; my $infix = 'NUKIBridge';
$hash->{HOST} = $host // 'discover'; $hash->{HOST} = $host // 'discover';
@ -411,6 +407,7 @@ sub Set {
my $arg = shift // ''; my $arg = shift // '';
my $endpoint; my $endpoint;
my $param;
if ( lc($cmd) eq 'getdevicelist' ) { if ( lc($cmd) eq 'getdevicelist' ) {
return 'usage: getDeviceList' if ($arg); return 'usage: getDeviceList' if ($arg);
@ -441,21 +438,26 @@ sub Set {
return 'usage: callbackRemove' if ( split( m{\s+}xms, $arg ) > 1 ); return 'usage: callbackRemove' if ( split( m{\s+}xms, $arg ) > 1 );
my $id = ( defined($arg) ? $arg : 0 ); my $id = ( defined($arg) ? $arg : 0 );
$endpoint = 'callback/remove';
$param = '{"param":"' . $id . '"}';
}
elsif ( lc($cmd) eq 'configauth' ) {
return 'usage: configAuth' if ( split( m{\s+}xms, $arg ) > 1 );
Write( $hash, 'callback/remove', '{"param":"' . $id . '"}' ) my $configAuth = 'enable=' . ( $arg eq 'enable' ? 1 : 0 );
if ( !::IsDisabled($name) ); $endpoint = 'configAuth';
$param = '{"param":"' . $configAuth . '"}';
return;
} }
else { else {
my $list = ''; my $list = '';
$list .= 'info:noArg getDeviceList:noArg '; $list .= 'info:noArg getDeviceList:noArg ';
$list .= 'clearLog:noArg fwUpdate:noArg reboot:noArg factoryReset:noArg' $list .=
'clearLog:noArg fwUpdate:noArg reboot:noArg factoryReset:noArg configAuth:enable,disable'
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 ) Write( $hash, $endpoint, $param )
if ( !::IsDisabled($name) ); if ( !::IsDisabled($name) );
return; return;
@ -529,6 +531,9 @@ sub FirstRun {
if ( !::IsDisabled($name) ); if ( !::IsDisabled($name) );
$hash->{helper}->{runInfo} = 0; $hash->{helper}->{runInfo} = 0;
::readingsSingleUpdate( $hash, 'configAuthSuccess', 'unknown', 0 )
if ( ::ReadingsVal( $name, 'configAuthSuccess', 'none' ) eq 'none' );
return ::InternalTimer( ::gettimeofday() + 5, return ::InternalTimer( ::gettimeofday() + 5,
\&FHEM::Devices::Nuki::Bridge::GetCheckBridgeAlive, $hash ); \&FHEM::Devices::Nuki::Bridge::GetCheckBridgeAlive, $hash );
} }
@ -597,6 +602,10 @@ sub CreateUri {
&& $deviceType == 2 ); && $deviceType == 2 );
} }
$uri .= '&' . $param
if ( defined($param)
&& $endpoint eq 'configAuth' );
$uri .= '&id=' . $param $uri .= '&id=' . $param
if ( defined($param) if ( defined($param)
&& $endpoint eq 'callback/remove' ); && $endpoint eq 'callback/remove' );
@ -906,11 +915,14 @@ sub ResponseProcessing {
} }
} }
WriteReadings( $hash, $decode_json ) WriteReadings( $hash, $decode_json, $endpoint )
if ( $endpoint eq 'info' ); if ( $endpoint eq 'info' );
return; return;
} }
elsif ( $endpoint eq 'configAuth' ) {
WriteReadings( $hash, $decode_json, $endpoint );
}
else { else {
return ::Log3( $name, 5, return ::Log3( $name, 5,
@ -979,6 +991,7 @@ sub CGI() {
sub WriteReadings { sub WriteReadings {
my $hash = shift; my $hash = shift;
my $decode_json = shift; my $decode_json = shift;
my $endpoint = shift;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
@ -989,6 +1002,12 @@ sub WriteReadings {
my $dhash; my $dhash;
::readingsBeginUpdate($hash); ::readingsBeginUpdate($hash);
if ( $endpoint eq 'configAuth' ) {
::readingsBulkUpdate( $hash, 'configAuthSuccess',
$decode_json->{success} );
}
else {
::readingsBulkUpdate( $hash, 'appVersion', ::readingsBulkUpdate( $hash, 'appVersion',
$decode_json->{versions}->{appVersion} ); $decode_json->{versions}->{appVersion} );
::readingsBulkUpdate( $hash, 'firmwareVersion', ::readingsBulkUpdate( $hash, 'firmwareVersion',
@ -999,15 +1018,18 @@ sub WriteReadings {
$bridgeType{ $decode_json->{bridgeType} } ); $bridgeType{ $decode_json->{bridgeType} } );
::readingsBulkUpdate( $hash, 'hardwareId', ::readingsBulkUpdate( $hash, 'hardwareId',
$decode_json->{ids}{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, 'currentGMTime', $decode_json->{currentTime} ); ::readingsBulkUpdate( $hash, 'currentGMTime',
$decode_json->{currentTime} );
::readingsBulkUpdate( $hash, 'serverConnected', ::readingsBulkUpdate( $hash, 'serverConnected',
$decode_json->{serverConnected} ); $decode_json->{serverConnected} );
::readingsBulkUpdate( $hash, 'wlanConnected', ::readingsBulkUpdate( $hash, 'wlanConnected',
$decode_json->{wlanConnected} ); $decode_json->{wlanConnected} );
::readingsEndUpdate( $hash, 1 ); }
::readingsEndUpdate( $hash, 1 );
return; return;
} }

View File

@ -113,7 +113,6 @@ my %deviceTypes = (
my %deviceTypeIds = reverse(%deviceTypes); my %deviceTypeIds = reverse(%deviceTypes);
my %modes = ( my %modes = (
2 => { 2 => {
0 => 'door mode', 0 => 'door mode',
@ -191,7 +190,6 @@ my %doorsensorStates = (
5 => 'calibrating' 5 => 'calibrating'
); );
sub Define { sub Define {
my $hash = shift; my $hash = shift;
my $def = shift // return; my $def = shift // return;
@ -215,7 +213,6 @@ sub Define {
$hash->{STATE} = 'Initialized'; $hash->{STATE} = 'Initialized';
$hash->{NOTIFYDEV} = 'global,autocreate,' . $name; $hash->{NOTIFYDEV} = 'global,autocreate,' . $name;
my $iodev = ::AttrVal( $name, 'IODev', 'none' ); my $iodev = ::AttrVal( $name, 'IODev', 'none' );
::AssignIoPort( $hash, $iodev ) if ( !$hash->{IODev} ); ::AssignIoPort( $hash, $iodev ) if ( !$hash->{IODev} );
@ -558,7 +555,6 @@ sub WriteReadings {
&& $t ne 'doorsensorState' && $t ne 'doorsensorState'
&& $t ne 'doorsensorStateName' ); && $t ne 'doorsensorStateName' );
::readingsBulkUpdate( ::readingsBulkUpdate(
$hash, $t, $hash, $t,
( (