diff --git a/esphome/components/wifi/automation.h b/esphome/components/wifi/automation.h index fb0e71bcf6..1ad69b3992 100644 --- a/esphome/components/wifi/automation.h +++ b/esphome/components/wifi/automation.h @@ -48,7 +48,7 @@ template class WiFiConfigureAction : public Action, publi char ssid_buf[SSID_BUFFER_SIZE]; if (strcmp(global_wifi_component->wifi_ssid_to(ssid_buf), ssid.c_str()) == 0) { // Callback to notify the user that the connection was successful - this->connect_trigger_->trigger(); + this->connect_trigger_.trigger(); return; } // Create a new WiFiAP object with the new SSID and password @@ -79,13 +79,13 @@ template class WiFiConfigureAction : public Action, publi // Start a timeout for the fallback if the connection to the old AP fails this->set_timeout("wifi-fallback-timeout", this->connection_timeout_.value(x...), [this]() { this->connecting_ = false; - this->error_trigger_->trigger(); + this->error_trigger_.trigger(); }); }); } - Trigger<> *get_connect_trigger() const { return this->connect_trigger_; } - Trigger<> *get_error_trigger() const { return this->error_trigger_; } + Trigger<> *get_connect_trigger() { return &this->connect_trigger_; } + Trigger<> *get_error_trigger() { return &this->error_trigger_; } void loop() override { if (!this->connecting_) @@ -98,10 +98,10 @@ template class WiFiConfigureAction : public Action, publi char ssid_buf[SSID_BUFFER_SIZE]; if (strcmp(global_wifi_component->wifi_ssid_to(ssid_buf), this->new_sta_.get_ssid().c_str()) == 0) { // Callback to notify the user that the connection was successful - this->connect_trigger_->trigger(); + this->connect_trigger_.trigger(); } else { // Callback to notify the user that the connection failed - this->error_trigger_->trigger(); + this->error_trigger_.trigger(); } } } @@ -110,8 +110,8 @@ template class WiFiConfigureAction : public Action, publi bool connecting_{false}; WiFiAP new_sta_; WiFiAP old_sta_; - Trigger<> *connect_trigger_{new Trigger<>()}; - Trigger<> *error_trigger_{new Trigger<>()}; + Trigger<> connect_trigger_; + Trigger<> error_trigger_; }; } // namespace esphome::wifi diff --git a/esphome/components/wifi/wifi_component.cpp b/esphome/components/wifi/wifi_component.cpp index 226e2345c3..c4bfdf3c42 100644 --- a/esphome/components/wifi/wifi_component.cpp +++ b/esphome/components/wifi/wifi_component.cpp @@ -655,12 +655,12 @@ void WiFiComponent::loop() { if (this->is_connected() != this->handled_connected_state_) { #ifdef USE_WIFI_DISCONNECT_TRIGGER if (this->handled_connected_state_) { - this->disconnect_trigger_->trigger(); + this->disconnect_trigger_.trigger(); } #endif #ifdef USE_WIFI_CONNECT_TRIGGER if (!this->handled_connected_state_) { - this->connect_trigger_->trigger(); + this->connect_trigger_.trigger(); } #endif this->handled_connected_state_ = this->is_connected(); diff --git a/esphome/components/wifi/wifi_component.h b/esphome/components/wifi/wifi_component.h index 92cd96fe6f..4bdc253f66 100644 --- a/esphome/components/wifi/wifi_component.h +++ b/esphome/components/wifi/wifi_component.h @@ -455,10 +455,10 @@ class WiFiComponent : public Component { void set_post_connect_roaming(bool enabled) { this->post_connect_roaming_ = enabled; } #ifdef USE_WIFI_CONNECT_TRIGGER - Trigger<> *get_connect_trigger() const { return this->connect_trigger_; } + Trigger<> *get_connect_trigger() { return &this->connect_trigger_; } #endif #ifdef USE_WIFI_DISCONNECT_TRIGGER - Trigger<> *get_disconnect_trigger() const { return this->disconnect_trigger_; } + Trigger<> *get_disconnect_trigger() { return &this->disconnect_trigger_; } #endif int32_t get_wifi_channel(); @@ -739,12 +739,11 @@ class WiFiComponent : public Component { SemaphoreHandle_t high_performance_semaphore_{nullptr}; #endif - // Pointers at the end (naturally aligned) #ifdef USE_WIFI_CONNECT_TRIGGER - Trigger<> *connect_trigger_{new Trigger<>()}; + Trigger<> connect_trigger_; #endif #ifdef USE_WIFI_DISCONNECT_TRIGGER - Trigger<> *disconnect_trigger_{new Trigger<>()}; + Trigger<> disconnect_trigger_; #endif private: