From a7d9152204d51251852a8107dfb17e726bc6d2dd Mon Sep 17 00:00:00 2001 From: klaudiusz223 Date: Mon, 6 Feb 2023 19:39:55 +0100 Subject: [PATCH] Fixing a bug when issuing the stop command just after the start (between the transition from STATE_IDLE to STATE_MOVING). Now the STOP command always stops the cover even during recalibration. --- .../time_based_tilt/time_based_tilt_cover.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/esphome/components/time_based_tilt/time_based_tilt_cover.cpp b/esphome/components/time_based_tilt/time_based_tilt_cover.cpp index 00b96bc77d..a40316d176 100644 --- a/esphome/components/time_based_tilt/time_based_tilt_cover.cpp +++ b/esphome/components/time_based_tilt/time_based_tilt_cover.cpp @@ -72,8 +72,12 @@ void TimeBasedTiltCover::loop() { if ( this->fsm_state_ == STATE_STOPPING ) { this->stop_trigger_->trigger(); - this->interlocked_time = millis(); - this->interlocked_direction = this->current_operation == COVER_OPERATION_CLOSING ? COVER_OPERATION_OPENING : COVER_OPERATION_CLOSING; + if (this->current_operation != COVER_OPERATION_IDLE){ + this->interlocked_time = millis(); + this->interlocked_direction = this->current_operation == COVER_OPERATION_CLOSING ? COVER_OPERATION_OPENING : COVER_OPERATION_CLOSING; + } else { + this->interlocked_direction = COVER_OPERATION_IDLE; + } this->fsm_state_ = STATE_IDLE; this->last_operation_ = this->current_operation; this->current_operation = COVER_OPERATION_IDLE; @@ -200,9 +204,7 @@ void TimeBasedTiltCover::control(const CoverCall &call) { if (call.get_stop()) { this->target_position_ = TARGET_NONE; this->target_tilt_= TARGET_NONE; - if (this->fsm_state_ == STATE_MOVING) { - this->fsm_state_ = STATE_STOPPING; - } + this->fsm_state_ = STATE_STOPPING; return; } if (call.get_position().has_value() && call.get_tilt().has_value() ) {