ESPHome  2024.12.2
ota_backend.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/defines.h"
5 #include "esphome/core/helpers.h"
6 
7 #ifdef USE_OTA_STATE_CALLBACK
9 #endif
10 
11 namespace esphome {
12 namespace ota {
13 
17 
26 
41 };
42 
43 enum OTAState {
49 };
50 
51 class OTABackend {
52  public:
53  virtual ~OTABackend() = default;
54  virtual OTAResponseTypes begin(size_t image_size) = 0;
55  virtual void set_update_md5(const char *md5) = 0;
56  virtual OTAResponseTypes write(uint8_t *data, size_t len) = 0;
57  virtual OTAResponseTypes end() = 0;
58  virtual void abort() = 0;
59  virtual bool supports_compression() = 0;
60 };
61 
62 class OTAComponent : public Component {
63 #ifdef USE_OTA_STATE_CALLBACK
64  public:
65  void add_on_state_callback(std::function<void(ota::OTAState, float, uint8_t)> &&callback) {
66  this->state_callback_.add(std::move(callback));
67  }
68 
69  protected:
71 #endif
72 };
73 
74 #ifdef USE_OTA_STATE_CALLBACK
76  public:
77  void register_ota(OTAComponent *ota_caller) {
78  ota_caller->add_on_state_callback([this, ota_caller](OTAState state, float progress, uint8_t error) {
79  this->state_callback_.call(state, progress, error, ota_caller);
80  });
81  }
82  void add_on_state_callback(std::function<void(OTAState, float, uint8_t, OTAComponent *)> &&callback) {
83  this->state_callback_.add(std::move(callback));
84  }
85 
86  protected:
88 };
89 
91 void register_ota_platform(OTAComponent *ota_caller);
92 #endif
93 std::unique_ptr<ota::OTABackend> make_ota_backend();
94 
95 } // namespace ota
96 } // namespace esphome
virtual void set_update_md5(const char *md5)=0
virtual OTAResponseTypes end()=0
virtual bool supports_compression()=0
void register_ota_platform(OTAComponent *ota_caller)
Definition: ota_backend.cpp:16
void add_on_state_callback(std::function< void(ota::OTAState, float, uint8_t)> &&callback)
Definition: ota_backend.h:65
virtual void abort()=0
std::unique_ptr< ota::OTABackend > make_ota_backend()
virtual OTAResponseTypes write(uint8_t *data, size_t len)=0
void add_on_state_callback(std::function< void(OTAState, float, uint8_t, OTAComponent *)> &&callback)
Definition: ota_backend.h:82
virtual OTAResponseTypes begin(size_t image_size)=0
std::string size_t len
Definition: helpers.h:293
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void register_ota(OTAComponent *ota_caller)
Definition: ota_backend.h:77
virtual ~OTABackend()=default
OTAGlobalCallback * get_global_ota_callback()
Definition: ota_backend.cpp:9
bool state
Definition: fan.h:34