From 55407844d81a328638e4619daf2cf426401ae951 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 17 Nov 2025 23:08:29 +0000 Subject: [PATCH] [bthome] Optimize loop efficiency with disable_loop/enable_loop Use disable_loop() and enable_loop() to avoid running loop() when there's no immediate advertising work to do. The loop is disabled by default and only enabled when a sensor with advertise_immediately triggers, then disabled again after processing. --- esphome/components/bthome/bthome.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/esphome/components/bthome/bthome.cpp b/esphome/components/bthome/bthome.cpp index ab30fc4e91..259aee136d 100644 --- a/esphome/components/bthome/bthome.cpp +++ b/esphome/components/bthome/bthome.cpp @@ -96,6 +96,9 @@ void BTHome::setup() { } }); } + + // Start with loop disabled - only enable when immediate advertising is needed + this->disable_loop(); } void BTHome::loop() { @@ -107,6 +110,8 @@ void BTHome::loop() { this->build_advertisement_packets_(); this->current_packet_index_ = 0; this->on_advertise_(); + // Disable loop again until next immediate advertising request + this->disable_loop(); } } @@ -128,6 +133,8 @@ void BTHome::trigger_immediate_advertising_(uint8_t measurement_index, bool is_b this->immediate_advertising_pending_ = true; this->immediate_adv_measurement_index_ = measurement_index; this->immediate_adv_is_binary_ = is_binary; + // Enable loop to process immediate advertising + this->enable_loop(); } void BTHome::build_advertisement_packets_() {