mirror of
https://github.com/esphome/esphome.git
synced 2024-12-25 15:04:54 +01:00
Add cover toggle support to endstop cover (#3358)
This commit is contained in:
parent
a2d0c1bf18
commit
9e3e34acf5
3 changed files with 20 additions and 0 deletions
|
@ -12,6 +12,7 @@ using namespace esphome::cover;
|
|||
CoverTraits EndstopCover::get_traits() {
|
||||
auto traits = CoverTraits();
|
||||
traits.set_supports_position(true);
|
||||
traits.set_supports_toggle(true);
|
||||
traits.set_is_assumed_state(false);
|
||||
return traits;
|
||||
}
|
||||
|
@ -20,6 +21,20 @@ void EndstopCover::control(const CoverCall &call) {
|
|||
this->start_direction_(COVER_OPERATION_IDLE);
|
||||
this->publish_state();
|
||||
}
|
||||
if (call.get_toggle().has_value()) {
|
||||
if (this->current_operation != COVER_OPERATION_IDLE) {
|
||||
this->start_direction_(COVER_OPERATION_IDLE);
|
||||
this->publish_state();
|
||||
} else {
|
||||
if (this->position == COVER_CLOSED || this->last_operation_ == COVER_OPERATION_CLOSING) {
|
||||
this->target_position_ = COVER_OPEN;
|
||||
this->start_direction_(COVER_OPERATION_OPENING);
|
||||
} else {
|
||||
this->target_position_ = COVER_CLOSED;
|
||||
this->start_direction_(COVER_OPERATION_CLOSING);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (call.get_position().has_value()) {
|
||||
auto pos = *call.get_position();
|
||||
if (pos == this->position) {
|
||||
|
@ -125,9 +140,11 @@ void EndstopCover::start_direction_(CoverOperation dir) {
|
|||
trig = this->stop_trigger_;
|
||||
break;
|
||||
case COVER_OPERATION_OPENING:
|
||||
this->last_operation_ = dir;
|
||||
trig = this->open_trigger_;
|
||||
break;
|
||||
case COVER_OPERATION_CLOSING:
|
||||
this->last_operation_ = dir;
|
||||
trig = this->close_trigger_;
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -51,6 +51,7 @@ class EndstopCover : public cover::Cover, public Component {
|
|||
uint32_t start_dir_time_{0};
|
||||
uint32_t last_publish_time_{0};
|
||||
float target_position_{0};
|
||||
cover::CoverOperation last_operation_{cover::COVER_OPERATION_OPENING};
|
||||
};
|
||||
|
||||
} // namespace endstop
|
||||
|
|
|
@ -795,6 +795,7 @@ binary_sensor:
|
|||
on_press:
|
||||
then:
|
||||
- cover.toggle: time_based_cover
|
||||
- cover.toggle: endstop_cover
|
||||
- platform: template
|
||||
id: 'pzemac_reset_energy'
|
||||
on_press:
|
||||
|
@ -1060,6 +1061,7 @@ climate:
|
|||
cover:
|
||||
- platform: endstop
|
||||
name: Endstop Cover
|
||||
id: endstop_cover
|
||||
stop_action:
|
||||
- switch.turn_on: gpio_switch1
|
||||
open_endstop: my_binary_sensor
|
||||
|
|
Loading…
Reference in a new issue