[gpio] Use constexpr uint32_t timer ID for interlock timeout

Replace string-based timeout ID "interlock" with a constexpr
uint32_t, saving 12 bytes of RAM on ESP8266 and avoiding the
string hash lookup.
This commit is contained in:
J. Nick Koston
2026-03-19 23:57:50 -10:00
parent d59c006ff9
commit b51d6165df
@@ -5,6 +5,7 @@ namespace esphome {
namespace gpio {
static const char *const TAG = "switch.gpio";
static constexpr uint32_t INTERLOCK_TIMEOUT_ID = 0;
float GPIOSwitch::get_setup_priority() const { return setup_priority::HARDWARE; }
void GPIOSwitch::setup() {
@@ -51,7 +52,7 @@ void GPIOSwitch::write_state(bool state) {
}
}
if (found && this->interlock_wait_time_ != 0) {
this->set_timeout("interlock", this->interlock_wait_time_, [this, state] {
this->set_timeout(INTERLOCK_TIMEOUT_ID, this->interlock_wait_time_, [this, state] {
// Don't write directly, call the function again
// (some other switch may have changed state while we were waiting)
this->write_state(state);
@@ -61,7 +62,7 @@ void GPIOSwitch::write_state(bool state) {
} else if (this->interlock_wait_time_ != 0) {
// If we are switched off during the interlock wait time, cancel any pending
// re-activations
this->cancel_timeout("interlock");
this->cancel_timeout(INTERLOCK_TIMEOUT_ID);
}
this->pin_->digital_write(state);