Execute a direction change instead of a stop command, when any of the obstacle sensors are triggered, to keep 'direction_change_waittime' functionality together with 'obstacle_rollback'

This commit is contained in:
xX7 2024-09-24 23:15:53 +02:00
parent cc53eb42b2
commit 9ebd89dcea

View file

@ -188,12 +188,13 @@ void FeedbackCover::set_close_obstacle_sensor(binary_sensor::BinarySensor *close
close_obstacle->add_on_state_callback([this](bool state) { close_obstacle->add_on_state_callback([this](bool state) {
if (state && (this->current_operation == COVER_OPERATION_CLOSING || if (state && (this->current_operation == COVER_OPERATION_CLOSING ||
this->current_trigger_operation_ == COVER_OPERATION_CLOSING)) { this->current_trigger_operation_ == COVER_OPERATION_CLOSING)) {
ESP_LOGD(TAG, "'%s' - Close obstacle detected.", this->name_.c_str()); ESP_LOGD(TAG, "'%s' - Obstacle collision detected while closing.", this->name_.c_str());
this->start_direction_(COVER_OPERATION_IDLE);
if (this->obstacle_rollback_) { if (this->obstacle_rollback_) {
this->target_position_ = clamp(this->position + this->obstacle_rollback_, COVER_CLOSED, COVER_OPEN); this->target_position_ = clamp(this->position + this->obstacle_rollback_, COVER_CLOSED, COVER_OPEN);
this->start_direction_(COVER_OPERATION_OPENING); this->start_direction_(COVER_OPERATION_OPENING);
} else {
this->start_direction_(COVER_OPERATION_IDLE);
} }
} }
}); });
@ -205,12 +206,13 @@ void FeedbackCover::set_open_obstacle_sensor(binary_sensor::BinarySensor *open_o
open_obstacle->add_on_state_callback([this](bool state) { open_obstacle->add_on_state_callback([this](bool state) {
if (state && (this->current_operation == COVER_OPERATION_OPENING || if (state && (this->current_operation == COVER_OPERATION_OPENING ||
this->current_trigger_operation_ == COVER_OPERATION_OPENING)) { this->current_trigger_operation_ == COVER_OPERATION_OPENING)) {
ESP_LOGD(TAG, "'%s' - Open obstacle detected.", this->name_.c_str()); ESP_LOGD(TAG, "'%s' - Obstacle collision detected while opening.", this->name_.c_str());
this->start_direction_(COVER_OPERATION_IDLE);
if (this->obstacle_rollback_) { if (this->obstacle_rollback_) {
this->target_position_ = clamp(this->position - this->obstacle_rollback_, COVER_CLOSED, COVER_OPEN); this->target_position_ = clamp(this->position - this->obstacle_rollback_, COVER_CLOSED, COVER_OPEN);
this->start_direction_(COVER_OPERATION_CLOSING); this->start_direction_(COVER_OPERATION_CLOSING);
} else {
this->start_direction_(COVER_OPERATION_IDLE);
} }
} }
}); });