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:
parent
23e5cdb30e
commit
9637ef35bd
@ -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)
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user