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

[template.text] Avoid heap allocation for trigger (#13711)

This commit is contained in:
J. Nick Koston
2026-02-02 07:35:21 +01:00
committed by GitHub
parent 420de987bc
commit c0e5ae4298
2 changed files with 3 additions and 3 deletions

View File

@@ -47,7 +47,7 @@ void TemplateText::update() {
}
void TemplateText::control(const std::string &value) {
this->set_trigger_->trigger(value);
this->set_trigger_.trigger(value);
if (this->optimistic_)
this->publish_state(value);

View File

@@ -68,7 +68,7 @@ class TemplateText final : public text::Text, public PollingComponent {
void dump_config() override;
float get_setup_priority() const override { return setup_priority::HARDWARE; }
Trigger<std::string> *get_set_trigger() const { return this->set_trigger_; }
Trigger<std::string> *get_set_trigger() { return &this->set_trigger_; }
void set_optimistic(bool optimistic) { this->optimistic_ = optimistic; }
void set_initial_value(const char *initial_value) { this->initial_value_ = initial_value; }
/// Prevent accidental use of std::string which would dangle
@@ -79,7 +79,7 @@ class TemplateText final : public text::Text, public PollingComponent {
void control(const std::string &value) override;
bool optimistic_ = false;
const char *initial_value_{nullptr};
Trigger<std::string> *set_trigger_ = new Trigger<std::string>();
Trigger<std::string> set_trigger_;
TemplateLambda<std::string> f_{};
TemplateTextSaverBase *pref_ = nullptr;