1
0
mirror of https://github.com/esphome/esphome.git synced 2025-04-10 12:50:30 +01:00

Move make_ota_backend into the OTA backend

This commit is contained in:
Keith Burzinski 2024-04-11 00:18:16 -05:00
parent d88bee1a28
commit 91198556f6
No known key found for this signature in database
GPG Key ID: 802564C5F0EEFFBE
7 changed files with 13 additions and 21 deletions

View File

@ -24,26 +24,6 @@ static constexpr u_int16_t OTA_BLOCK_SIZE = 8192;
OTAESPHomeComponent *global_ota_component = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
std::unique_ptr<ota::OTABackend> make_ota_backend() {
#ifdef USE_ARDUINO
#ifdef USE_ESP8266
return make_unique<ota::ArduinoESP8266OTABackend>();
#endif // USE_ESP8266
#ifdef USE_ESP32
return make_unique<ota::ArduinoESP32OTABackend>();
#endif // USE_ESP32
#endif // USE_ARDUINO
#ifdef USE_ESP_IDF
return make_unique<ota::IDFOTABackend>();
#endif // USE_ESP_IDF
#ifdef USE_RP2040
return make_unique<ota::ArduinoRP2040OTABackend>();
#endif // USE_RP2040
#ifdef USE_LIBRETINY
return make_unique<ota::ArduinoLibreTinyOTABackend>();
#endif
}
OTAESPHomeComponent::OTAESPHomeComponent() { global_ota_component = this; }
void OTAESPHomeComponent::setup() {
@ -172,7 +152,7 @@ void OTAESPHomeComponent::handle_() {
buf[1] = USE_OTA_VERSION;
this->writeall_(buf, 2);
backend = make_ota_backend();
backend = ota::make_ota_backend();
// Read features - 1 byte
if (!this->readall_(buf, 1)) {

View File

@ -44,5 +44,7 @@ class OTABackend {
virtual bool supports_compression() = 0;
};
std::unique_ptr<ota::OTABackend> make_ota_backend();
} // namespace ota
} // namespace esphome

View File

@ -9,6 +9,8 @@
namespace esphome {
namespace ota {
std::unique_ptr<ota::OTABackend> make_ota_backend() { return make_unique<ota::ArduinoESP32OTABackend>(); }
OTAResponseTypes ArduinoESP32OTABackend::begin(size_t image_size) {
bool ret = Update.begin(image_size, U_FLASH);
if (ret) {

View File

@ -11,6 +11,8 @@
namespace esphome {
namespace ota {
std::unique_ptr<ota::OTABackend> make_ota_backend() { return make_unique<ota::ArduinoESP8266OTABackend>(); }
OTAResponseTypes ArduinoESP8266OTABackend::begin(size_t image_size) {
bool ret = Update.begin(image_size, U_FLASH);
if (ret) {

View File

@ -9,6 +9,8 @@
namespace esphome {
namespace ota {
std::unique_ptr<ota::OTABackend> make_ota_backend() { return make_unique<ota::ArduinoLibreTinyOTABackend>(); }
OTAResponseTypes ArduinoLibreTinyOTABackend::begin(size_t image_size) {
bool ret = Update.begin(image_size, U_FLASH);
if (ret) {

View File

@ -11,6 +11,8 @@
namespace esphome {
namespace ota {
std::unique_ptr<ota::OTABackend> make_ota_backend() { return make_unique<ota::ArduinoRP2040OTABackend>(); }
OTAResponseTypes ArduinoRP2040OTABackend::begin(size_t image_size) {
bool ret = Update.begin(image_size, U_FLASH);
if (ret) {

View File

@ -14,6 +14,8 @@
namespace esphome {
namespace ota {
std::unique_ptr<ota::OTABackend> make_ota_backend() { return make_unique<ota::IDFOTABackend>(); }
OTAResponseTypes IDFOTABackend::begin(size_t image_size) {
this->partition_ = esp_ota_get_next_update_partition(nullptr);
if (this->partition_ == nullptr) {