Files
esphome/tests/components
Claude 227c46403b [bthome] Add BTHome v2 BLE protocol support
Implements native BTHome v2 protocol support for broadcasting sensor data
over BLE advertisements. This enables ESP32 devices to act as battery-powered
BLE sensors that are natively compatible with Home Assistant.

Features:
- Support for multiple sensor types (temperature, humidity, battery, etc.)
- Support for binary sensors (motion, door, window, etc.)
- AES-CCM encryption support with 16-byte keys
- Automatic packet encoding per BTHome v2 specification
- Dynamic advertisement updates when sensor values change
- Configurable advertising intervals and TX power
- Proper BTHome v2 device info byte and service UUID

Implementation:
- Python configuration for sensor/binary sensor mapping
- C++ component for BTHome packet encoding and BLE advertising
- mbedtls CCM encryption for secure advertisements
- Leverages existing esp32_ble infrastructure

Test coverage:
- Basic sensor/binary sensor configuration tests
- Encryption test configuration
- Multi-platform support (ESP32, ESP32-C3, ESP32-S3 with IDF)

Closes: https://github.com/orgs/esphome/discussions/3235
2025-11-17 21:42: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.