8 static const char *
const TAG =
"time_based.cover";
13 LOG_COVER(
"",
"Time Based Cover",
this);
14 ESP_LOGCONFIG(TAG,
" Open Duration: %.1fs", this->open_duration_ / 1e3f);
15 ESP_LOGCONFIG(TAG,
" Close Duration: %.1fs", this->close_duration_ / 1e3f);
18 auto restore = this->restore_state_();
19 if (restore.has_value()) {
29 const uint32_t now =
millis();
32 this->recompute_position_();
34 if (this->is_at_target_()) {
35 if (this->has_built_in_endstop_ &&
42 this->publish_state();
46 if (now - this->last_publish_time_ > 1000) {
47 this->publish_state(
false);
48 this->last_publish_time_ = now;
54 traits.set_supports_position(
true);
55 traits.set_supports_toggle(
true);
56 traits.set_is_assumed_state(this->assumed_state_);
62 this->publish_state();
67 this->publish_state();
85 this->target_position_ = pos;
86 this->start_direction_(op);
90 this->target_position_ = pos;
91 this->start_direction_(op);
96 if (this->prev_command_trigger_ !=
nullptr) {
97 this->prev_command_trigger_->stop_action();
98 this->prev_command_trigger_ =
nullptr;
102 switch (this->current_operation) {
104 return this->
position >= this->target_position_;
106 return this->
position <= this->target_position_;
116 this->recompute_position_();
120 trig = this->stop_trigger_;
123 this->last_operation_ = dir;
124 trig = this->open_trigger_;
127 this->last_operation_ = dir;
128 trig = this->close_trigger_;
134 this->current_operation = dir;
136 const uint32_t now =
millis();
137 this->start_dir_time_ = now;
138 this->last_recompute_time_ = now;
140 this->stop_prev_trigger_();
142 this->prev_command_trigger_ = trig;
150 switch (this->current_operation) {
153 action_dur = this->open_duration_;
157 action_dur = this->close_duration_;
163 const uint32_t now =
millis();
164 this->
position += dir * (now - this->last_recompute_time_) / action_dur;
167 this->last_recompute_time_ = now;
void dump_config() override
const float DATA
For components that import data from directly connected sensors like DHT.
void control(const cover::CoverCall &call) override
CoverOperation
Enum encoding the current operation of a cover.
The cover is currently closing.
void recompute_position_()
cover::CoverTraits get_traits() override
void stop_prev_trigger_()
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.
float get_setup_priority() const override
void start_direction_(cover::CoverOperation dir)
const optional< bool > & get_toggle() const
bool is_at_target_() const
The cover is currently opening.
const optional< float > & get_position() const