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:13:58 +02:00
parent 04bcc5c879
commit 5d2f454a94

View File

@@ -19,11 +19,12 @@ void GPIOBinarySensorStore::setup(InternalGPIOPin *pin, gpio::InterruptType type
this->pin_ = pin;
pin->setup();
this->isr_pin_ = pin->to_isr();
{
InterruptLock lock;
this->last_state_ = pin->digital_read();
this->state_ = this->last_state_;
}
// Read initial state
this->last_state_ = pin->digital_read();
this->state_ = this->last_state_;
// Attach interrupt - from this point on, any changes will be caught by the interrupt
pin->attach_interrupt(&GPIOBinarySensorStore::gpio_intr, this, type);
}