mirror of
https://github.com/esphome/esphome.git
synced 2025-04-10 21:00:31 +01:00
Enable esp32_ble_tracker
to stop_scan()
for all configured OTA platforms
This commit is contained in:
parent
c719b7203c
commit
4f8dd25478
@ -15,6 +15,7 @@ from esphome.const import (
|
||||
CONF_ON_BLE_ADVERTISE,
|
||||
CONF_ON_BLE_MANUFACTURER_DATA_ADVERTISE,
|
||||
CONF_ON_BLE_SERVICE_DATA_ADVERTISE,
|
||||
CONF_OTA,
|
||||
CONF_SERVICE_UUID,
|
||||
CONF_TRIGGER_ID,
|
||||
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_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_ESP32_BLE_CLIENT")
|
||||
|
||||
|
@ -17,10 +17,6 @@
|
||||
#include <nvs_flash.h>
|
||||
#include <cinttypes>
|
||||
|
||||
#ifdef USE_OTA
|
||||
#include "esphome/components/esphome/ota/ota_esphome.h"
|
||||
#endif
|
||||
|
||||
#ifdef USE_ARDUINO
|
||||
#include <esp32-hal-bt.h>
|
||||
#endif
|
||||
@ -58,11 +54,13 @@ void ESP32BLETracker::setup() {
|
||||
this->scanner_idle_ = true;
|
||||
|
||||
#ifdef USE_OTA
|
||||
esphome::global_ota_component->add_on_state_callback([this](ota::OTAState state, float progress, uint8_t error) {
|
||||
if (state == ota::OTA_STARTED) {
|
||||
this->stop_scan();
|
||||
}
|
||||
});
|
||||
for (auto &ota_comp : this->ota_components_) {
|
||||
ota_comp->add_on_state_callback([this](ota::OTAState state, float progress, uint8_t error) {
|
||||
if (state == ota::OTA_STARTED) {
|
||||
this->stop_scan();
|
||||
}
|
||||
});
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,10 @@
|
||||
|
||||
#ifdef USE_ESP32
|
||||
|
||||
#ifdef USE_OTA
|
||||
#include "esphome/components/ota/ota_backend.h"
|
||||
#endif
|
||||
|
||||
#include <esp_gap_ble_api.h>
|
||||
#include <esp_gattc_api.h>
|
||||
#include <esp_bt_defs.h>
|
||||
@ -197,6 +201,10 @@ class ESP32BLETracker : public Component,
|
||||
|
||||
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_client(ESPBTClient *client);
|
||||
void recalculate_advertisement_parser_types();
|
||||
@ -228,6 +236,11 @@ class ESP32BLETracker : public Component,
|
||||
|
||||
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
|
||||
std::vector<uint64_t> already_discovered_;
|
||||
std::vector<ESPBTDeviceListener *> listeners_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user