From 4489744f90fa7a18e99920d1f8acd5858617f727 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Sat, 27 Nov 2021 23:34:28 +0100 Subject: [PATCH 1/2] add configAuth option enable/disable publication of the local IP and port via discovery URL --- controls_NukiSmart.txt | 2 +- lib/FHEM/Devices/Nuki/Bridge.pm | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/controls_NukiSmart.txt b/controls_NukiSmart.txt index bb62667..0d0665b 100644 --- a/controls_NukiSmart.txt +++ b/controls_NukiSmart.txt @@ -1,4 +1,4 @@ UPD 2021-11-27_22:52:03 9217 FHEM/73_NUKIBridge.pm UPD 2021-11-27_21:36:27 7569 FHEM/74_NUKIDevice.pm -UPD 2021-11-27_22:52:20 40367 lib/FHEM/Devices/Nuki/Bridge.pm +UPD 2021-11-27_23:33:54 40749 lib/FHEM/Devices/Nuki/Bridge.pm UPD 2021-11-27_22:56:00 15826 lib/FHEM/Devices/Nuki/Device.pm diff --git a/lib/FHEM/Devices/Nuki/Bridge.pm b/lib/FHEM/Devices/Nuki/Bridge.pm index 32c24cb..9980924 100644 --- a/lib/FHEM/Devices/Nuki/Bridge.pm +++ b/lib/FHEM/Devices/Nuki/Bridge.pm @@ -411,6 +411,8 @@ sub Set { my $arg = shift // ''; my $endpoint; + my $param; + if ( lc($cmd) eq 'getdevicelist' ) { return 'usage: getDeviceList' if ($arg); @@ -441,21 +443,25 @@ sub Set { return 'usage: callbackRemove' if ( split( m{\s+}xms, $arg ) > 1 ); 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 . '"}' ) - if ( !::IsDisabled($name) ); - - return; + my $configAuth = 'enable=' . ($arg eq 'enable' ? 1 : 0); + $endpoint = 'configAuth'; + $param = '{"param":"' . $configAuth . '"}'; } else { my $list = ''; $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' ); return ( 'Unknown argument ' . $cmd . ', choose one of ' . $list ); } - Write( $hash, $endpoint, undef ) + Write( $hash, $endpoint, $param ) if ( !::IsDisabled($name) ); return; @@ -596,6 +602,10 @@ sub CreateUri { if ( $endpoint ne 'callback/add' && $deviceType == 2 ); } + + $uri .= '&' . $param + if ( defined($param) + && $endpoint eq 'configAuth' ); $uri .= '&id=' . $param if ( defined($param) -- 2.45.2 From 99fcb221d82ad4d22db6af9857ffcb4245d78196 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Sun, 28 Nov 2021 00:31:39 +0100 Subject: [PATCH 2/2] fix little bugs --- controls_NukiSmart.txt | 8 ++-- lib/FHEM/Devices/Nuki/Bridge.pm | 74 +++++++++++++++++++-------------- lib/FHEM/Devices/Nuki/Device.pm | 8 +--- 3 files changed, 49 insertions(+), 41 deletions(-) diff --git a/controls_NukiSmart.txt b/controls_NukiSmart.txt index 0d0665b..f4d09fe 100644 --- a/controls_NukiSmart.txt +++ b/controls_NukiSmart.txt @@ -1,4 +1,4 @@ -UPD 2021-11-27_22:52:03 9217 FHEM/73_NUKIBridge.pm -UPD 2021-11-27_21:36:27 7569 FHEM/74_NUKIDevice.pm -UPD 2021-11-27_23:33:54 40749 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:29:42 9217 FHEM/73_NUKIBridge.pm +UPD 2021-11-28_00:29:54 7569 FHEM/74_NUKIDevice.pm +UPD 2021-11-28_00:30:36 41129 lib/FHEM/Devices/Nuki/Bridge.pm +UPD 2021-11-28_00:30:50 15802 lib/FHEM/Devices/Nuki/Device.pm diff --git a/lib/FHEM/Devices/Nuki/Bridge.pm b/lib/FHEM/Devices/Nuki/Bridge.pm index 9980924..a224cbb 100644 --- a/lib/FHEM/Devices/Nuki/Bridge.pm +++ b/lib/FHEM/Devices/Nuki/Bridge.pm @@ -146,10 +146,6 @@ sub Define { my ( $name, undef, $host, $token ) = split( m{\s+}xms, $def ); - # return ('too few parameters: define NUKIBridge ') - # if ( !defined($host) - # || !defined($token) ); - my $port = ::AttrVal( $name, 'port', 8080 ); my $infix = 'NUKIBridge'; $hash->{HOST} = $host // 'discover'; @@ -413,7 +409,6 @@ sub Set { my $endpoint; my $param; - if ( lc($cmd) eq 'getdevicelist' ) { return 'usage: getDeviceList' if ($arg); $endpoint = 'list'; @@ -443,20 +438,21 @@ sub Set { return 'usage: callbackRemove' if ( split( m{\s+}xms, $arg ) > 1 ); my $id = ( defined($arg) ? $arg : 0 ); - $endpoint = 'callback/remove'; - $param = '{"param":"' . $id . '"}'; + $endpoint = 'callback/remove'; + $param = '{"param":"' . $id . '"}'; } elsif ( lc($cmd) eq 'configauth' ) { return 'usage: configAuth' if ( split( m{\s+}xms, $arg ) > 1 ); - my $configAuth = 'enable=' . ($arg eq 'enable' ? 1 : 0); - $endpoint = 'configAuth'; - $param = '{"param":"' . $configAuth . '"}'; + my $configAuth = 'enable=' . ( $arg eq 'enable' ? 1 : 0 ); + $endpoint = 'configAuth'; + $param = '{"param":"' . $configAuth . '"}'; } else { my $list = ''; $list .= 'info:noArg getDeviceList:noArg '; - $list .= 'clearLog:noArg fwUpdate:noArg reboot:noArg factoryReset:noArg configAuth:enable,disable' + $list .= +'clearLog:noArg fwUpdate:noArg reboot:noArg factoryReset:noArg configAuth:enable,disable' if ( ::ReadingsVal( $name, 'bridgeType', 'Software' ) eq 'Hardware' ); return ( 'Unknown argument ' . $cmd . ', choose one of ' . $list ); } @@ -535,6 +531,9 @@ sub FirstRun { if ( !::IsDisabled($name) ); $hash->{helper}->{runInfo} = 0; + ::readingsSingleUpdate( $hash, 'configAuthSuccess', 'unknown', 0 ) + if ( ::ReadingsVal( $name, 'configAuthSuccess', 'none' ) eq 'none' ); + return ::InternalTimer( ::gettimeofday() + 5, \&FHEM::Devices::Nuki::Bridge::GetCheckBridgeAlive, $hash ); } @@ -602,7 +601,7 @@ sub CreateUri { if ( $endpoint ne 'callback/add' && $deviceType == 2 ); } - + $uri .= '&' . $param if ( defined($param) && $endpoint eq 'configAuth' ); @@ -916,11 +915,14 @@ sub ResponseProcessing { } } - WriteReadings( $hash, $decode_json ) + WriteReadings( $hash, $decode_json, $endpoint ) if ( $endpoint eq 'info' ); return; } + elsif ( $endpoint eq 'configAuth' ) { + WriteReadings( $hash, $decode_json, $endpoint ); + } else { return ::Log3( $name, 5, @@ -989,6 +991,7 @@ sub CGI() { sub WriteReadings { my $hash = shift; my $decode_json = shift; + my $endpoint = shift; my $name = $hash->{NAME}; @@ -999,25 +1002,34 @@ sub WriteReadings { my $dhash; ::readingsBeginUpdate($hash); - ::readingsBulkUpdate( $hash, 'appVersion', - $decode_json->{versions}->{appVersion} ); - ::readingsBulkUpdate( $hash, 'firmwareVersion', - $decode_json->{versions}->{firmwareVersion} ); - ::readingsBulkUpdate( $hash, 'wifiFirmwareVersion', - $decode_json->{versions}->{wifiFirmwareVersion} ); - ::readingsBulkUpdate( $hash, 'bridgeType', - $bridgeType{ $decode_json->{bridgeType} } ); - ::readingsBulkUpdate( $hash, 'hardwareId', - $decode_json->{ids}{hardwareId} ); - ::readingsBulkUpdate( $hash, 'serverId', $decode_json->{ids}{serverId} ); - ::readingsBulkUpdate( $hash, 'uptime', $decode_json->{uptime} ); - ::readingsBulkUpdate( $hash, 'currentGMTime', $decode_json->{currentTime} ); - ::readingsBulkUpdate( $hash, 'serverConnected', - $decode_json->{serverConnected} ); - ::readingsBulkUpdate( $hash, 'wlanConnected', - $decode_json->{wlanConnected} ); - ::readingsEndUpdate( $hash, 1 ); + if ( $endpoint eq 'configAuth' ) { + ::readingsBulkUpdate( $hash, 'configAuthSuccess', + $decode_json->{success} ); + } + else { + ::readingsBulkUpdate( $hash, 'appVersion', + $decode_json->{versions}->{appVersion} ); + ::readingsBulkUpdate( $hash, 'firmwareVersion', + $decode_json->{versions}->{firmwareVersion} ); + ::readingsBulkUpdate( $hash, 'wifiFirmwareVersion', + $decode_json->{versions}->{wifiFirmwareVersion} ); + ::readingsBulkUpdate( $hash, 'bridgeType', + $bridgeType{ $decode_json->{bridgeType} } ); + ::readingsBulkUpdate( $hash, 'hardwareId', + $decode_json->{ids}{hardwareId} ); + ::readingsBulkUpdate( $hash, 'serverId', + $decode_json->{ids}{serverId} ); + ::readingsBulkUpdate( $hash, 'uptime', $decode_json->{uptime} ); + ::readingsBulkUpdate( $hash, 'currentGMTime', + $decode_json->{currentTime} ); + ::readingsBulkUpdate( $hash, 'serverConnected', + $decode_json->{serverConnected} ); + ::readingsBulkUpdate( $hash, 'wlanConnected', + $decode_json->{wlanConnected} ); + } + + ::readingsEndUpdate( $hash, 1 ); return; } diff --git a/lib/FHEM/Devices/Nuki/Device.pm b/lib/FHEM/Devices/Nuki/Device.pm index c171db2..1a20598 100644 --- a/lib/FHEM/Devices/Nuki/Device.pm +++ b/lib/FHEM/Devices/Nuki/Device.pm @@ -113,7 +113,6 @@ my %deviceTypes = ( my %deviceTypeIds = reverse(%deviceTypes); - my %modes = ( 2 => { 0 => 'door mode', @@ -191,7 +190,6 @@ my %doorsensorStates = ( 5 => 'calibrating' ); - sub Define { my $hash = shift; my $def = shift // return; @@ -215,7 +213,6 @@ sub Define { $hash->{STATE} = 'Initialized'; $hash->{NOTIFYDEV} = 'global,autocreate,' . $name; - my $iodev = ::AttrVal( $name, 'IODev', 'none' ); ::AssignIoPort( $hash, $iodev ) if ( !$hash->{IODev} ); @@ -558,7 +555,6 @@ sub WriteReadings { && $t ne 'doorsensorState' && $t ne 'doorsensorStateName' ); - ::readingsBulkUpdate( $hash, $t, ( @@ -573,13 +569,13 @@ sub WriteReadings { ::readingsBulkUpdate( $hash, $t, $deviceTypes{$v} ) if ( $t eq 'deviceType' ); - + ::readingsBulkUpdate( $hash, $t, $doorsensorStates{$v} ) if ( $t eq 'doorsensorState' ); ::readingsBulkUpdate( $hash, $t, ( $v == 1 ? 'true' : 'false' ) ) if ( $t eq 'paired' ); - + ::readingsBulkUpdate( $hash, $t, ( $v == 1 ? 'true' : 'false' ) ) if ( $t eq 'batteryCharging' ); -- 2.45.2