1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-14 17:22:20 +01:00

Avoid polling for GPIO binary sensors when possible

This commit is contained in:
J. Nick Koston
2025-06-17 13:02:00 +02:00
parent d4db16665f
commit 04bcc5c879
2 changed files with 3 additions and 2 deletions

View File

@@ -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]]))

View File

@@ -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; }