More robust partial door closing mechanism

This commit is contained in:
2026-05-22 22:29:54 +00:00
parent 553c6d2dcb
commit 41db350f5c
2 changed files with 30 additions and 10 deletions
+28 -10
View File
@@ -162,12 +162,18 @@ void RATGDOComponent::received(const DoorState door_state)
}
this->cancel_position_sync_callbacks();
this->cancel_timeout(TIMEOUT_DOOR_QUERY_STATE);
this->target_position_ = DOOR_POSITION_UNKNOWN;
this->target_direction_ = DoorAction::UNKNOWN;
} else if (door_state == DoorState::OPEN) {
this->door_position = 1.0;
this->cancel_position_sync_callbacks();
this->target_position_ = DOOR_POSITION_UNKNOWN;
this->target_direction_ = DoorAction::UNKNOWN;
} else if (door_state == DoorState::CLOSED) {
this->door_position = 0.0;
this->cancel_position_sync_callbacks();
this->target_position_ = DOOR_POSITION_UNKNOWN;
this->target_direction_ = DoorAction::UNKNOWN;
}
if (door_state == DoorState::CLOSED && door_state != prev_door_state) {
@@ -250,8 +256,26 @@ void RATGDOComponent::door_position_update()
return;
}
auto position = this->door_start_position + (now - this->door_start_moving) / (1000 * duration);
position = clamp(position, 0.0f, 1.0f);
ESP_LOG2(TAG, "[%d] Position update: %f", now, position);
this->door_position = clamp(position, 0.0f, 1.0f);
this->door_position = position;
// Check if we reached our move-to-position target
if (this->target_position_ != DOOR_POSITION_UNKNOWN && this->target_direction_ != DoorAction::UNKNOWN) {
bool reached = false;
if (this->target_direction_ == DoorAction::OPEN && position >= this->target_position_) {
reached = true;
} else if (this->target_direction_ == DoorAction::CLOSE && position <= this->target_position_) {
reached = true;
}
if (reached) {
ESP_LOGD(TAG, "Reached target position %.2f, stopping door", this->target_position_);
this->door_stop();
this->target_position_ = DOOR_POSITION_UNKNOWN;
this->target_direction_ = DoorAction::UNKNOWN;
}
}
}
void RATGDOComponent::set_opening_duration(float duration)
@@ -451,16 +475,10 @@ void RATGDOComponent::door_move_to_position(float position)
ESP_LOGD(TAG, "Moving to position %.2f (target duration %.1fs)", position,
operation_time / 1000.0);
// Wait for the door to actually start moving before starting the stop timer.
// This makes the timing independent of any smart fallback delays.
this->on_door_state([this, operation_time](DoorState s) {
if (s == DoorState::OPENING || s == DoorState::CLOSING) {
this->set_timeout(TIMEOUT_MOVE_TO_POSITION, operation_time,
[this] { this->door_action(DoorAction::STOP); });
}
});
this->target_position_ = position;
this->target_direction_ = (delta > 0 ? DoorAction::OPEN : DoorAction::CLOSE);
this->smart_door_action(delta > 0 ? DoorAction::OPEN : DoorAction::CLOSE);
this->smart_door_action(this->target_direction_);
}
void RATGDOComponent::cancel_position_sync_callbacks()
+2
View File
@@ -71,6 +71,8 @@ public:
float door_start_position { DOOR_POSITION_UNKNOWN };
float door_move_delta { DOOR_DELTA_UNKNOWN };
uint16_t position_sync_remaining_ { 0 };
float target_position_ { DOOR_POSITION_UNKNOWN };
DoorAction target_direction_ { DoorAction::UNKNOWN };
single_observable<LightState> light_state { LightState::UNKNOWN };
single_observable<LockState> lock_state { LockState::UNKNOWN };