88 auto *result =
new TaskResult();
89 auto *info = &result->info;
93 if (container ==
nullptr || container->status_code !=
HTTP_STATUS_OK) {
94 ESP_LOGE(TAG,
"Failed to fetch manifest from %s", this_update->
source_url_.c_str());
95 if (container !=
nullptr)
97 result->error_str = LOG_STR(
"Failed to fetch manifest");
103 uint8_t *data = allocator.
allocate(container->content_length);
104 if (data ==
nullptr) {
105 ESP_LOGE(TAG,
"Failed to allocate %zu bytes for manifest", container->content_length);
107 result->error_str = LOG_STR(
"Failed to allocate memory for manifest");
111 auto read_result =
http_read_fully(container.get(), data, container->content_length, MAX_READ_SIZE,
115 ESP_LOGE(TAG,
"Timeout reading manifest");
117 ESP_LOGE(TAG,
"Error reading manifest: %d", read_result.error_code);
119 allocator.
deallocate(data, container->content_length);
121 result->error_str = LOG_STR(
"Failed to read manifest");
124 size_t read_index = container->get_bytes_read();
125 size_t content_length = container->content_length;
133 if (!root[ESPHOME_F(
"name")].is<const char *>() || !root[ESPHOME_F(
"version")].is<const char *>() ||
134 !root[ESPHOME_F(
"builds")].is<JsonArray>()) {
135 ESP_LOGE(TAG,
"Manifest does not contain required fields");
138 info->title = root[ESPHOME_F(
"name")].as<std::string>();
139 info->latest_version = root[ESPHOME_F(
"version")].as<std::string>();
141 auto builds_array = root[ESPHOME_F(
"builds")].as<JsonArray>();
142 for (
auto build : builds_array) {
143 if (!build[ESPHOME_F(
"chipFamily")].is<const char *>()) {
144 ESP_LOGE(TAG,
"Manifest does not contain required fields");
147 if (build[ESPHOME_F(
"chipFamily")] == ESPHOME_VARIANT) {
148 if (!build[ESPHOME_F(
"ota")].is<JsonObject>()) {
149 ESP_LOGE(TAG,
"Manifest does not contain required fields");
152 JsonObject ota = build[ESPHOME_F(
"ota")].as<JsonObject>();
153 if (!ota[ESPHOME_F(
"path")].is<const char *>() || !ota[ESPHOME_F(
"md5")].is<const char *>()) {
154 ESP_LOGE(TAG,
"Manifest does not contain required fields");
157 info->firmware_url = ota[ESPHOME_F(
"path")].as<std::string>();
158 info->md5 = ota[ESPHOME_F(
"md5")].as<std::string>();
160 if (ota[ESPHOME_F(
"summary")].is<const char *>())
161 info->summary = ota[ESPHOME_F(
"summary")].as<std::string>();
162 if (ota[ESPHOME_F(
"release_url")].is<const char *>())
163 info->release_url = ota[ESPHOME_F(
"release_url")].as<std::string>();
174 ESP_LOGE(TAG,
"Failed to parse JSON from %s", this_update->
source_url_.c_str());
175 result->error_str = LOG_STR(
"Failed to parse manifest JSON");
180 if (!info->firmware_url.empty() && info->firmware_url.find(
"http") == std::string::npos) {
181 std::string path = info->firmware_url;
182 if (path[0] ==
'/') {
184 info->firmware_url = domain + path;
187 info->firmware_url = domain + path;
191#ifdef ESPHOME_PROJECT_VERSION
192 info->current_version = ESPHOME_PROJECT_VERSION;
194 info->current_version = ESPHOME_VERSION;
206 this_update->
defer([this_update, result]() {
207 if (result->error_str !=
nullptr) {
214 bool trigger_update_available =
false;
216 if (result->info.latest_version.empty() || result->info.latest_version == result->info.current_version) {
221 trigger_update_available =
true;
226 this_update->
state_ = new_state;
232 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,...