diff --git a/esphome/components/api/api_server.cpp b/esphome/components/api/api_server.cpp index ddcccc0b6e..438283e826 100644 --- a/esphome/components/api/api_server.cpp +++ b/esphome/components/api/api_server.cpp @@ -199,8 +199,8 @@ void APIServer::loop() { #ifdef USE_API_NOISE // Refill only while no api client is still connecting; an OTA handshake is // not visible here and just pays the refill it triggered. -void APIServer::prepare_spare_ephemeral_() { - if (noise::has_spare_ephemeral() || !network::is_connected()) { +void APIServer::prepare_spare_ephemeral_slow_() { + if (!network::is_connected()) { return; } const uint32_t now = App.get_loop_component_start_time(); diff --git a/esphome/components/api/api_server.h b/esphome/components/api/api_server.h index 673def615a..5e5f472c1f 100644 --- a/esphome/components/api/api_server.h +++ b/esphome/components/api/api_server.h @@ -364,7 +364,13 @@ class APIServer final : public Component, #endif #ifdef USE_API_NOISE - void prepare_spare_ephemeral_(); + // Polled every loop tick: only the flag test stays inline + void prepare_spare_ephemeral_() { + if (!noise::has_spare_ephemeral()) { + this->prepare_spare_ephemeral_slow_(); + } + } + void prepare_spare_ephemeral_slow_(); noise::NoiseContext noise_ctx_; #ifndef USE_API_NOISE_PSK_FROM_YAML SavedNoisePsk saved_psk_{}; // backs noise_ctx_ for a runtime provisioned key