ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
ota_http_request.h
Go to the documentation of this file.
1#pragma once
2
7
8#include <memory>
9#include <string>
10#include <utility>
11
12#include "../http_request.h"
13
14namespace esphome::http_request {
15
16static const uint8_t MD5_SIZE = 32;
17
23
24class OtaHttpRequestComponent final : public ota::OTAComponent, public Parented<HttpRequestComponent> {
25 public:
26 void dump_config() override;
27 float get_setup_priority() const override { return setup_priority::AFTER_WIFI; }
28
29 void set_md5_url(const std::string &md5_url);
30 void set_md5(const std::string &md5) { this->get_request_().md5_expected = md5; }
31 void set_password(const std::string &password);
32 void set_url(const std::string &url);
33 void set_username(const std::string &username);
34
35 std::string md5_computed() { return this->request_ != nullptr ? this->request_->md5_computed : std::string(); }
36 std::string md5_expected() { return this->request_ != nullptr ? this->request_->md5_expected : std::string(); }
37
38 void flash();
39
40 protected:
42 struct Request {
43 std::string md5_computed;
44 std::string md5_expected;
45 std::string md5_url;
46 std::string password;
47 std::string username;
48 std::string url;
49 };
51
52 void cleanup_(ota::OTABackendPtr backend, const std::shared_ptr<HttpContainer> &container, bool abort_backend);
53 // Only reached from flash(), which returns early while request_ is null
54 uint8_t do_ota_();
55 std::string get_url_with_auth_(const std::string &url);
56 bool http_get_md5_();
57 bool validate_url_(const std::string &url);
58
59 std::unique_ptr<Request> request_;
60 int status_ = -1;
61 static const uint16_t HTTP_RECV_BUFFER = 256; // the firmware GET chunk size
62};
63
64} // namespace esphome::http_request
Helper class to easily give an object a parent of type T.
Definition helpers.h:2160
void cleanup_(ota::OTABackendPtr backend, const std::shared_ptr< HttpContainer > &container, bool abort_backend)
void set_password(const std::string &password)
void set_username(const std::string &username)
std::string get_url_with_auth_(const std::string &url)
void set_md5_url(const std::string &md5_url)
decltype(make_ota_backend()) OTABackendPtr
constexpr float AFTER_WIFI
For components that should be initialized after WiFi is connected.
Definition component.h:55
Allocated by the first setter, which only runs before a flash, and never freed, so a flash never lose...