60 if (container ==
nullptr || container->status_code !=
HTTP_STATUS_OK) {
61 ESP_LOGE(TAG,
"Failed to fetch manifest from %s", this_update->
source_url_.c_str());
63 this_update->
defer([this_update]() { this_update->
status_set_error(LOG_STR(
"Failed to fetch manifest")); });
68 uint8_t *data = allocator.
allocate(container->content_length);
69 if (data ==
nullptr) {
70 ESP_LOGE(TAG,
"Failed to allocate %zu bytes for manifest", container->content_length);
73 [this_update]() { this_update->
status_set_error(LOG_STR(
"Failed to allocate memory for manifest")); });
78 auto read_result =
http_read_fully(container.get(), data, container->content_length, MAX_READ_SIZE,
82 ESP_LOGE(TAG,
"Timeout reading manifest");
84 ESP_LOGE(TAG,
"Error reading manifest: %d", read_result.error_code);
87 this_update->
defer([this_update]() { this_update->
status_set_error(LOG_STR(
"Failed to read manifest")); });
88 allocator.
deallocate(data, container->content_length);
92 size_t read_index = container->get_bytes_read();
93 size_t content_length = container->content_length;
100 valid =
json::parse_json(data, read_index, [this_update](JsonObject root) ->
bool {
101 if (!root[ESPHOME_F(
"name")].is<const char *>() || !root[ESPHOME_F(
"version")].is<const char *>() ||
102 !root[ESPHOME_F(
"builds")].is<JsonArray>()) {
103 ESP_LOGE(TAG,
"Manifest does not contain required fields");
109 for (
auto build : root[ESPHOME_F(
"builds")].as<JsonArray>()) {
110 if (!build[ESPHOME_F(
"chipFamily")].is<const char *>()) {
111 ESP_LOGE(TAG,
"Manifest does not contain required fields");
114 if (build[ESPHOME_F(
"chipFamily")] == ESPHOME_VARIANT) {
115 if (!build[ESPHOME_F(
"ota")].is<JsonObject>()) {
116 ESP_LOGE(TAG,
"Manifest does not contain required fields");
119 JsonObject ota = build[ESPHOME_F(
"ota")].as<JsonObject>();
120 if (!ota[ESPHOME_F(
"path")].is<const char *>() || !ota[ESPHOME_F(
"md5")].is<const char *>()) {
121 ESP_LOGE(TAG,
"Manifest does not contain required fields");
125 this_update->
update_info_.
md5 = ota[ESPHOME_F(
"md5")].as<std::string>();
127 if (ota[ESPHOME_F(
"summary")].is<const char *>())
129 if (ota[ESPHOME_F(
"release_url")].is<const char *>())
141 ESP_LOGE(TAG,
"Failed to parse JSON from %s", this_update->
source_url_.c_str());
143 this_update->
defer([this_update]() { this_update->
status_set_error(LOG_STR(
"Failed to parse manifest JSON")); });
150 if (path[0] ==
'/') {
159#ifdef ESPHOME_PROJECT_VERSION
165 bool trigger_update_available =
false;
172 trigger_update_available =
true;
182 this_update->
defer([this_update, trigger_update_available]() {
189 if (trigger_update_available) {
ESPDEPRECATED("Use const char* overload instead. Removed in 2026.7.0", "2026.1.0") void defer(const std voi defer)(const char *name, std::function< void()> &&f)
Defer a callback to the next loop() call.
HttpReadResult http_read_fully(HttpContainer *container, uint8_t *buffer, size_t total_size, size_t chunk_size, uint32_t timeout_ms)
Read data from HTTP container into buffer with timeout handling Handles feed_wdt, yield,...