diff --git a/esphome/components/wifi/wifi_component.cpp b/esphome/components/wifi/wifi_component.cpp index d16c94fa13..e57bf25b8c 100644 --- a/esphome/components/wifi/wifi_component.cpp +++ b/esphome/components/wifi/wifi_component.cpp @@ -148,7 +148,7 @@ void WiFiComponent::loop() { switch (this->state_) { case WIFI_COMPONENT_STATE_COOLDOWN: { - this->status_set_warning("waiting to reconnect"); + this->status_set_warning(LOG_STR("waiting to reconnect")); if (millis() - this->action_started_ > 5000) { if (this->fast_connect_ || this->retry_hidden_) { if (!this->selected_ap_.get_bssid().has_value()) @@ -161,13 +161,13 @@ void WiFiComponent::loop() { break; } case WIFI_COMPONENT_STATE_STA_SCANNING: { - this->status_set_warning("scanning for networks"); + this->status_set_warning(LOG_STR("scanning for networks")); this->check_scanning_finished(); break; } case WIFI_COMPONENT_STATE_STA_CONNECTING: case WIFI_COMPONENT_STATE_STA_CONNECTING_2: { - this->status_set_warning("associating to network"); + this->status_set_warning(LOG_STR("associating to network")); this->check_connecting_finished(); break; } diff --git a/esphome/core/component.cpp b/esphome/core/component.cpp index 3f6beeb28e..b5522f030c 100644 --- a/esphome/core/component.cpp +++ b/esphome/core/component.cpp @@ -278,15 +278,29 @@ bool Component::is_ready() const { bool Component::can_proceed() { return true; } bool Component::status_has_warning() const { return this->component_state_ & STATUS_LED_WARNING; } bool Component::status_has_error() const { return this->component_state_ & STATUS_LED_ERROR; } -void Component::status_set_warning(const char *message) { + +void Component::status_set_warning_flag_() { // Don't spam the log. This risks missing different warning messages though. if ((this->component_state_ & STATUS_LED_WARNING) != 0) return; this->component_state_ |= STATUS_LED_WARNING; App.app_state_ |= STATUS_LED_WARNING; - ESP_LOGW(TAG, "%s set Warning flag: %s", LOG_STR_ARG(this->get_component_log_str()), - message ? message : UNSPECIFIED_MESSAGE); } + +void Component::status_set_warning(const char *message) { + this->status_set_warning_flag_(); + if ((this->component_state_ & STATUS_LED_WARNING) != 0) + ESP_LOGW(TAG, "%s set Warning flag: %s", LOG_STR_ARG(this->get_component_log_str()), + message ? message : UNSPECIFIED_MESSAGE); +} +#ifdef USE_STORE_LOG_STR_IN_FLASH +void Component::status_set_warning(const LogString *message) { + this->status_set_warning_flag_(); + if ((this->component_state_ & STATUS_LED_WARNING) != 0) + ESP_LOGW(TAG, "%s set Warning flag: %s", LOG_STR_ARG(this->get_component_log_str()), + message ? LOG_STR_ARG(message) : UNSPECIFIED_MESSAGE); +} +#endif void Component::status_set_error(const char *message) { if ((this->component_state_ & STATUS_LED_ERROR) != 0) return; diff --git a/esphome/core/component.h b/esphome/core/component.h index 9a7e442c5c..3e3c61abc5 100644 --- a/esphome/core/component.h +++ b/esphome/core/component.h @@ -204,6 +204,9 @@ class Component { bool status_has_error() const; void status_set_warning(const char *message = nullptr); +#ifdef USE_STORE_LOG_STR_IN_FLASH + void status_set_warning(const LogString *message); +#endif void status_set_error(const char *message = nullptr); @@ -240,6 +243,9 @@ class Component { /// Helper to set component state (clears state bits and sets new state) void set_component_state_(uint8_t state); + /// Helper to set warning flag without duplicating logic + void status_set_warning_flag_(); + /** Set an interval function with a unique name. Empty name means no cancelling possible. * * This will call f every interval ms. Can be cancelled via CancelInterval().