8 static const char *
const TAG =
"endstop.cover";
14 traits.set_supports_stop(
true);
15 traits.set_supports_position(
true);
16 traits.set_supports_toggle(
true);
17 traits.set_is_assumed_state(
false);
23 this->publish_state();
28 this->publish_state();
45 this->target_position_ = pos;
46 this->start_direction_(op);
51 auto restore = this->restore_state_();
52 if (restore.has_value()) {
56 if (this->is_open_()) {
58 }
else if (this->is_closed_()) {
60 }
else if (!restore.has_value()) {
68 const uint32_t now =
millis();
71 float dur = (now - this->start_dir_time_) / 1e3f;
72 ESP_LOGD(TAG,
"'%s' - Open endstop reached. Took %.1fs.", this->name_.c_str(), dur);
76 this->publish_state();
78 float dur = (now - this->start_dir_time_) / 1e3f;
79 ESP_LOGD(TAG,
"'%s' - Close endstop reached. Took %.1fs.", this->name_.c_str(), dur);
83 this->publish_state();
84 }
else if (now - this->start_dir_time_ > this->max_duration_) {
85 ESP_LOGD(TAG,
"'%s' - Max duration reached. Stopping cover.", this->name_.c_str());
87 this->publish_state();
91 this->recompute_position_();
95 this->publish_state();
100 this->publish_state(
false);
101 this->last_publish_time_ = now;
105 LOG_COVER(
"",
"Endstop Cover",
this);
106 LOG_BINARY_SENSOR(
" ",
"Open Endstop", this->open_endstop_);
107 ESP_LOGCONFIG(TAG,
" Open Duration: %.1fs", this->open_duration_ / 1e3f);
108 LOG_BINARY_SENSOR(
" ",
"Close Endstop", this->close_endstop_);
109 ESP_LOGCONFIG(TAG,
" Close Duration: %.1fs", this->close_duration_ / 1e3f);
113 if (this->prev_command_trigger_ !=
nullptr) {
114 this->prev_command_trigger_->stop_action();
115 this->prev_command_trigger_ =
nullptr;
119 switch (this->current_operation) {
122 return this->is_open_();
123 return this->
position >= this->target_position_;
126 return this->is_closed_();
127 return this->
position <= this->target_position_;
134 if (dir == this->current_operation)
137 this->recompute_position_();
141 trig = this->stop_trigger_;
144 this->last_operation_ = dir;
145 trig = this->open_trigger_;
148 this->last_operation_ = dir;
149 trig = this->close_trigger_;
155 this->current_operation = dir;
157 this->stop_prev_trigger_();
159 this->prev_command_trigger_ = trig;
161 const uint32_t now =
millis();
162 this->start_dir_time_ = now;
163 this->last_recompute_time_ = now;
171 switch (this->current_operation) {
174 action_dur = this->open_duration_;
178 action_dur = this->close_duration_;
184 const uint32_t now =
millis();
185 this->
position += dir * (now - this->last_recompute_time_) / action_dur;
188 this->last_recompute_time_ = now;
const float DATA
For components that import data from directly connected sensors like DHT.
cover::CoverTraits get_traits() override
void stop_prev_trigger_()
CoverOperation
Enum encoding the current operation of a cover.
The cover is currently closing.
constexpr const T & clamp(const T &v, const T &lo, const T &hi, Compare comp)
uint32_t IRAM_ATTR HOT millis()
void trigger(Ts... x)
Inform the parent automation that the event has triggered.
const optional< bool > & get_toggle() const
void start_direction_(cover::CoverOperation dir)
bool is_at_target_() const
void recompute_position_()
void dump_config() override
Implementation of SPI Controller mode.
void control(const cover::CoverCall &call) override
The cover is currently opening.
float get_setup_priority() const override
const optional< float > & get_position() const