mirror of
https://github.com/esphome/esphome.git
synced 2026-09-11 15:27:33 +00:00
Keep advertising start/stop decisions in one place
advertising_stop() now just drops its request and lets advertising_refresh() decide, so both sides are symmetric and only refresh knows when the radio should be advertising.
This commit is contained in:
@@ -107,19 +107,19 @@ void ESP32BLE::advertising_start() {
|
||||
void ESP32BLE::advertising_stop() {
|
||||
if (this->advertising_ref_count_ == 0)
|
||||
return;
|
||||
// Keep advertising while another component still needs it
|
||||
if (--this->advertising_ref_count_ > 0)
|
||||
return;
|
||||
if (this->advertising_ == nullptr || !this->is_active())
|
||||
return;
|
||||
this->advertising_->stop();
|
||||
this->advertising_ref_count_--;
|
||||
this->advertising_refresh();
|
||||
}
|
||||
|
||||
void ESP32BLE::advertising_refresh() {
|
||||
if (this->advertising_ref_count_ == 0 || !this->is_active())
|
||||
if (this->advertising_ == nullptr || !this->is_active())
|
||||
return;
|
||||
this->advertising_init_();
|
||||
this->advertising_->start();
|
||||
// Advertise while any component still needs it, otherwise stop
|
||||
if (this->advertising_ref_count_ == 0) {
|
||||
this->advertising_->stop();
|
||||
} else {
|
||||
this->advertising_->start();
|
||||
}
|
||||
}
|
||||
|
||||
void ESP32BLE::advertising_set_service_data(const std::vector<uint8_t> &data) {
|
||||
|
||||
@@ -123,7 +123,7 @@ class ESP32BLE final : public Component {
|
||||
void advertising_start();
|
||||
/// Release a request made with advertising_start(); advertising stops at the last release.
|
||||
void advertising_stop();
|
||||
/// Re-apply the advertising payload, restarting advertising only if it is still requested.
|
||||
/// Apply the current payload and request count: advertise while requested, otherwise stop.
|
||||
void advertising_refresh();
|
||||
void advertising_set_service_data(const std::vector<uint8_t> &data);
|
||||
void advertising_set_manufacturer_data(const std::vector<uint8_t> &data);
|
||||
|
||||
Reference in New Issue
Block a user