mirror of
https://github.com/esphome/esphome.git
synced 2026-08-24 15:16:20 +00:00
Merge branch 'esp32-tracker-retire-scanner-listener' into esp32-hub-devirtualize
This commit is contained in:
@@ -674,7 +674,7 @@ void ESP32BLE::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gat
|
||||
}
|
||||
#endif
|
||||
|
||||
void ESP32BLE::get_mac_msb_first(uint8_t out[6]) {
|
||||
void ESP32BLE::get_mac_msb_first(uint8_t out[6]) const {
|
||||
// The running stack owns the address (on hosted controllers it lives in
|
||||
// the remote chip's efuse); null before init becomes all-zero.
|
||||
const uint8_t *mac = esp_bt_dev_get_address();
|
||||
|
||||
@@ -109,7 +109,7 @@ class ESP32BLE final : public Component {
|
||||
void loop() override;
|
||||
void dump_config() override;
|
||||
/// Adapter MAC in printable (MSB-first) order; all-zero until the stack is up.
|
||||
void get_mac_msb_first(uint8_t out[6]);
|
||||
void get_mac_msb_first(uint8_t out[6]) const;
|
||||
float get_setup_priority() const override;
|
||||
void set_name(const char *name) { this->name_ = name; }
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "esphome/components/ble_device_base/ble_hub.h"
|
||||
|
||||
namespace esphome::ble_device_base::testing {
|
||||
|
||||
// Pins the ScannerStateCallback slot semantics, mirroring test_raw_callback:
|
||||
// a default-constructed slot is "no subscriber", a set slot delivers the
|
||||
// state, and a new registration replaces the old.
|
||||
namespace {
|
||||
|
||||
struct CapturingSubscriber {
|
||||
ScannerState last{ScannerState::IDLE};
|
||||
int calls{0};
|
||||
|
||||
static void trampoline(void *self, ScannerState state) {
|
||||
auto *sub = static_cast<CapturingSubscriber *>(self);
|
||||
sub->last = state;
|
||||
sub->calls++;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(ScannerStateCallback, DefaultConstructedSlotIsNotSet) {
|
||||
const ScannerStateCallback callback{};
|
||||
EXPECT_FALSE(callback.is_set());
|
||||
}
|
||||
|
||||
TEST(ScannerStateCallback, SubscriberSeesState) {
|
||||
CapturingSubscriber subscriber;
|
||||
ScannerStateCallback callback{&subscriber, CapturingSubscriber::trampoline};
|
||||
ASSERT_TRUE(callback.is_set());
|
||||
callback.invoke(ScannerState::RUNNING);
|
||||
EXPECT_EQ(subscriber.calls, 1);
|
||||
EXPECT_EQ(subscriber.last, ScannerState::RUNNING);
|
||||
}
|
||||
|
||||
TEST(ScannerStateCallback, NewSubscriberReplacesOld) {
|
||||
CapturingSubscriber first;
|
||||
CapturingSubscriber second;
|
||||
ScannerStateCallback callback{&first, CapturingSubscriber::trampoline};
|
||||
callback = {&second, CapturingSubscriber::trampoline};
|
||||
callback.invoke(ScannerState::STOPPED);
|
||||
EXPECT_EQ(first.calls, 0);
|
||||
EXPECT_EQ(second.calls, 1);
|
||||
EXPECT_EQ(second.last, ScannerState::STOPPED);
|
||||
}
|
||||
|
||||
} // namespace esphome::ble_device_base::testing
|
||||
Reference in New Issue
Block a user