Files
esphome/tests/components
Claude 21539bdeba [bthome_ble] Add BTHome BLE packet parser component
Implements a BTHome v2 BLE advertisement parser component that allows ESPHome
to receive and parse sensor data from BTHome-compatible BLE devices.

Features:
- Parse BTHome v2 format BLE advertisements
- Support for sensors and binary sensors
- AES-CCM encryption support with 16-byte bind keys
- Independent sensor configuration (each sensor specifies MAC address and bind key)
- Supports 50+ BTHome object types including temperature, humidity, motion, door, etc.

Component structure:
- Main component: bthome_ble (BLE device listener)
- Sensor platform: supports numeric sensor types
- Binary sensor platform: supports boolean sensor types

Each sensor/binary_sensor independently listens for BLE advertisements from
the configured MAC address and extracts the specified object type. Multiple
sensors can monitor the same device by specifying the same MAC address and
bind key (if encrypted).

This is the complementary receiver component to the BTHome transmitter.
2025-11-18 20:31:08 +00:00
..
2025-09-26 08:53:21 +12:00
2025-11-03 18:29:30 -06:00

How to write C++ ESPHome unit tests

  1. Locate the folder with your component or create a new one with the same name as the component.
  2. Write the tests. You can add as many .cpp and .h files as you need to organize your tests.

IMPORTANT: wrap all your testing code in a unique namespace to avoid linker collisions when compiling testing binaries that combine many components. By convention, this unique namespace is esphome::component::testing (where "component" is the component under test), for example: esphome::uart::testing.

Running component unit tests

(from the repository root)

./script/cpp_unit_test.py component1 component2 ...

The above will compile and run the provided components and their tests.

To run all tests, you can invoke cpp_unit_test.py with the special --all flag:

./script/cpp_unit_test.py --all

To run a specific test suite, you can provide a Google Test filter:

GTEST_FILTER='UART*' ./script/cpp_unit_test.py uart modbus

The process will return 0 for success or nonzero for failure. In case of failure, the errors will be printed out to the console.