diff --git a/components/gpio_control/GPIODevices/shutdown_button.py b/components/gpio_control/GPIODevices/shutdown_button.py index 30ba26b6f..ee8cb1e98 100644 --- a/components/gpio_control/GPIODevices/shutdown_button.py +++ b/components/gpio_control/GPIODevices/shutdown_button.py @@ -34,27 +34,28 @@ def set_led(self, status): logger.debug('cannot set LED to {}: no LED pin defined'.format(status)) def callbackFunctionHandler(self, *args): - logger.debug('ShutdownButton pressed, ensuring long press for {} seconds, checking each {}s'.format( - self.hold_time, self.iteration_time - )) - t_passed = 0 - led_state = True - while t_passed < self.hold_time: - self.set_led(led_state) - time.sleep(self.iteration_time) - t_passed += self.iteration_time - led_state = not led_state - if not self.is_pressed: - break - if t_passed >= self.hold_time: - # trippel off period to indicate command accepted - self.set_led(GPIO.HIGH) - time.sleep(.6) - # leave it on for the moment, it will be off when the system is down - self.when_pressed(*args) - else: - # switch off LED if pressing was cancelled early (during flashing) - self.set_led(GPIO.LOW) + if self.is_pressed: # Should not be necessary, but handler gets called on rising edge too + logger.debug('ShutdownButton pressed, ensuring long press for {} seconds, checking each {}s'.format( + self.hold_time, self.iteration_time + )) + t_passed = 0 + led_state = True + while t_passed < self.hold_time: + self.set_led(led_state) + time.sleep(self.iteration_time) + t_passed += self.iteration_time + led_state = not led_state + if not self.is_pressed: + break + if t_passed >= self.hold_time: + # trippel off period to indicate command accepted + self.set_led(GPIO.HIGH) + time.sleep(.6) + # leave it on for the moment, it will be off when the system is down + self.when_pressed(*args) + else: + # switch off LED if pressing was cancelled early (during flashing) + self.set_led(GPIO.LOW) def __repr__(self): return ''.format(