From 0a0c369b88fc4e70c2e1788722d7e5c99a83b485 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 17 Jun 2025 13:17:35 +0200 Subject: [PATCH] Avoid polling for GPIO binary sensors when possible --- .../gpio/binary_sensor/gpio_binary_sensor.cpp | 14 -------------- .../gpio/binary_sensor/gpio_binary_sensor.h | 4 ---- 2 files changed, 18 deletions(-) diff --git a/esphome/components/gpio/binary_sensor/gpio_binary_sensor.cpp b/esphome/components/gpio/binary_sensor/gpio_binary_sensor.cpp index ef99863845..fcb2696090 100644 --- a/esphome/components/gpio/binary_sensor/gpio_binary_sensor.cpp +++ b/esphome/components/gpio/binary_sensor/gpio_binary_sensor.cpp @@ -16,7 +16,6 @@ void IRAM_ATTR GPIOBinarySensorStore::gpio_intr(GPIOBinarySensorStore *arg) { } void GPIOBinarySensorStore::setup(InternalGPIOPin *pin, gpio::InterruptType type) { - this->pin_ = pin; pin->setup(); this->isr_pin_ = pin->to_isr(); @@ -28,19 +27,6 @@ void GPIOBinarySensorStore::setup(InternalGPIOPin *pin, gpio::InterruptType type pin->attach_interrupt(&GPIOBinarySensorStore::gpio_intr, this, type); } -void GPIOBinarySensorStore::detach() { - if (this->pin_ != nullptr) { - this->pin_->detach_interrupt(); - this->pin_ = nullptr; - } -} - -GPIOBinarySensor::~GPIOBinarySensor() { - if (this->use_interrupt_) { - this->store_.detach(); - } -} - void GPIOBinarySensor::setup() { if (this->use_interrupt_ && !this->pin_->is_internal()) { ESP_LOGW(TAG, "Interrupts not supported for this pin type, falling back to polling"); diff --git a/esphome/components/gpio/binary_sensor/gpio_binary_sensor.h b/esphome/components/gpio/binary_sensor/gpio_binary_sensor.h index 0c10cdd8b1..960fa427f4 100644 --- a/esphome/components/gpio/binary_sensor/gpio_binary_sensor.h +++ b/esphome/components/gpio/binary_sensor/gpio_binary_sensor.h @@ -12,7 +12,6 @@ namespace gpio { class GPIOBinarySensorStore { public: void setup(InternalGPIOPin *pin, gpio::InterruptType type); - void detach(); static void gpio_intr(GPIOBinarySensorStore *arg); @@ -29,7 +28,6 @@ class GPIOBinarySensorStore { } protected: - InternalGPIOPin *pin_{nullptr}; ISRInternalGPIOPin isr_pin_; volatile bool state_{false}; volatile bool last_state_{false}; @@ -38,8 +36,6 @@ class GPIOBinarySensorStore { class GPIOBinarySensor : public binary_sensor::BinarySensor, public Component { public: - ~GPIOBinarySensor(); - void set_pin(GPIOPin *pin) { pin_ = pin; } void set_use_interrupt(bool use_interrupt) { use_interrupt_ = use_interrupt; } void set_interrupt_type(gpio::InterruptType type) { interrupt_type_ = type; }