mirror of
https://github.com/esphome/esphome.git
synced 2025-08-06 18:37:47 +00:00
cleanup
This commit is contained in:
parent
3162bb475d
commit
78fd0a4870
@ -14,7 +14,7 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef USE_WEBSERVER_OTA
|
||||
#if defined(USE_ESP_IDF) && defined(USE_WEBSERVER_OTA)
|
||||
#include "esphome/components/ota/ota_backend.h"
|
||||
#endif
|
||||
|
||||
@ -119,15 +119,17 @@ void OTARequestHandler::handleUpload(AsyncWebServerRequest *request, const Strin
|
||||
this->ota_started_ = false;
|
||||
|
||||
// Create OTA backend
|
||||
this->ota_backend_ = ota::make_ota_backend();
|
||||
auto backend = ota::make_ota_backend();
|
||||
|
||||
// Begin OTA with unknown size
|
||||
auto result = this->ota_backend_->begin(0);
|
||||
auto result = backend->begin(0);
|
||||
if (result != ota::OTA_RESPONSE_OK) {
|
||||
ESP_LOGE(TAG, "OTA begin failed: %d", result);
|
||||
this->ota_backend_.reset();
|
||||
return;
|
||||
}
|
||||
|
||||
// Store the backend pointer
|
||||
this->ota_backend_ = backend.release();
|
||||
this->ota_started_ = true;
|
||||
} else if (!this->ota_started_ || !this->ota_backend_) {
|
||||
// Begin failed or was aborted
|
||||
@ -136,11 +138,13 @@ void OTARequestHandler::handleUpload(AsyncWebServerRequest *request, const Strin
|
||||
|
||||
// Write data
|
||||
if (len > 0) {
|
||||
auto result = this->ota_backend_->write(data, len);
|
||||
auto *backend = static_cast<ota::OTABackend *>(this->ota_backend_);
|
||||
auto result = backend->write(data, len);
|
||||
if (result != ota::OTA_RESPONSE_OK) {
|
||||
ESP_LOGE(TAG, "OTA write failed: %d", result);
|
||||
this->ota_backend_->abort();
|
||||
this->ota_backend_.reset();
|
||||
backend->abort();
|
||||
delete backend;
|
||||
this->ota_backend_ = nullptr;
|
||||
this->ota_started_ = false;
|
||||
return;
|
||||
}
|
||||
@ -150,13 +154,15 @@ void OTARequestHandler::handleUpload(AsyncWebServerRequest *request, const Strin
|
||||
}
|
||||
|
||||
if (final) {
|
||||
auto result = this->ota_backend_->end();
|
||||
auto *backend = static_cast<ota::OTABackend *>(this->ota_backend_);
|
||||
auto result = backend->end();
|
||||
if (result == ota::OTA_RESPONSE_OK) {
|
||||
this->schedule_ota_reboot_();
|
||||
} else {
|
||||
ESP_LOGE(TAG, "OTA end failed: %d", result);
|
||||
}
|
||||
this->ota_backend_.reset();
|
||||
delete backend;
|
||||
this->ota_backend_ = nullptr;
|
||||
this->ota_started_ = false;
|
||||
}
|
||||
#endif // USE_ESP_IDF
|
||||
@ -176,8 +182,7 @@ void OTARequestHandler::handleRequest(AsyncWebServerRequest *request) {
|
||||
}
|
||||
#endif // USE_ARDUINO
|
||||
#ifdef USE_ESP_IDF
|
||||
response = request->beginResponse(
|
||||
200, "text/plain", (this->ota_started_ && this->ota_backend_) ? "Update Successful!" : "Update Failed!");
|
||||
response = request->beginResponse(200, "text/plain", this->ota_started_ ? "Update Successful!" : "Update Failed!");
|
||||
#endif // USE_ESP_IDF
|
||||
response->addHeader("Connection", "close");
|
||||
request->send(response);
|
||||
|
@ -148,8 +148,10 @@ class OTARequestHandler : public AsyncWebHandler {
|
||||
uint32_t ota_read_length_{0};
|
||||
#endif
|
||||
WebServerBase *parent_;
|
||||
|
||||
private:
|
||||
#if defined(USE_ESP_IDF) && defined(USE_WEBSERVER_OTA)
|
||||
std::unique_ptr<ota::OTABackend> ota_backend_;
|
||||
void *ota_backend_{nullptr}; // Actually ota::OTABackend*, stored as void* to avoid incomplete type issues
|
||||
bool ota_started_{false};
|
||||
#endif
|
||||
};
|
||||
|
@ -1,6 +1,5 @@
|
||||
from esphome.components.esp32 import add_idf_component, add_idf_sdkconfig_option
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import CONF_OTA
|
||||
from esphome.core import CORE
|
||||
|
||||
CODEOWNERS = ["@dentra"]
|
||||
@ -17,6 +16,6 @@ async def to_code(config):
|
||||
|
||||
# Check if web_server component has OTA enabled
|
||||
web_server_config = CORE.config.get("web_server", {})
|
||||
if web_server_config.get(CONF_OTA, True): # OTA is enabled by default
|
||||
# Add multipart parser component for OTA support
|
||||
if web_server_config and web_server_config.get("ota", True):
|
||||
# Add multipart parser component for ESP-IDF OTA support
|
||||
add_idf_component(name="zorxx/multipart-parser", ref="1.0.1")
|
||||
|
@ -9,13 +9,13 @@
|
||||
#include "esp_tls_crypto.h"
|
||||
|
||||
#include "utils.h"
|
||||
#include "web_server_idf.h"
|
||||
|
||||
#ifdef USE_WEBSERVER_OTA
|
||||
#include "multipart_reader.h"
|
||||
#include "multipart_parser_utils.h"
|
||||
#endif
|
||||
|
||||
#include "web_server_idf.h"
|
||||
|
||||
#ifdef USE_WEBSERVER
|
||||
#include "esphome/components/web_server/web_server.h"
|
||||
#include "esphome/components/web_server/list_entities.h"
|
||||
|
Loading…
x
Reference in New Issue
Block a user