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:
@@ -47,7 +47,7 @@ void TemplateText::update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TemplateText::control(const std::string &value) {
|
void TemplateText::control(const std::string &value) {
|
||||||
this->set_trigger_->trigger(value);
|
this->set_trigger_.trigger(value);
|
||||||
|
|
||||||
if (this->optimistic_)
|
if (this->optimistic_)
|
||||||
this->publish_state(value);
|
this->publish_state(value);
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ class TemplateText final : public text::Text, public PollingComponent {
|
|||||||
void dump_config() override;
|
void dump_config() override;
|
||||||
float get_setup_priority() const override { return setup_priority::HARDWARE; }
|
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_optimistic(bool optimistic) { this->optimistic_ = optimistic; }
|
||||||
void set_initial_value(const char *initial_value) { this->initial_value_ = initial_value; }
|
void set_initial_value(const char *initial_value) { this->initial_value_ = initial_value; }
|
||||||
/// Prevent accidental use of std::string which would dangle
|
/// 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;
|
void control(const std::string &value) override;
|
||||||
bool optimistic_ = false;
|
bool optimistic_ = false;
|
||||||
const char *initial_value_{nullptr};
|
const char *initial_value_{nullptr};
|
||||||
Trigger<std::string> *set_trigger_ = new Trigger<std::string>();
|
Trigger<std::string> set_trigger_;
|
||||||
TemplateLambda<std::string> f_{};
|
TemplateLambda<std::string> f_{};
|
||||||
|
|
||||||
TemplateTextSaverBase *pref_ = nullptr;
|
TemplateTextSaverBase *pref_ = nullptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user