mirror of
https://github.com/esphome/esphome.git
synced 2026-02-11 10:12:38 +00:00
Compare commits
3 Commits
beta
...
status_set
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
42be5381e6 | ||
|
|
ada557b9fe | ||
|
|
8ad4bb9255 |
@@ -19,8 +19,7 @@ void CST816Touchscreen::continue_setup_() {
|
|||||||
case CST816T_CHIP_ID:
|
case CST816T_CHIP_ID:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ESP_LOGE(TAG, "Unknown chip ID: 0x%02X", this->chip_id_);
|
this->status_set_error(str_sprintf("Unknown chip ID 0x%02X", this->chip_id_));
|
||||||
this->status_set_error("Unknown chip ID");
|
|
||||||
this->mark_failed();
|
this->mark_failed();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,18 +49,18 @@ void HttpRequestUpdate::update_task(void *params) {
|
|||||||
auto container = this_update->request_parent_->get(this_update->source_url_);
|
auto container = this_update->request_parent_->get(this_update->source_url_);
|
||||||
|
|
||||||
if (container == nullptr || container->status_code != HTTP_STATUS_OK) {
|
if (container == nullptr || container->status_code != HTTP_STATUS_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to fetch manifest from %s", this_update->source_url_.c_str());
|
std::string msg = str_sprintf("Failed to fetch manifest from %s", this_update->source_url_.c_str());
|
||||||
// Defer to main loop to avoid race condition on component_state_ read-modify-write
|
// Defer to main loop to avoid race condition on component_state_ read-modify-write
|
||||||
this_update->defer([this_update]() { this_update->status_set_error("Failed to fetch manifest"); });
|
this_update->defer([this_update, msg]() { this_update->status_set_error(msg); });
|
||||||
UPDATE_RETURN;
|
UPDATE_RETURN;
|
||||||
}
|
}
|
||||||
|
|
||||||
RAMAllocator<uint8_t> allocator;
|
RAMAllocator<uint8_t> allocator;
|
||||||
uint8_t *data = allocator.allocate(container->content_length);
|
uint8_t *data = allocator.allocate(container->content_length);
|
||||||
if (data == nullptr) {
|
if (data == nullptr) {
|
||||||
ESP_LOGE(TAG, "Failed to allocate %zu bytes for manifest", container->content_length);
|
std::string msg = str_sprintf("Failed to allocate %zu bytes for manifest", container->content_length);
|
||||||
// Defer to main loop to avoid race condition on component_state_ read-modify-write
|
// Defer to main loop to avoid race condition on component_state_ read-modify-write
|
||||||
this_update->defer([this_update]() { this_update->status_set_error("Failed to allocate memory for manifest"); });
|
this_update->defer([this_update, msg]() { this_update->status_set_error(msg); });
|
||||||
container->end();
|
container->end();
|
||||||
UPDATE_RETURN;
|
UPDATE_RETURN;
|
||||||
}
|
}
|
||||||
@@ -121,9 +121,9 @@ void HttpRequestUpdate::update_task(void *params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
ESP_LOGE(TAG, "Failed to parse JSON from %s", this_update->source_url_.c_str());
|
std::string msg = str_sprintf("Failed to parse JSON from %s", this_update->source_url_.c_str());
|
||||||
// Defer to main loop to avoid race condition on component_state_ read-modify-write
|
// Defer to main loop to avoid race condition on component_state_ read-modify-write
|
||||||
this_update->defer([this_update]() { this_update->status_set_error("Failed to parse manifest JSON"); });
|
this_update->defer([this_update, msg]() { this_update->status_set_error(msg); });
|
||||||
UPDATE_RETURN;
|
UPDATE_RETURN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ static const char *const TAG = "component";
|
|||||||
namespace {
|
namespace {
|
||||||
struct ComponentErrorMessage {
|
struct ComponentErrorMessage {
|
||||||
const Component *component;
|
const Component *component;
|
||||||
const char *message;
|
std::string message;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ComponentPriorityOverride {
|
struct ComponentPriorityOverride {
|
||||||
@@ -146,7 +146,7 @@ void Component::call_dump_config() {
|
|||||||
if (component_error_messages) {
|
if (component_error_messages) {
|
||||||
for (const auto &entry : *component_error_messages) {
|
for (const auto &entry : *component_error_messages) {
|
||||||
if (entry.component == this) {
|
if (entry.component == this) {
|
||||||
error_msg = entry.message;
|
error_msg = entry.message.c_str();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -307,28 +307,33 @@ void Component::status_set_warning(const LogString *message) {
|
|||||||
ESP_LOGW(TAG, "%s set Warning flag: %s", LOG_STR_ARG(this->get_component_log_str()),
|
ESP_LOGW(TAG, "%s set Warning flag: %s", LOG_STR_ARG(this->get_component_log_str()),
|
||||||
message ? LOG_STR_ARG(message) : LOG_STR_LITERAL("unspecified"));
|
message ? LOG_STR_ARG(message) : LOG_STR_LITERAL("unspecified"));
|
||||||
}
|
}
|
||||||
void Component::status_set_error(const char *message) {
|
void Component::status_set_error(const std::string &message) {
|
||||||
if ((this->component_state_ & STATUS_LED_ERROR) != 0)
|
if ((this->component_state_ & STATUS_LED_ERROR) != 0)
|
||||||
return;
|
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(TAG, "%s set Error flag: %s", LOG_STR_ARG(this->get_component_log_str()),
|
ESP_LOGE(TAG, "%s set Error flag: %s", LOG_STR_ARG(this->get_component_log_str()), message.c_str());
|
||||||
message ? message : LOG_STR_LITERAL("unspecified"));
|
// Lazy allocate the error messages vector if needed
|
||||||
if (message != nullptr) {
|
if (!component_error_messages) {
|
||||||
// Lazy allocate the error messages vector if needed
|
component_error_messages = std::make_unique<std::vector<ComponentErrorMessage>>();
|
||||||
if (!component_error_messages) {
|
|
||||||
component_error_messages = std::make_unique<std::vector<ComponentErrorMessage>>();
|
|
||||||
}
|
|
||||||
// Check if this component already has an error message
|
|
||||||
for (auto &entry : *component_error_messages) {
|
|
||||||
if (entry.component == this) {
|
|
||||||
entry.message = message;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Add new error message
|
|
||||||
component_error_messages->emplace_back(ComponentErrorMessage{this, message});
|
|
||||||
}
|
}
|
||||||
|
// Check if this component already has an error message
|
||||||
|
for (auto &entry : *component_error_messages) {
|
||||||
|
if (entry.component == this) {
|
||||||
|
entry.message = message;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Add new error message
|
||||||
|
component_error_messages->emplace_back(ComponentErrorMessage{this, message});
|
||||||
|
}
|
||||||
|
void Component::status_set_error() {
|
||||||
|
// No message version - just set the error flag
|
||||||
|
if ((this->component_state_ & STATUS_LED_ERROR) != 0)
|
||||||
|
return;
|
||||||
|
this->component_state_ |= STATUS_LED_ERROR;
|
||||||
|
App.app_state_ |= STATUS_LED_ERROR;
|
||||||
|
ESP_LOGE(TAG, "%s set Error flag: %s", LOG_STR_ARG(this->get_component_log_str()), LOG_STR_LITERAL("unspecified"));
|
||||||
}
|
}
|
||||||
void Component::status_clear_warning() {
|
void Component::status_clear_warning() {
|
||||||
if ((this->component_state_ & STATUS_LED_WARNING) == 0)
|
if ((this->component_state_ & STATUS_LED_WARNING) == 0)
|
||||||
|
|||||||
@@ -216,7 +216,8 @@ class Component {
|
|||||||
void status_set_warning(const char *message = nullptr);
|
void status_set_warning(const char *message = nullptr);
|
||||||
void status_set_warning(const LogString *message);
|
void status_set_warning(const LogString *message);
|
||||||
|
|
||||||
void status_set_error(const char *message = nullptr);
|
void status_set_error(const std::string &message);
|
||||||
|
void status_set_error();
|
||||||
|
|
||||||
void status_clear_warning();
|
void status_clear_warning();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user