1
0
mirror of https://github.com/esphome/esphome.git synced 2026-02-08 00:31:58 +00:00

[esp32_hosted] Replace set_retry with set_interval to avoid heap allocation

set_retry internally does a std::make_shared<RetryArgs>() heap allocation
on every invocation. Replace with set_interval + countdown counter which
avoids this entirely. The original code used fixed-interval polling
(no backoff), making set_interval a direct fit.
This commit is contained in:
J. Nick Koston
2026-02-07 14:18:23 -06:00
parent 9de91539e6
commit 4d2354da2e
2 changed files with 10 additions and 6 deletions

View File

@@ -127,15 +127,18 @@ void Esp32HostedUpdate::setup() {
this->status_clear_error();
this->publish_state();
#else
// HTTP mode: retry initial check every 10s until network is ready (max 6 attempts)
// HTTP mode: check every 10s until network is ready (max 6 attempts)
// Only if update interval is > 1 minute to avoid redundant checks
if (this->get_update_interval() > 60000) {
this->set_retry("initial_check", 10000, 6, [this](uint8_t) {
if (!network::is_connected()) {
return RetryResult::RETRY;
this->initial_check_remaining_ = 6;
this->set_interval("initial_check", 10000, [this]() {
bool connected = network::is_connected();
if (--this->initial_check_remaining_ == 0 || connected) {
this->cancel_interval("initial_check");
if (connected) {
this->check();
}
}
this->check();
return RetryResult::DONE;
});
}
#endif

View File

@@ -44,6 +44,7 @@ class Esp32HostedUpdate : public update::UpdateEntity, public PollingComponent {
// HTTP mode helpers
bool fetch_manifest_();
bool stream_firmware_to_coprocessor_();
uint8_t initial_check_remaining_{0};
#else
// Embedded mode members
const uint8_t *firmware_data_{nullptr};