21#include <initializer_list>
25#if defined(__cpp_lib_span)
33#include <esp_bt_defs.h>
41static constexpr uint8_t BLE_ADDR_TYPE_PUBLIC = 0;
42static constexpr uint8_t BLE_ADDR_TYPE_RANDOM = 1;
43static constexpr uint8_t BLE_ADDR_TYPE_RPA_PUBLIC = 2;
44static constexpr uint8_t BLE_ADDR_TYPE_RPA_RANDOM = 3;
47static constexpr size_t UUID_STR_LEN = 37;
71 return from_raw(
reinterpret_cast<const char *
>(data.begin()), data.size());
84 bool contains(uint8_t data1, uint8_t data2)
const;
91 const char *
to_str(
char *buf)
const;
92#if defined(__cpp_lib_span)
93 const char *
to_str(std::span<char, UUID_STR_LEN> output)
const {
return this->
to_str(output.data()); }
149 uint8_t proximity_uuid[16];
162 for (
int i = 0; i < 6; i++)
163 addr |=
static_cast<uint64_t
>(mac[i]) << (i * 8);
170 for (
int i = 0; i < 6; i++)
171 out[i] = (
address >> ((5 - i) * 8)) & 0xFF;
182 void from_scan_result(
const uint8_t *mac,
int rssi, uint8_t addr_type,
const uint8_t *data, uint16_t data_len);
188 ESPDEPRECATED(
"Use address_str_to() instead. Removed in 2027.2.0.",
"2026.8.0")
189 std::
string address_str() const;
192#if defined(__cpp_lib_span)
193 const char *
address_str_to(std::span<char, MAC_ADDRESS_PRETTY_BUFFER_SIZE> buf)
const {
StringRef is a reference to a string owned by something else.
Per-scan-period "Found device" DEBUG logger, deduplicated by MAC address.
std::vector< uint64_t > already_discovered_
void clear()
Reset the per-period dedup list (call when a scan period ends).
void log_device(const char *tag, const ESPBTDevice &device)
Log the device at DEBUG the first time its MAC is seen this scan period.
uint16_t get_major() const
int8_t get_signal_power() const
static optional< ESPBLEiBeacon > from_manufacturer_data(const ServiceData &data, bool *prefix_rejected=nullptr)
prefix_rejected: caller must initialise to false; set to true ONLY when a 23-byte Apple frame was ref...
ESPBTUUID get_uuid() const
uint16_t get_minor() const
struct PACKED esphome::ble_device_base::ESPBLEiBeacon::BeaconData beacon_data_
ESPDEPRECATED("Use address_str_to() instead. Removed in 2027.2.0.", "2026.8.0") std const char * address_str_to(char *buf) const
Return MAC as "XX:XX:XX:XX:XX:XX" string.
void parse_scan_rst(const esp32_ble::BLEScanResult &scan_result)
Historical esp32 ingest (esp32 builds only): parse an ESP-IDF scan result.
const optional< uint8_t > & get_ad_flag() const
const std::vector< ESPBTUUID > & get_service_uuids() const
const uint8_t * address() const
Raw MAC bytes in printable (MSB-first) order — matches the historical esp32 layout (ESP-IDF bda order...
std::vector< ESPBTUUID > service_uuids_
std::vector< int8_t > tx_powers_
const optional< uint16_t > & get_appearance() const
const std::vector< int8_t > & get_tx_powers() const
optional< uint16_t > appearance_
void from_scan_result(const uint8_t *mac, int rssi, uint8_t addr_type, const uint8_t *data, uint16_t data_len)
Populate from a raw scan result delivered by a BLE tracker backend.
static constexpr size_t MAC_ADDRESS_PRETTY_BUFFER_SIZE
esp_ble_addr_type_t get_address_type() const
char name_[MAX_ADV_NAME_LEN+1]
void parse_adv_(const uint8_t *payload, uint16_t len)
std::vector< ServiceData > service_datas_
const esp32_ble::BLEScanResult * scan_result_
std::vector< ServiceData > manufacturer_datas_
const char * address_str_to(std::span< char, MAC_ADDRESS_PRETTY_BUFFER_SIZE > buf) const
optional< ESPBLEiBeacon > get_ibeacon() const
uint8_t get_address_type() const
uint64_t address_uint64() const
Return MAC as packed uint64 (byte 0 in LSB — matches esp32's address_uint64).
const char * address_type_str() const
Human-readable address type ("PUBLIC", "RANDOM", "RPA_PUBLIC", "RPA_RANDOM" or "UNKNOWN"),...
const std::vector< ServiceData > & get_service_datas() const
const std::vector< ServiceData > & get_manufacturer_datas() const
uint8_t address_[MAC_ADDRESS_SIZE]
const esp32_ble::BLEScanResult & get_scan_result() const
static constexpr uint8_t MAX_ADV_NAME_LEN
StringRef get_name() const
Advertised name as a view into the fixed buffer (always NUL-terminated, so c_str() is safe); converts...
bool resolve_irk(const uint8_t *irk) const
Resolve a Resolvable Private Address against a 16-byte IRK (Bluetooth "ah" function,...
optional< uint8_t > ad_flag_
virtual void on_scan_end()
Called at the end of each scan duration period.
virtual ~ESPBTDeviceListener()=default
virtual bool parse_device(const ESPBTDevice &device)=0
static ESPBTUUID from_uuid(esp_bt_uuid_t uuid)
Source compatibility with the historical esp32_ble API (esp32 builds only).
const char * to_str(std::span< char, UUID_STR_LEN > output) const
static ESPBTUUID from_uint16(uint16_t uuid)
static ESPBTUUID from_raw(const char *data)
static ESPBTUUID from_raw(const std::string &data)
static ESPBTUUID from_raw(const uint8_t *data)
Construct from raw 16-byte little-endian UUID.
bool contains(uint8_t data1, uint8_t data2) const
True if the UUID value contains the adjacent byte pair (data1, data2).
void to_128bit_(uint8_t out[16]) const
esp_bt_uuid_t get_uuid() const
static ESPBTUUID from_raw_reversed(const uint8_t *data)
Construct from raw 16-byte big-endian UUID (reversed on store).
union esphome::ble_device_base::ESPBTUUID::@21 uuid_
static ESPBTUUID from_raw(std::initializer_list< uint8_t > data)
static ESPBTUUID from_uint32(uint32_t uuid)
bool operator!=(const ESPBTUUID &other) const
bool is_set() const
True if a UUID has been configured (not default-constructed).
ESPBTUUID as_128bit() const
Expand to the 128-bit Bluetooth Base UUID form.
const uint8_t * uuid128() const
bool operator==(const ESPBTUUID &other) const
const char * to_str(char *buf) const
Write "0xABCD" / "0xABCDEF01" / the dashed 128-bit form, or "None" for an unset UUID,...
std::vector< uint8_t > adv_data_t
uint64_t mac_lsb_first_to_uint64(const uint8_t *mac)
Pack a controller-order (LSB-first) MAC into the uint64 the API speaks.
void uint64_to_mac_msb_first(uint64_t address, uint8_t out[6])
Unpack a uint64 BLE address into printable (MSB-first) byte order — the order bd_addr_t / esp_bd_addr...
ESPDEPRECATED("Use LightState::gamma_correct_lut() instead. Removed in 2026.9.0.", "2026.3.0") float gamma_correct(float value
Applies gamma correction of gamma to value.
uint8_t proximity_uuid[16]