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:
@@ -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 ';
|
||||
|
||||
Reference in New Issue
Block a user