mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-25 07:08:30 +02:00
add time based cover, has built in endstop (#665)
* add has built in endstop * rewrite as proposed * Update esphome/components/time_based/time_based_cover.h Co-Authored-By: Otto Winter <otto@otto-winter.com> * lint * Re trigger stop_operation if stop called * allow se triggering open/close command if safe * using COVER_OPEN/CLOSE constants
This commit is contained in:
committed by
Otto Winter
parent
d27291b997
commit
83a92f03fc
@@ -30,13 +30,18 @@ void TimeBasedCover::loop() {
|
||||
// Recompute position every loop cycle
|
||||
this->recompute_position_();
|
||||
|
||||
if (this->current_operation != COVER_OPERATION_IDLE && this->is_at_target_()) {
|
||||
this->start_direction_(COVER_OPERATION_IDLE);
|
||||
if (this->is_at_target_()) {
|
||||
if (this->has_built_in_endstop_ && (this->target_position_ == COVER_OPEN || this->target_position_ == COVER_CLOSED)) {
|
||||
// Don't trigger stop, let the cover stop by itself.
|
||||
this->current_operation = COVER_OPERATION_IDLE;
|
||||
} else {
|
||||
this->start_direction_(COVER_OPERATION_IDLE);
|
||||
}
|
||||
this->publish_state();
|
||||
}
|
||||
|
||||
// Send current position every second
|
||||
if (this->current_operation != COVER_OPERATION_IDLE && now - this->last_publish_time_ > 1000) {
|
||||
if (now - this->last_publish_time_ > 1000) {
|
||||
this->publish_state(false);
|
||||
this->last_publish_time_ = now;
|
||||
}
|
||||
@@ -57,6 +62,12 @@ void TimeBasedCover::control(const CoverCall &call) {
|
||||
auto pos = *call.get_position();
|
||||
if (pos == this->position) {
|
||||
// already at target
|
||||
// for covers with built in end stop, we should send the command again
|
||||
if (this->has_built_in_endstop_ && (pos == COVER_OPEN || pos == COVER_CLOSED)) {
|
||||
auto op = pos == COVER_CLOSED ? COVER_OPERATION_CLOSING : COVER_OPERATION_OPENING;
|
||||
this->target_position_ = pos;
|
||||
this->start_direction_(op);
|
||||
}
|
||||
} else {
|
||||
auto op = pos < this->position ? COVER_OPERATION_CLOSING : COVER_OPERATION_OPENING;
|
||||
this->target_position_ = pos;
|
||||
@@ -82,7 +93,7 @@ bool TimeBasedCover::is_at_target_() const {
|
||||
}
|
||||
}
|
||||
void TimeBasedCover::start_direction_(CoverOperation dir) {
|
||||
if (dir == this->current_operation)
|
||||
if (dir == this->current_operation && dir != COVER_OPERATION_IDLE)
|
||||
return;
|
||||
|
||||
this->recompute_position_();
|
||||
|
||||
Reference in New Issue
Block a user