91 auto *result =
new TaskResult();
92 auto *info = &result->info;
96 if (container ==
nullptr || container->status_code !=
HTTP_STATUS_OK) {
97 ESP_LOGE(TAG,
"Failed to fetch manifest from %s", this_update->
source_url_.c_str());
98 if (container !=
nullptr)
100 result->error_str = LOG_STR(
"Failed to fetch manifest");
106 uint8_t *data = allocator.
allocate(container->content_length);
107 if (data ==
nullptr) {
108 ESP_LOGE(TAG,
"Failed to allocate %zu bytes for manifest", container->content_length);
110 result->error_str = LOG_STR(
"Failed to allocate memory for manifest");
114 auto read_result =
http_read_fully(container.get(), data, container->content_length, MAX_READ_SIZE,
118 ESP_LOGE(TAG,
"Timeout reading manifest");
120 ESP_LOGE(TAG,
"Error reading manifest: %d", read_result.error_code);
122 allocator.
deallocate(data, container->content_length);
124 result->error_str = LOG_STR(
"Failed to read manifest");
127 size_t read_index = container->get_bytes_read();
128 size_t content_length = container->content_length;
136 if (!root[ESPHOME_F(
"name")].is<const char *>() || !root[ESPHOME_F(
"version")].is<const char *>() ||
137 !root[ESPHOME_F(
"builds")].is<JsonArray>()) {
138 ESP_LOGE(TAG,
"Manifest does not contain required fields");
141 info->title = root[ESPHOME_F(
"name")].as<std::string>();
142 info->latest_version = root[ESPHOME_F(
"version")].as<std::string>();
144 auto builds_array = root[ESPHOME_F(
"builds")].as<JsonArray>();
145 for (
auto build : builds_array) {
146 if (!build[ESPHOME_F(
"chipFamily")].is<const char *>()) {
147 ESP_LOGE(TAG,
"Manifest does not contain required fields");
150 if (build[ESPHOME_F(
"chipFamily")] == ESPHOME_VARIANT) {
151 if (!build[ESPHOME_F(
"ota")].is<JsonObject>()) {
152 ESP_LOGE(TAG,
"Manifest does not contain required fields");
155 JsonObject ota = build[ESPHOME_F(
"ota")].as<JsonObject>();
156 if (!ota[ESPHOME_F(
"path")].is<const char *>() || !ota[ESPHOME_F(
"md5")].is<const char *>()) {
157 ESP_LOGE(TAG,
"Manifest does not contain required fields");
160 info->firmware_url = ota[ESPHOME_F(
"path")].as<std::string>();
161 info->md5 = ota[ESPHOME_F(
"md5")].as<std::string>();
163 if (ota[ESPHOME_F(
"summary")].is<const char *>())
164 info->summary = ota[ESPHOME_F(
"summary")].as<std::string>();
165 if (ota[ESPHOME_F(
"release_url")].is<const char *>())
166 info->release_url = ota[ESPHOME_F(
"release_url")].as<std::string>();
177 ESP_LOGE(TAG,
"Failed to parse JSON from %s", this_update->
source_url_.c_str());
178 result->error_str = LOG_STR(
"Failed to parse manifest JSON");
183 if (!info->firmware_url.empty() && info->firmware_url.find(
"http") == std::string::npos) {
184 std::string path = info->firmware_url;
185 if (path[0] ==
'/') {
187 info->firmware_url = domain + path;
190 info->firmware_url = domain + path;
194#ifdef ESPHOME_PROJECT_VERSION
195 info->current_version = ESPHOME_PROJECT_VERSION;
197 info->current_version = ESPHOME_VERSION;
209 this_update->
defer([this_update, result]() {
213 if (result->error_str !=
nullptr) {
220 bool trigger_update_available =
false;
222 if (result->info.latest_version.empty() || result->info.latest_version == result->info.current_version) {
227 trigger_update_available =
true;
232 this_update->
state_ = new_state;
238 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.
ESPDEPRECATED("Use const char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0") void set_interval(const std voi set_interval)(const char *name, uint32_t interval, std::function< void()> &&f)
Set an interval function with a unique name.
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,...