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:
@@ -41,6 +41,6 @@ async def to_code(config):
|
|||||||
pin = await cg.gpio_pin_expression(config[CONF_PIN])
|
pin = await cg.gpio_pin_expression(config[CONF_PIN])
|
||||||
cg.add(var.set_pin(pin))
|
cg.add(var.set_pin(pin))
|
||||||
|
|
||||||
|
cg.add(var.set_use_interrupt(config[CONF_USE_INTERRUPT]))
|
||||||
if 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]]))
|
cg.add(var.set_interrupt_type(INTERRUPT_TYPES[config[CONF_INTERRUPT_TYPE]]))
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
#include "esphome/core/hal.h"
|
#include "esphome/core/hal.h"
|
||||||
|
#include "esphome/core/helpers.h"
|
||||||
#include "esphome/components/binary_sensor/binary_sensor.h"
|
#include "esphome/components/binary_sensor/binary_sensor.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
@@ -37,7 +38,7 @@ class GPIOBinarySensorStore {
|
|||||||
|
|
||||||
class GPIOBinarySensor : public binary_sensor::BinarySensor, public Component {
|
class GPIOBinarySensor : public binary_sensor::BinarySensor, public Component {
|
||||||
public:
|
public:
|
||||||
~GPIOBinarySensor() override;
|
~GPIOBinarySensor();
|
||||||
|
|
||||||
void set_pin(GPIOPin *pin) { pin_ = pin; }
|
void set_pin(GPIOPin *pin) { pin_ = pin; }
|
||||||
void set_use_interrupt(bool use_interrupt) { use_interrupt_ = use_interrupt; }
|
void set_use_interrupt(bool use_interrupt) { use_interrupt_ = use_interrupt; }
|
||||||
|
Reference in New Issue
Block a user