Refactor command handler return logic for clarity

Improved the command handler functions within the Nuki Bridge module
by standardizing return statements for consistency. Each command now
immediately returns after assigning its respective endpoint, ensuring
clearer control flow. This change simplifies the readability of the
code and ensures that all command handlers consistently exit without
proceeding further when their conditions are met.

Additionally, unnecessary checks for the endpoint were removed,
streamlining the handling of responses. These adjustments should help
reduce confusion and make future modifications easier, without
introducing any breaking changes.
This commit is contained in:
2025-10-16 19:50:36 +02:00
parent feb1e1fdd5
commit 728319d81e
2 changed files with 16 additions and 10 deletions

View File

@@ -1,4 +1,4 @@
UPD 2025-10-16_18:36:43 10358 FHEM/73_NUKIBridge.pm
UPD 2025-10-16_18:43:02 10358 FHEM/73_NUKIBridge.pm
UPD 2025-10-15_06:55:14 11100 FHEM/74_NUKIDevice.pm
UPD 2025-10-16_18:34:25 42928 lib/FHEM/Devices/Nuki/Bridge.pm
UPD 2025-10-16_19:50:02 43040 lib/FHEM/Devices/Nuki/Bridge.pm
UPD 2025-10-15_06:55:14 16775 lib/FHEM/Devices/Nuki/Device.pm

View File

@@ -429,49 +429,55 @@ sub Set {
getdevicelist => sub {
return 'usage: getDeviceList' if $arg;
$endpoint = 'list';
return;
},
info => sub {
return 'usage: info' if $arg;
$endpoint = 'info';
return;
},
fwupdate => sub {
return 'usage: fwUpdate' if $arg;
$endpoint = 'fwupdate';
return;
},
reboot => sub {
return 'usage: reboot' if $arg;
$endpoint = 'reboot';
return;
},
clearlog => sub {
return 'usage: clearLog' if $arg;
$endpoint = 'clearlog';
return;
},
factoryreset => sub {
return 'usage: factoryReset' if $arg;
$endpoint = 'factoryreset';
return;
},
callbackremove => sub {
return 'usage: callbackRemove'
if ( split( m{\s+}xms, $arg ) > 1 );
my $id = defined $arg ? $arg : 0;
$param = '{"param":"' . $id . '"}';
$endpoint = 'callback/remove';
$param = '{"param":"' . $id . '"}';
return;
},
configauth => sub {
return 'usage: configAuth'
if ( split( m{\s+}xms, $arg ) > 1 );
my $configAuth = 'enable=' . ( $arg eq 'enable' ? 1 : 0 );
$param = '{"param":"' . $configAuth . '"}';
$endpoint = 'configAuth';
$param = '{"param":"' . $configAuth . '"}';
return;
},
);
if ( exists $handlers{$cmd} ) {
my $result = $handlers{$cmd}->();
return $result
if defined $result
&& length $result
&& $result ne $endpoint;
if defined $result && length $result;
}
else {
my $list = 'info:noArg getDeviceList:noArg ';
@@ -501,19 +507,19 @@ sub Get {
logfile => sub {
return 'usage: logFile' if defined $arg;
$endpoint = 'log';
return;
},
callbacklist => sub {
return 'usage: callbackList' if defined $arg;
$endpoint = 'callback/list';
return;
},
);
if ( exists $handlers{$cmd} ) {
my $result = $handlers{$cmd}->();
return $result
if defined $result
&& length $result
&& $result ne $endpoint;
if defined $result && length $result;
}
else {
my $list = 'callbackList:noArg ';