mirror of
https://github.com/esphome/esphome.git
synced 2025-01-18 20:10:55 +00:00
Add cover toggle support to endstop cover (#3358)
This commit is contained in:
parent
a2d0c1bf18
commit
9e3e34acf5
@ -12,6 +12,7 @@ using namespace esphome::cover;
|
|||||||
CoverTraits EndstopCover::get_traits() {
|
CoverTraits EndstopCover::get_traits() {
|
||||||
auto traits = CoverTraits();
|
auto traits = CoverTraits();
|
||||||
traits.set_supports_position(true);
|
traits.set_supports_position(true);
|
||||||
|
traits.set_supports_toggle(true);
|
||||||
traits.set_is_assumed_state(false);
|
traits.set_is_assumed_state(false);
|
||||||
return traits;
|
return traits;
|
||||||
}
|
}
|
||||||
@ -20,6 +21,20 @@ void EndstopCover::control(const CoverCall &call) {
|
|||||||
this->start_direction_(COVER_OPERATION_IDLE);
|
this->start_direction_(COVER_OPERATION_IDLE);
|
||||||
this->publish_state();
|
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()) {
|
if (call.get_position().has_value()) {
|
||||||
auto pos = *call.get_position();
|
auto pos = *call.get_position();
|
||||||
if (pos == this->position) {
|
if (pos == this->position) {
|
||||||
@ -125,9 +140,11 @@ void EndstopCover::start_direction_(CoverOperation dir) {
|
|||||||
trig = this->stop_trigger_;
|
trig = this->stop_trigger_;
|
||||||
break;
|
break;
|
||||||
case COVER_OPERATION_OPENING:
|
case COVER_OPERATION_OPENING:
|
||||||
|
this->last_operation_ = dir;
|
||||||
trig = this->open_trigger_;
|
trig = this->open_trigger_;
|
||||||
break;
|
break;
|
||||||
case COVER_OPERATION_CLOSING:
|
case COVER_OPERATION_CLOSING:
|
||||||
|
this->last_operation_ = dir;
|
||||||
trig = this->close_trigger_;
|
trig = this->close_trigger_;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -51,6 +51,7 @@ class EndstopCover : public cover::Cover, public Component {
|
|||||||
uint32_t start_dir_time_{0};
|
uint32_t start_dir_time_{0};
|
||||||
uint32_t last_publish_time_{0};
|
uint32_t last_publish_time_{0};
|
||||||
float target_position_{0};
|
float target_position_{0};
|
||||||
|
cover::CoverOperation last_operation_{cover::COVER_OPERATION_OPENING};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace endstop
|
} // namespace endstop
|
||||||
|
@ -795,6 +795,7 @@ binary_sensor:
|
|||||||
on_press:
|
on_press:
|
||||||
then:
|
then:
|
||||||
- cover.toggle: time_based_cover
|
- cover.toggle: time_based_cover
|
||||||
|
- cover.toggle: endstop_cover
|
||||||
- platform: template
|
- platform: template
|
||||||
id: 'pzemac_reset_energy'
|
id: 'pzemac_reset_energy'
|
||||||
on_press:
|
on_press:
|
||||||
@ -1060,6 +1061,7 @@ climate:
|
|||||||
cover:
|
cover:
|
||||||
- platform: endstop
|
- platform: endstop
|
||||||
name: Endstop Cover
|
name: Endstop Cover
|
||||||
|
id: endstop_cover
|
||||||
stop_action:
|
stop_action:
|
||||||
- switch.turn_on: gpio_switch1
|
- switch.turn_on: gpio_switch1
|
||||||
open_endstop: my_binary_sensor
|
open_endstop: my_binary_sensor
|
||||||
|
Loading…
x
Reference in New Issue
Block a user