From b6cad9a94fe3a2ccad0bc63aeb7068692b133f1a Mon Sep 17 00:00:00 2001 From: Alvin Schiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Wed, 24 Apr 2024 00:35:30 +0200 Subject: [PATCH] simplify holdMode callback handling --- .../gpio_control/GPIODevices/simple_button.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/components/gpio_control/GPIODevices/simple_button.py b/components/gpio_control/GPIODevices/simple_button.py index 1256dc7cb..3055a15a5 100644 --- a/components/gpio_control/GPIODevices/simple_button.py +++ b/components/gpio_control/GPIODevices/simple_button.py @@ -106,11 +106,7 @@ def callbackFunctionHandler(self, *args): if inval != GPIO.LOW: return None - if self.hold_mode in ('Repeat', 'Postpone', 'SecondFunc', 'SecondFuncRepeat'): - return self.longPressHandler(*args) - else: - logger.info('{}: execute callback'.format(self.name)) - return self.when_pressed(*args) + return self._handleCallbackFunction(*args) @property def when_pressed(self): @@ -136,8 +132,8 @@ def when_pressed(self, func): def set_callbackFunction(self, callbackFunction): self.when_pressed = callbackFunction - def longPressHandler(self, *args): - logger.info('{}: longPressHandler, mode: {}'.format(self.name, self.hold_mode)) + def _handleCallbackFunction(self, *args): + logger.info('{}: handleCallbackFunction, mode: {}'.format(self.name, self.hold_mode)) # action(s) after hold_time if self.hold_mode == "Repeat": @@ -173,6 +169,9 @@ def longPressHandler(self, *args): while checkGpioStaysInState(self.hold_time, self.pin, GPIO.LOW): self.when_held(*args) + else: + self.when_pressed(*args) + def __del__(self): logger.debug('remove event detection') GPIO.remove_event_detect(self.pin)