1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-30 14:43:51 +00:00

Enable esp32_ble_tracker to stop_scan() for all configured OTA platforms

This commit is contained in:
Keith Burzinski
2024-04-28 21:50:53 -05:00
parent c719b7203c
commit 4f8dd25478
3 changed files with 26 additions and 9 deletions

View File

@@ -15,6 +15,7 @@ from esphome.const import (
CONF_ON_BLE_ADVERTISE, CONF_ON_BLE_ADVERTISE,
CONF_ON_BLE_MANUFACTURER_DATA_ADVERTISE, CONF_ON_BLE_MANUFACTURER_DATA_ADVERTISE,
CONF_ON_BLE_SERVICE_DATA_ADVERTISE, CONF_ON_BLE_SERVICE_DATA_ADVERTISE,
CONF_OTA,
CONF_SERVICE_UUID, CONF_SERVICE_UUID,
CONF_TRIGGER_ID, CONF_TRIGGER_ID,
KEY_CORE, KEY_CORE,
@@ -272,6 +273,11 @@ async def to_code(config):
add_idf_sdkconfig_option("CONFIG_BTU_TASK_STACK_SIZE", 8192) add_idf_sdkconfig_option("CONFIG_BTU_TASK_STACK_SIZE", 8192)
add_idf_sdkconfig_option("CONFIG_BT_ACL_CONNECTIONS", 9) add_idf_sdkconfig_option("CONFIG_BT_ACL_CONNECTIONS", 9)
if CONF_OTA in CORE.config:
for ota_config in CORE.config.get(CONF_OTA):
ota_platform = await cg.get_variable(ota_config[CONF_ID])
cg.add(var.add_ota_component(ota_platform))
cg.add_define("USE_OTA_STATE_CALLBACK") # To be notified when an OTA update starts cg.add_define("USE_OTA_STATE_CALLBACK") # To be notified when an OTA update starts
cg.add_define("USE_ESP32_BLE_CLIENT") cg.add_define("USE_ESP32_BLE_CLIENT")

View File

@@ -17,10 +17,6 @@
#include <nvs_flash.h> #include <nvs_flash.h>
#include <cinttypes> #include <cinttypes>
#ifdef USE_OTA
#include "esphome/components/esphome/ota/ota_esphome.h"
#endif
#ifdef USE_ARDUINO #ifdef USE_ARDUINO
#include <esp32-hal-bt.h> #include <esp32-hal-bt.h>
#endif #endif
@@ -58,11 +54,13 @@ void ESP32BLETracker::setup() {
this->scanner_idle_ = true; this->scanner_idle_ = true;
#ifdef USE_OTA #ifdef USE_OTA
esphome::global_ota_component->add_on_state_callback([this](ota::OTAState state, float progress, uint8_t error) { for (auto &ota_comp : this->ota_components_) {
if (state == ota::OTA_STARTED) { ota_comp->add_on_state_callback([this](ota::OTAState state, float progress, uint8_t error) {
this->stop_scan(); if (state == ota::OTA_STARTED) {
} this->stop_scan();
}); }
});
}
#endif #endif
} }

View File

@@ -11,6 +11,10 @@
#ifdef USE_ESP32 #ifdef USE_ESP32
#ifdef USE_OTA
#include "esphome/components/ota/ota_backend.h"
#endif
#include <esp_gap_ble_api.h> #include <esp_gap_ble_api.h>
#include <esp_gattc_api.h> #include <esp_gattc_api.h>
#include <esp_bt_defs.h> #include <esp_bt_defs.h>
@@ -197,6 +201,10 @@ class ESP32BLETracker : public Component,
void loop() override; void loop() override;
#ifdef USE_OTA
void add_ota_component(ota::OTAComponent *ota_component) { this->ota_components_.push_back(ota_component); }
#endif
void register_listener(ESPBTDeviceListener *listener); void register_listener(ESPBTDeviceListener *listener);
void register_client(ESPBTClient *client); void register_client(ESPBTClient *client);
void recalculate_advertisement_parser_types(); void recalculate_advertisement_parser_types();
@@ -228,6 +236,11 @@ class ESP32BLETracker : public Component,
int app_id_; int app_id_;
#ifdef USE_OTA
/// Vector of OTA components we'll hook into so we can stop scanning when an OTA update begins
std::vector<ota::OTAComponent *> ota_components_{};
#endif
/// Vector of addresses that have already been printed in print_bt_device_info /// Vector of addresses that have already been printed in print_bt_device_info
std::vector<uint64_t> already_discovered_; std::vector<uint64_t> already_discovered_;
std::vector<ESPBTDeviceListener *> listeners_; std::vector<ESPBTDeviceListener *> listeners_;