55 if (container ==
nullptr || container->status_code !=
HTTP_STATUS_OK) {
56 ESP_LOGE(TAG,
"Failed to fetch manifest from %s", this_update->
source_url_.c_str());
58 this_update->
defer([this_update]() { this_update->
status_set_error(LOG_STR(
"Failed to fetch manifest")); });
63 uint8_t *data = allocator.
allocate(container->content_length);
64 if (data ==
nullptr) {
65 ESP_LOGE(TAG,
"Failed to allocate %zu bytes for manifest", container->content_length);
68 [this_update]() { this_update->
status_set_error(LOG_STR(
"Failed to allocate memory for manifest")); });
73 size_t read_index = 0;
74 while (container->get_bytes_read() < container->content_length) {
75 int read_bytes = container->read(data + read_index, MAX_READ_SIZE);
79 if (read_bytes <= 0) {
84 read_index += read_bytes;
89 std::string response((
char *) data, read_index);
90 allocator.
deallocate(data, container->content_length);
96 if (!root[
"name"].is<const char *>() || !root[
"version"].is<const char *>() || !root[
"builds"].is<JsonArray>()) {
97 ESP_LOGE(TAG,
"Manifest does not contain required fields");
103 for (
auto build : root[
"builds"].as<JsonArray>()) {
104 if (!build[
"chipFamily"].is<const char *>()) {
105 ESP_LOGE(TAG,
"Manifest does not contain required fields");
108 if (build[
"chipFamily"] == ESPHOME_VARIANT) {
109 if (!build[
"ota"].is<JsonObject>()) {
110 ESP_LOGE(TAG,
"Manifest does not contain required fields");
113 JsonObject ota = build[
"ota"].as<JsonObject>();
114 if (!ota[
"path"].is<const char *>() || !ota[
"md5"].is<const char *>()) {
115 ESP_LOGE(TAG,
"Manifest does not contain required fields");
121 if (ota[
"summary"].is<const char *>())
123 if (ota[
"release_url"].is<const char *>())
134 ESP_LOGE(TAG,
"Failed to parse JSON from %s", this_update->
source_url_.c_str());
136 this_update->
defer([this_update]() { this_update->
status_set_error(LOG_STR(
"Failed to parse manifest JSON")); });
143 if (path[0] ==
'/') {
153 std::string current_version;
154#ifdef ESPHOME_PROJECT_VERSION
155 current_version = ESPHOME_PROJECT_VERSION;
157 current_version = ESPHOME_VERSION;
163 bool trigger_update_available =
false;
170 trigger_update_available =
true;
180 this_update->
defer([this_update, trigger_update_available]() {
187 if (trigger_update_available) {