mirror of
https://github.com/esphome/esphome.git
synced 2025-08-10 12:27:46 +00:00
cleanup
This commit is contained in:
@@ -36,6 +36,16 @@ void OTARequestHandler::report_ota_progress_(AsyncWebServerRequest *request) {
|
|||||||
this->last_ota_progress_ = now;
|
this->last_ota_progress_ = now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OTARequestHandler::schedule_ota_reboot_() {
|
||||||
|
ESP_LOGI(TAG, "OTA update successful!");
|
||||||
|
this->parent_->set_timeout(100, []() { App.safe_reboot(); });
|
||||||
|
}
|
||||||
|
|
||||||
|
void OTARequestHandler::ota_init_(const char *filename) {
|
||||||
|
ESP_LOGI(TAG, "OTA Update Start: %s", filename);
|
||||||
|
this->ota_read_length_ = 0;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void WebServerBase::add_handler(AsyncWebHandler *handler) {
|
void WebServerBase::add_handler(AsyncWebHandler *handler) {
|
||||||
@@ -64,8 +74,7 @@ void OTARequestHandler::handleUpload(AsyncWebServerRequest *request, const Strin
|
|||||||
#ifdef USE_ARDUINO
|
#ifdef USE_ARDUINO
|
||||||
bool success;
|
bool success;
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
ESP_LOGI(TAG, "OTA Update Start: %s", filename.c_str());
|
this->ota_init_(filename.c_str());
|
||||||
this->ota_read_length_ = 0;
|
|
||||||
#ifdef USE_ESP8266
|
#ifdef USE_ESP8266
|
||||||
Update.runAsync(true);
|
Update.runAsync(true);
|
||||||
// NOLINTNEXTLINE(readability-static-accessed-through-instance)
|
// NOLINTNEXTLINE(readability-static-accessed-through-instance)
|
||||||
@@ -96,8 +105,7 @@ void OTARequestHandler::handleUpload(AsyncWebServerRequest *request, const Strin
|
|||||||
|
|
||||||
if (final) {
|
if (final) {
|
||||||
if (Update.end(true)) {
|
if (Update.end(true)) {
|
||||||
ESP_LOGI(TAG, "OTA update successful!");
|
this->schedule_ota_reboot_();
|
||||||
this->parent_->set_timeout(100, []() { App.safe_reboot(); });
|
|
||||||
} else {
|
} else {
|
||||||
report_ota_error();
|
report_ota_error();
|
||||||
}
|
}
|
||||||
@@ -107,8 +115,7 @@ void OTARequestHandler::handleUpload(AsyncWebServerRequest *request, const Strin
|
|||||||
#ifdef USE_ESP_IDF
|
#ifdef USE_ESP_IDF
|
||||||
// ESP-IDF implementation
|
// ESP-IDF implementation
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
ESP_LOGI(TAG, "OTA Update Start: %s", filename.c_str());
|
this->ota_init_(filename.c_str());
|
||||||
this->ota_read_length_ = 0;
|
|
||||||
this->ota_started_ = false;
|
this->ota_started_ = false;
|
||||||
|
|
||||||
// Create OTA backend
|
// Create OTA backend
|
||||||
@@ -145,8 +152,7 @@ void OTARequestHandler::handleUpload(AsyncWebServerRequest *request, const Strin
|
|||||||
if (final) {
|
if (final) {
|
||||||
auto result = this->ota_backend_->end();
|
auto result = this->ota_backend_->end();
|
||||||
if (result == ota::OTA_RESPONSE_OK) {
|
if (result == ota::OTA_RESPONSE_OK) {
|
||||||
ESP_LOGI(TAG, "OTA update successful!");
|
this->schedule_ota_reboot_();
|
||||||
this->parent_->set_timeout(100, []() { App.safe_reboot(); });
|
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGE(TAG, "OTA end failed: %d", result);
|
ESP_LOGE(TAG, "OTA end failed: %d", result);
|
||||||
}
|
}
|
||||||
|
@@ -141,6 +141,8 @@ class OTARequestHandler : public AsyncWebHandler {
|
|||||||
protected:
|
protected:
|
||||||
#ifdef USE_WEBSERVER_OTA
|
#ifdef USE_WEBSERVER_OTA
|
||||||
void report_ota_progress_(AsyncWebServerRequest *request);
|
void report_ota_progress_(AsyncWebServerRequest *request);
|
||||||
|
void schedule_ota_reboot_();
|
||||||
|
void ota_init_(const char *filename);
|
||||||
|
|
||||||
uint32_t last_ota_progress_{0};
|
uint32_t last_ota_progress_{0};
|
||||||
uint32_t ota_read_length_{0};
|
uint32_t ota_read_length_{0};
|
||||||
|
Reference in New Issue
Block a user