1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-16 23:05:46 +00:00

Add cover toggle support (#1809)

* Add cover toggle support

Step through open/stop/close/stop sequence with every toggle

* Move the cover toggle logic to perform()

* Add clang-tidy CI suggestion

* Implement cover toggle action as cover trait

* Handle toggle correctly if cover fully closed on POR

* Fix CI finding

* Add deprecated warning

* Don't add already deprecated interface

Co-authored-by: Oxan van Leeuwen <oxan@oxanvanleeuwen.nl>

* Don't add already deprecated interface

Co-authored-by: Oxan van Leeuwen <oxan@oxanvanleeuwen.nl>

* Don't add already deprecated interface

Co-authored-by: Oxan van Leeuwen <oxan@oxanvanleeuwen.nl>

Co-authored-by: Mueller, Daniel <daniel.mueller@karlstorz.com>
Co-authored-by: Oxan van Leeuwen <oxan@oxanvanleeuwen.nl>
This commit is contained in:
Daniel Müller
2021-09-27 22:31:15 +02:00
committed by GitHub
parent e30f17f64f
commit 2eb5f89d82
8 changed files with 70 additions and 1 deletions

View File

@@ -43,6 +43,8 @@ CoverCall &CoverCall::set_command(const char *command) {
this->set_command_close();
} else if (strcasecmp(command, "STOP") == 0) {
this->set_command_stop();
} else if (strcasecmp(command, "TOGGLE") == 0) {
this->set_command_toggle();
} else {
ESP_LOGW(TAG, "'%s' - Unrecognized command %s", this->parent_->get_name().c_str(), command);
}
@@ -60,6 +62,10 @@ CoverCall &CoverCall::set_command_stop() {
this->stop_ = true;
return *this;
}
CoverCall &CoverCall::set_command_toggle() {
this->toggle_ = true;
return *this;
}
CoverCall &CoverCall::set_position(float position) {
this->position_ = position;
return *this;
@@ -85,10 +91,14 @@ void CoverCall::perform() {
if (this->tilt_.has_value()) {
ESP_LOGD(TAG, " Tilt: %.0f%%", *this->tilt_ * 100.0f);
}
if (this->toggle_.has_value()) {
ESP_LOGD(TAG, " Command: TOGGLE");
}
this->parent_->control(*this);
}
const optional<float> &CoverCall::get_position() const { return this->position_; }
const optional<float> &CoverCall::get_tilt() const { return this->tilt_; }
const optional<bool> &CoverCall::get_toggle() const { return this->toggle_; }
void CoverCall::validate_() {
auto traits = this->parent_->get_traits();
if (this->position_.has_value()) {
@@ -111,6 +121,12 @@ void CoverCall::validate_() {
this->tilt_ = clamp(tilt, 0.0f, 1.0f);
}
}
if (this->toggle_.has_value()) {
if (!traits.get_supports_toggle()) {
ESP_LOGW(TAG, "'%s' - This cover device does not support toggle!", this->parent_->get_name().c_str());
this->toggle_.reset();
}
}
if (this->stop_) {
if (this->position_.has_value()) {
ESP_LOGW(TAG, "Cannot set position when stopping a cover!");
@@ -120,6 +136,10 @@ void CoverCall::validate_() {
ESP_LOGW(TAG, "Cannot set tilt when stopping a cover!");
this->tilt_.reset();
}
if (this->toggle_.has_value()) {
ESP_LOGW(TAG, "Cannot set toggle when stopping a cover!");
this->toggle_.reset();
}
}
}
CoverCall &CoverCall::set_stop(bool stop) {