diff --git a/esphome/core/component.cpp b/esphome/core/component.cpp index a6224a17c0..b20964b872 100644 --- a/esphome/core/component.cpp +++ b/esphome/core/component.cpp @@ -79,7 +79,7 @@ void Component::call_setup() { this->setup(); } void Component::call_dump_config() { this->dump_config(); if (this->is_failed()) { - ESP_LOGE(TAG, " Component %s is marked FAILED", this->get_component_source()); + ESP_LOGE(TAG, " Component %s is marked FAILED: %s", this->get_component_source(), this->error_message_.c_str()); } } @@ -162,6 +162,8 @@ void Component::status_set_error(const char *message) { this->component_state_ |= STATUS_LED_ERROR; App.app_state_ |= STATUS_LED_ERROR; ESP_LOGE(TAG, "Component %s set Error flag: %s", this->get_component_source(), message); + if (strcmp(message, "unspecified") != 0) + this->error_message_ = message; } void Component::status_clear_warning() { if ((this->component_state_ & STATUS_LED_WARNING) == 0) diff --git a/esphome/core/component.h b/esphome/core/component.h index e6ed55efb7..f5c56459b1 100644 --- a/esphome/core/component.h +++ b/esphome/core/component.h @@ -118,6 +118,11 @@ class Component { */ virtual void mark_failed(); + void mark_failed(const char *message) { + this->status_set_error(message); + this->mark_failed(); + } + bool is_failed() const; bool is_ready() const; @@ -279,6 +284,7 @@ class Component { uint32_t component_state_{0x0000}; ///< State of this component. float setup_priority_override_{NAN}; const char *component_source_{nullptr}; + std::string error_message_{}; }; /** This class simplifies creating components that periodically check a state.