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_stop(
true);
55 traits.set_supports_position(
true);
56 traits.set_supports_toggle(
true);
57 traits.set_is_assumed_state(this->assumed_state_);
63 this->publish_state();
68 this->publish_state();
88 this->target_position_ = pos;
89 this->start_direction_(op);
94 this->target_position_ = pos;
95 this->start_direction_(op);
102 this->target_position_ = pos;
103 this->start_direction_(op);
108 if (this->prev_command_trigger_ !=
nullptr) {
109 this->prev_command_trigger_->stop_action();
110 this->prev_command_trigger_ =
nullptr;
114 switch (this->current_operation) {
116 return this->
position >= this->target_position_;
118 return this->
position <= this->target_position_;
128 this->recompute_position_();
132 trig = this->stop_trigger_;
135 this->last_operation_ = dir;
136 trig = this->open_trigger_;
139 this->last_operation_ = dir;
140 trig = this->close_trigger_;
146 this->current_operation = dir;
148 const uint32_t now =
millis();
149 this->start_dir_time_ = now;
150 this->last_recompute_time_ = now;
152 this->stop_prev_trigger_();
154 this->prev_command_trigger_ = trig;
162 switch (this->current_operation) {
165 action_dur = this->open_duration_;
169 action_dur = this->close_duration_;
175 const uint32_t now =
millis();
176 this->
position += dir * (now - this->last_recompute_time_) / action_dur;
179 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
Implementation of SPI Controller mode.
The cover is currently opening.
const optional< float > & get_position() const