mirror of
https://github.com/esphome/esphome.git
synced 2026-02-18 15:35:59 -07:00
Merge branch 'template_text_no_heap_trigger' into integration
This commit is contained in:
@@ -215,7 +215,7 @@ void APIServer::loop() {
|
|||||||
|
|
||||||
#ifdef USE_API_CLIENT_DISCONNECTED_TRIGGER
|
#ifdef USE_API_CLIENT_DISCONNECTED_TRIGGER
|
||||||
// Fire trigger after client is removed so api.connected reflects the true state
|
// Fire trigger after client is removed so api.connected reflects the true state
|
||||||
this->client_disconnected_trigger_->trigger(client_name, client_peername);
|
this->client_disconnected_trigger_.trigger(client_name, client_peername);
|
||||||
#endif
|
#endif
|
||||||
// Don't increment client_index since we need to process the swapped element
|
// Don't increment client_index since we need to process the swapped element
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -227,12 +227,10 @@ class APIServer : public Component,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_API_CLIENT_CONNECTED_TRIGGER
|
#ifdef USE_API_CLIENT_CONNECTED_TRIGGER
|
||||||
Trigger<std::string, std::string> *get_client_connected_trigger() const { return this->client_connected_trigger_; }
|
Trigger<std::string, std::string> *get_client_connected_trigger() { return &this->client_connected_trigger_; }
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_API_CLIENT_DISCONNECTED_TRIGGER
|
#ifdef USE_API_CLIENT_DISCONNECTED_TRIGGER
|
||||||
Trigger<std::string, std::string> *get_client_disconnected_trigger() const {
|
Trigger<std::string, std::string> *get_client_disconnected_trigger() { return &this->client_disconnected_trigger_; }
|
||||||
return this->client_disconnected_trigger_;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -253,10 +251,10 @@ class APIServer : public Component,
|
|||||||
// Pointers and pointer-like types first (4 bytes each)
|
// Pointers and pointer-like types first (4 bytes each)
|
||||||
std::unique_ptr<socket::Socket> socket_ = nullptr;
|
std::unique_ptr<socket::Socket> socket_ = nullptr;
|
||||||
#ifdef USE_API_CLIENT_CONNECTED_TRIGGER
|
#ifdef USE_API_CLIENT_CONNECTED_TRIGGER
|
||||||
Trigger<std::string, std::string> *client_connected_trigger_ = new Trigger<std::string, std::string>();
|
Trigger<std::string, std::string> client_connected_trigger_;
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_API_CLIENT_DISCONNECTED_TRIGGER
|
#ifdef USE_API_CLIENT_DISCONNECTED_TRIGGER
|
||||||
Trigger<std::string, std::string> *client_disconnected_trigger_ = new Trigger<std::string, std::string>();
|
Trigger<std::string, std::string> client_disconnected_trigger_;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// 4-byte aligned types
|
// 4-byte aligned types
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ void SprinklerControllerNumber::setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SprinklerControllerNumber::control(float value) {
|
void SprinklerControllerNumber::control(float value) {
|
||||||
this->set_trigger_->trigger(value);
|
this->set_trigger_.trigger(value);
|
||||||
|
|
||||||
this->publish_state(value);
|
this->publish_state(value);
|
||||||
|
|
||||||
@@ -39,8 +39,7 @@ void SprinklerControllerNumber::control(float value) {
|
|||||||
|
|
||||||
void SprinklerControllerNumber::dump_config() { LOG_NUMBER("", "Sprinkler Controller Number", this); }
|
void SprinklerControllerNumber::dump_config() { LOG_NUMBER("", "Sprinkler Controller Number", this); }
|
||||||
|
|
||||||
SprinklerControllerSwitch::SprinklerControllerSwitch()
|
SprinklerControllerSwitch::SprinklerControllerSwitch() = default;
|
||||||
: turn_on_trigger_(new Trigger<>()), turn_off_trigger_(new Trigger<>()) {}
|
|
||||||
|
|
||||||
void SprinklerControllerSwitch::loop() {
|
void SprinklerControllerSwitch::loop() {
|
||||||
// Loop is only enabled when f_ has a value (see setup())
|
// Loop is only enabled when f_ has a value (see setup())
|
||||||
@@ -56,11 +55,11 @@ void SprinklerControllerSwitch::write_state(bool state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (state) {
|
if (state) {
|
||||||
this->prev_trigger_ = this->turn_on_trigger_;
|
this->prev_trigger_ = &this->turn_on_trigger_;
|
||||||
this->turn_on_trigger_->trigger();
|
this->turn_on_trigger_.trigger();
|
||||||
} else {
|
} else {
|
||||||
this->prev_trigger_ = this->turn_off_trigger_;
|
this->prev_trigger_ = &this->turn_off_trigger_;
|
||||||
this->turn_off_trigger_->trigger();
|
this->turn_off_trigger_.trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
this->publish_state(state);
|
this->publish_state(state);
|
||||||
@@ -69,9 +68,6 @@ void SprinklerControllerSwitch::write_state(bool state) {
|
|||||||
void SprinklerControllerSwitch::set_state_lambda(std::function<optional<bool>()> &&f) { this->f_ = f; }
|
void SprinklerControllerSwitch::set_state_lambda(std::function<optional<bool>()> &&f) { this->f_ = f; }
|
||||||
float SprinklerControllerSwitch::get_setup_priority() const { return setup_priority::HARDWARE; }
|
float SprinklerControllerSwitch::get_setup_priority() const { return setup_priority::HARDWARE; }
|
||||||
|
|
||||||
Trigger<> *SprinklerControllerSwitch::get_turn_on_trigger() const { return this->turn_on_trigger_; }
|
|
||||||
Trigger<> *SprinklerControllerSwitch::get_turn_off_trigger() const { return this->turn_off_trigger_; }
|
|
||||||
|
|
||||||
void SprinklerControllerSwitch::setup() {
|
void SprinklerControllerSwitch::setup() {
|
||||||
this->state = this->get_initial_state_with_restore_mode().value_or(false);
|
this->state = this->get_initial_state_with_restore_mode().value_or(false);
|
||||||
// Disable loop if no state lambda is set - nothing to poll
|
// Disable loop if no state lambda is set - nothing to poll
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ class SprinklerControllerNumber : public number::Number, public Component {
|
|||||||
void dump_config() override;
|
void dump_config() override;
|
||||||
float get_setup_priority() const override { return setup_priority::PROCESSOR; }
|
float get_setup_priority() const override { return setup_priority::PROCESSOR; }
|
||||||
|
|
||||||
Trigger<float> *get_set_trigger() const { return set_trigger_; }
|
Trigger<float> *get_set_trigger() { return &this->set_trigger_; }
|
||||||
void set_initial_value(float initial_value) { initial_value_ = initial_value; }
|
void set_initial_value(float initial_value) { initial_value_ = initial_value; }
|
||||||
void set_restore_value(bool restore_value) { this->restore_value_ = restore_value; }
|
void set_restore_value(bool restore_value) { this->restore_value_ = restore_value; }
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ class SprinklerControllerNumber : public number::Number, public Component {
|
|||||||
void control(float value) override;
|
void control(float value) override;
|
||||||
float initial_value_{NAN};
|
float initial_value_{NAN};
|
||||||
bool restore_value_{true};
|
bool restore_value_{true};
|
||||||
Trigger<float> *set_trigger_ = new Trigger<float>();
|
Trigger<float> set_trigger_;
|
||||||
|
|
||||||
ESPPreferenceObject pref_;
|
ESPPreferenceObject pref_;
|
||||||
};
|
};
|
||||||
@@ -97,8 +97,8 @@ class SprinklerControllerSwitch : public switch_::Switch, public Component {
|
|||||||
void dump_config() override;
|
void dump_config() override;
|
||||||
|
|
||||||
void set_state_lambda(std::function<optional<bool>()> &&f);
|
void set_state_lambda(std::function<optional<bool>()> &&f);
|
||||||
Trigger<> *get_turn_on_trigger() const;
|
Trigger<> *get_turn_on_trigger() { return &this->turn_on_trigger_; }
|
||||||
Trigger<> *get_turn_off_trigger() const;
|
Trigger<> *get_turn_off_trigger() { return &this->turn_off_trigger_; }
|
||||||
void loop() override;
|
void loop() override;
|
||||||
|
|
||||||
float get_setup_priority() const override;
|
float get_setup_priority() const override;
|
||||||
@@ -107,8 +107,8 @@ class SprinklerControllerSwitch : public switch_::Switch, public Component {
|
|||||||
void write_state(bool state) override;
|
void write_state(bool state) override;
|
||||||
|
|
||||||
optional<std::function<optional<bool>()>> f_;
|
optional<std::function<optional<bool>()>> f_;
|
||||||
Trigger<> *turn_on_trigger_;
|
Trigger<> turn_on_trigger_;
|
||||||
Trigger<> *turn_off_trigger_;
|
Trigger<> turn_off_trigger_;
|
||||||
Trigger<> *prev_trigger_{nullptr};
|
Trigger<> *prev_trigger_{nullptr};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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