1
0
mirror of https://github.com/esphome/esphome.git synced 2025-04-08 03:40:28 +01:00

[component] Show error message for failed component (#8478)

This commit is contained in:
Clyde Stubbs 2025-04-07 19:26:34 +10:00 committed by GitHub
parent 23e5cdb30e
commit 9637ef35bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 1 deletions

View File

@ -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)

View File

@ -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.