1
0
mirror of https://github.com/esphome/esphome.git synced 2026-02-08 00:31:58 +00:00

[time_based] Avoid heap allocation for cover triggers (#13703)

This commit is contained in:
J. Nick Koston
2026-02-02 05:15:50 +01:00
committed by GitHub
parent 1362ff6cba
commit 56110d4495
2 changed files with 9 additions and 9 deletions

View File

@@ -132,15 +132,15 @@ void TimeBasedCover::start_direction_(CoverOperation dir) {
Trigger<> *trig;
switch (dir) {
case COVER_OPERATION_IDLE:
trig = this->stop_trigger_;
trig = &this->stop_trigger_;
break;
case COVER_OPERATION_OPENING:
this->last_operation_ = dir;
trig = this->open_trigger_;
trig = &this->open_trigger_;
break;
case COVER_OPERATION_CLOSING:
this->last_operation_ = dir;
trig = this->close_trigger_;
trig = &this->close_trigger_;
break;
default:
return;

View File

@@ -14,9 +14,9 @@ class TimeBasedCover : public cover::Cover, public Component {
void dump_config() override;
float get_setup_priority() const override;
Trigger<> *get_open_trigger() const { return this->open_trigger_; }
Trigger<> *get_close_trigger() const { return this->close_trigger_; }
Trigger<> *get_stop_trigger() const { return this->stop_trigger_; }
Trigger<> *get_open_trigger() { return &this->open_trigger_; }
Trigger<> *get_close_trigger() { return &this->close_trigger_; }
Trigger<> *get_stop_trigger() { return &this->stop_trigger_; }
void set_open_duration(uint32_t open_duration) { this->open_duration_ = open_duration; }
void set_close_duration(uint32_t close_duration) { this->close_duration_ = close_duration; }
cover::CoverTraits get_traits() override;
@@ -34,11 +34,11 @@ class TimeBasedCover : public cover::Cover, public Component {
void recompute_position_();
Trigger<> *open_trigger_{new Trigger<>()};
Trigger<> open_trigger_;
uint32_t open_duration_;
Trigger<> *close_trigger_{new Trigger<>()};
Trigger<> close_trigger_;
uint32_t close_duration_;
Trigger<> *stop_trigger_{new Trigger<>()};
Trigger<> stop_trigger_;
Trigger<> *prev_command_trigger_{nullptr};
uint32_t last_recompute_time_{0};