From e8547b16f6bd5831dc6f8d5d5e07269371b0c3ad Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 17 Jun 2025 13:20:41 +0200 Subject: [PATCH] Avoid polling for GPIO binary sensors when possible --- .../components/gpio/binary_sensor/gpio_binary_sensor.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/esphome/components/gpio/binary_sensor/gpio_binary_sensor.h b/esphome/components/gpio/binary_sensor/gpio_binary_sensor.h index e517376d0f..304ba465e9 100644 --- a/esphome/components/gpio/binary_sensor/gpio_binary_sensor.h +++ b/esphome/components/gpio/binary_sensor/gpio_binary_sensor.h @@ -21,10 +21,13 @@ class GPIOBinarySensorStore { } bool has_changed() { - InterruptLock lock; - bool changed = this->changed_; + // No lock needed: single writer (ISR) / single reader (main loop) pattern + // Volatile bool operations are atomic on all ESPHome-supported platforms + if (!this->changed_) { + return false; + } this->changed_ = false; - return changed; + return true; } protected: