1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-06 21:32:21 +01:00

Add GPIO Switch interlock wait time (#777)

* Add interlock wait time to gpio switch

Fixes https://github.com/esphome/issues/issues/753

* Format

* Fix
This commit is contained in:
Otto Winter
2019-10-20 18:10:14 +02:00
committed by GitHub
parent 9a152e588e
commit f1e00f8c8e
3 changed files with 22 additions and 1 deletions

View File

@@ -69,13 +69,29 @@ void GPIOSwitch::dump_config() {
void GPIOSwitch::write_state(bool state) {
if (state != this->inverted_) {
// Turning ON, check interlocking
bool found = false;
for (auto *lock : this->interlock_) {
if (lock == this)
continue;
if (lock->state)
if (lock->state) {
lock->turn_off();
found = true;
}
}
if (found && this->interlock_wait_time_ != 0) {
this->set_timeout("interlock", 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);
});
return;
}
} 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->pin_->digital_write(state);