From 728319d81efb091064b45118b489f9b89fe027a7 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Thu, 16 Oct 2025 19:50:36 +0200 Subject: [PATCH] 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. --- controls_NukiSmart.txt | 4 ++-- lib/FHEM/Devices/Nuki/Bridge.pm | 22 ++++++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/controls_NukiSmart.txt b/controls_NukiSmart.txt index 0056936..27f38ab 100644 --- a/controls_NukiSmart.txt +++ b/controls_NukiSmart.txt @@ -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 diff --git a/lib/FHEM/Devices/Nuki/Bridge.pm b/lib/FHEM/Devices/Nuki/Bridge.pm index c5e7366..5f0bdcf 100644 --- a/lib/FHEM/Devices/Nuki/Bridge.pm +++ b/lib/FHEM/Devices/Nuki/Bridge.pm @@ -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 ';