mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 08:28:12 +01:00
Show component warnings and errors in the log; (#6400)
This commit is contained in:
parent
f0936dd22d
commit
774cbde1b6
2 changed files with 27 additions and 10 deletions
|
@ -141,18 +141,35 @@ bool Component::is_ready() {
|
||||||
(this->component_state_ & COMPONENT_STATE_MASK) == COMPONENT_STATE_SETUP;
|
(this->component_state_ & COMPONENT_STATE_MASK) == COMPONENT_STATE_SETUP;
|
||||||
}
|
}
|
||||||
bool Component::can_proceed() { return true; }
|
bool Component::can_proceed() { return true; }
|
||||||
bool Component::status_has_warning() { return this->component_state_ & STATUS_LED_WARNING; }
|
bool Component::status_has_warning() const { return this->component_state_ & STATUS_LED_WARNING; }
|
||||||
bool Component::status_has_error() { return this->component_state_ & STATUS_LED_ERROR; }
|
bool Component::status_has_error() const { return this->component_state_ & STATUS_LED_ERROR; }
|
||||||
void Component::status_set_warning() {
|
void Component::status_set_warning(const char *message) {
|
||||||
|
// 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;
|
this->component_state_ |= STATUS_LED_WARNING;
|
||||||
App.app_state_ |= STATUS_LED_WARNING;
|
App.app_state_ |= STATUS_LED_WARNING;
|
||||||
|
ESP_LOGW(this->get_component_source(), "Warning set: %s", message);
|
||||||
}
|
}
|
||||||
void Component::status_set_error() {
|
void Component::status_set_error(const char *message) {
|
||||||
|
if ((this->component_state_ & STATUS_LED_ERROR) != 0)
|
||||||
|
return;
|
||||||
this->component_state_ |= STATUS_LED_ERROR;
|
this->component_state_ |= STATUS_LED_ERROR;
|
||||||
App.app_state_ |= STATUS_LED_ERROR;
|
App.app_state_ |= STATUS_LED_ERROR;
|
||||||
|
ESP_LOGE(this->get_component_source(), "Error set: %s", message);
|
||||||
|
}
|
||||||
|
void Component::status_clear_warning() {
|
||||||
|
if ((this->component_state_ & STATUS_LED_WARNING) == 0)
|
||||||
|
return;
|
||||||
|
this->component_state_ &= ~STATUS_LED_WARNING;
|
||||||
|
ESP_LOGW(this->get_component_source(), "Warning cleared");
|
||||||
|
}
|
||||||
|
void Component::status_clear_error() {
|
||||||
|
if ((this->component_state_ & STATUS_LED_ERROR) == 0)
|
||||||
|
return;
|
||||||
|
this->component_state_ &= ~STATUS_LED_ERROR;
|
||||||
|
ESP_LOGE(this->get_component_source(), "Error cleared");
|
||||||
}
|
}
|
||||||
void Component::status_clear_warning() { this->component_state_ &= ~STATUS_LED_WARNING; }
|
|
||||||
void Component::status_clear_error() { this->component_state_ &= ~STATUS_LED_ERROR; }
|
|
||||||
void Component::status_momentary_warning(const std::string &name, uint32_t length) {
|
void Component::status_momentary_warning(const std::string &name, uint32_t length) {
|
||||||
this->status_set_warning();
|
this->status_set_warning();
|
||||||
this->set_timeout(name, length, [this]() { this->status_clear_warning(); });
|
this->set_timeout(name, length, [this]() { this->status_clear_warning(); });
|
||||||
|
|
|
@ -124,13 +124,13 @@ class Component {
|
||||||
|
|
||||||
virtual bool can_proceed();
|
virtual bool can_proceed();
|
||||||
|
|
||||||
bool status_has_warning();
|
bool status_has_warning() const;
|
||||||
|
|
||||||
bool status_has_error();
|
bool status_has_error() const;
|
||||||
|
|
||||||
void status_set_warning();
|
void status_set_warning(const char *message = "unspecified");
|
||||||
|
|
||||||
void status_set_error();
|
void status_set_error(const char *message = "unspecified");
|
||||||
|
|
||||||
void status_clear_warning();
|
void status_clear_warning();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue