From 04bcc5c879f9a220c58ff311649fe66665f6024e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 17 Jun 2025 13:02:00 +0200 Subject: [PATCH] Avoid polling for GPIO binary sensors when possible --- esphome/components/gpio/binary_sensor/__init__.py | 2 +- esphome/components/gpio/binary_sensor/gpio_binary_sensor.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/esphome/components/gpio/binary_sensor/__init__.py b/esphome/components/gpio/binary_sensor/__init__.py index 2e5502164e..ddcb1c31fb 100644 --- a/esphome/components/gpio/binary_sensor/__init__.py +++ b/esphome/components/gpio/binary_sensor/__init__.py @@ -41,6 +41,6 @@ async def to_code(config): pin = await cg.gpio_pin_expression(config[CONF_PIN]) cg.add(var.set_pin(pin)) + cg.add(var.set_use_interrupt(config[CONF_USE_INTERRUPT])) if config[CONF_USE_INTERRUPT]: - cg.add(var.set_use_interrupt(True)) cg.add(var.set_interrupt_type(INTERRUPT_TYPES[config[CONF_INTERRUPT_TYPE]])) diff --git a/esphome/components/gpio/binary_sensor/gpio_binary_sensor.h b/esphome/components/gpio/binary_sensor/gpio_binary_sensor.h index b7fd219d25..0c10cdd8b1 100644 --- a/esphome/components/gpio/binary_sensor/gpio_binary_sensor.h +++ b/esphome/components/gpio/binary_sensor/gpio_binary_sensor.h @@ -2,6 +2,7 @@ #include "esphome/core/component.h" #include "esphome/core/hal.h" +#include "esphome/core/helpers.h" #include "esphome/components/binary_sensor/binary_sensor.h" namespace esphome { @@ -37,7 +38,7 @@ class GPIOBinarySensorStore { class GPIOBinarySensor : public binary_sensor::BinarySensor, public Component { public: - ~GPIOBinarySensor() override; + ~GPIOBinarySensor(); void set_pin(GPIOPin *pin) { pin_ = pin; } void set_use_interrupt(bool use_interrupt) { use_interrupt_ = use_interrupt; }