mirror of
https://github.com/esphome/esphome.git
synced 2026-08-24 07:06:20 +00:00
Monotonic parse flag, client-scoped opt-out, drop dead include
This commit is contained in:
committed by
J. Nick Koston
parent
b1e1b0d7c5
commit
7ec366c1ba
@@ -479,11 +479,6 @@ esp_err_t BluetoothConnection::notify_characteristic(uint16_t handle, bool enabl
|
||||
return this->check_and_log_error_("esp_ble_gattc_unregister_for_notify", err);
|
||||
}
|
||||
|
||||
bool BluetoothConnection::wants_parsed_advertisements() {
|
||||
// The proxy's connections never consume parsed ESPBTDevice objects.
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace esphome::bluetooth_connection
|
||||
|
||||
#endif // USE_ESP32
|
||||
|
||||
@@ -21,7 +21,8 @@ class BluetoothConnection final : public esp32_ble_client::BLEClientBase {
|
||||
bool gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
|
||||
esp_ble_gattc_cb_param_t *param) override;
|
||||
void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) override;
|
||||
bool wants_parsed_advertisements() override;
|
||||
// The proxy's connections never consume parsed ESPBTDevice objects.
|
||||
bool wants_parsed_advertisements() override { return false; }
|
||||
|
||||
esp_err_t read_characteristic(uint16_t handle);
|
||||
esp_err_t write_characteristic(uint16_t handle, const uint8_t *data, size_t length, bool response);
|
||||
|
||||
@@ -20,9 +20,6 @@
|
||||
|
||||
#include "esphome/components/bluetooth_connection/bluetooth_connection_esp32.h"
|
||||
|
||||
#ifndef CONFIG_ESP_HOSTED_ENABLE_BT_BLUEDROID
|
||||
#include <esp_bt.h>
|
||||
#endif
|
||||
#else
|
||||
#include "esphome/components/ble_device_base/ble_hub.h"
|
||||
#ifdef USE_BLE_GATT_CLIENT
|
||||
|
||||
@@ -271,7 +271,9 @@ void ESP32BLETracker::register_client(ESPBTClient *client) {
|
||||
// Safe because ESP32BLETracker (singleton) outlives all registered clients.
|
||||
client->set_tracker_state_version(&this->state_version_);
|
||||
this->clients_.push_back(client);
|
||||
this->recalculate_parse_advertisements_();
|
||||
// Registration is add-only, so the flag is a monotonic OR.
|
||||
if (client->wants_parsed_advertisements())
|
||||
this->parse_advertisements_ = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -294,30 +296,7 @@ void ESP32BLETracker::register_listener(ESPBTDeviceListener *listener) {
|
||||
#ifdef ESPHOME_ESP32_BLE_TRACKER_LISTENER_COUNT
|
||||
listener->set_parent(this);
|
||||
this->listeners_.push_back(listener);
|
||||
this->recalculate_parse_advertisements_();
|
||||
#endif
|
||||
}
|
||||
|
||||
void ESP32BLETracker::recalculate_parse_advertisements_() {
|
||||
this->parse_advertisements_ = false;
|
||||
#ifdef ESPHOME_BLE_DEVICE_BASE_LISTENER_COUNT
|
||||
// Neutral (BLEHub) listeners are parsed-advertisement consumers and are not in
|
||||
// listeners_; without this, any later esp32-path registration (e.g. the proxy's
|
||||
// GATT clients) would recompute the flag and silently drop parsed dispatch.
|
||||
if (!this->neutral_listeners_.empty())
|
||||
this->parse_advertisements_ = true;
|
||||
#endif
|
||||
#ifdef ESPHOME_ESP32_BLE_TRACKER_LISTENER_COUNT
|
||||
for (auto *listener : this->listeners_) {
|
||||
if (listener->wants_parsed_advertisements())
|
||||
this->parse_advertisements_ = true;
|
||||
}
|
||||
#endif
|
||||
#ifdef ESPHOME_ESP32_BLE_TRACKER_CLIENT_COUNT
|
||||
for (auto *client : this->clients_) {
|
||||
if (client->wants_parsed_advertisements())
|
||||
this->parse_advertisements_ = true;
|
||||
}
|
||||
this->parse_advertisements_ = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -58,9 +58,6 @@ class ESPBTDeviceListener : public ble_device_base::ESPBTDeviceListener {
|
||||
// Raw-only build: no parsed-device support is compiled in.
|
||||
bool parse_device(const ble_device_base::ESPBTDevice &device) override { return false; }
|
||||
#endif
|
||||
/// False keeps the tracker from building parsed ESPBTDevice objects on
|
||||
/// this registrant's account (raw consumers use the hub callback).
|
||||
virtual bool wants_parsed_advertisements() { return true; }
|
||||
void set_parent(ESP32BLETracker *parent) { parent_ = parent; }
|
||||
|
||||
protected:
|
||||
@@ -116,6 +113,11 @@ class BLEScannerStateListener {
|
||||
/// increment the counter through this pointer when their state changes.
|
||||
/// The pointer may be null if the client is not registered with a tracker.
|
||||
class ESPBTClient : public ESPBTDeviceListener {
|
||||
public:
|
||||
/// False keeps the tracker from building parsed ESPBTDevice objects on
|
||||
/// this client's account (raw consumers use the hub callback).
|
||||
virtual bool wants_parsed_advertisements() { return true; }
|
||||
|
||||
public:
|
||||
virtual bool gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
|
||||
esp_ble_gattc_cb_param_t *param) = 0;
|
||||
@@ -250,7 +252,6 @@ class ESP32BLETracker final : public Component,
|
||||
void gap_scan_stop_complete_(const esp_ble_gap_cb_param_t::ble_scan_stop_cmpl_evt_param ¶m);
|
||||
/// Called to set the scanner state. Will also call callbacks to let listeners know when state is changed.
|
||||
void set_scanner_state_(ScannerState state);
|
||||
void recalculate_parse_advertisements_();
|
||||
/// Common cleanup logic when transitioning scanner to IDLE state
|
||||
void cleanup_scan_state_(bool is_stop_complete);
|
||||
/// Process a single scan result immediately
|
||||
|
||||
Reference in New Issue
Block a user