Use ESPHOME_DEBUG_API guard instead of DEBUG

CI compile tests also define DEBUG, so a dedicated guard is needed.
Enable ESPHOME_DEBUG_API in integration tests via conftest.py.
This commit is contained in:
J. Nick Koston
2026-02-11 11:34:14 -06:00
parent e63308aa33
commit 242d152edc
3 changed files with 4 additions and 2 deletions
+2 -2
View File
@@ -105,7 +105,7 @@ class ProtoVarInt {
/// Parse a varint from buffer. consumed must be a valid pointer (not null).
static optional<ProtoVarInt> parse(const uint8_t *buffer, uint32_t len, uint32_t *consumed) {
#ifdef DEBUG
#ifdef ESPHOME_DEBUG_API
assert(consumed != nullptr);
#endif
if (len == 0)
@@ -922,7 +922,7 @@ inline void ProtoWriteBuffer::encode_message(uint32_t field_id, const ProtoMessa
// Now encode the message content - it will append to the buffer
value.encode(*this);
#ifdef DEBUG
#ifdef ESPHOME_DEBUG_API
// Verify that the encoded size matches what we calculated
assert(this->buffer_->size() == begin + varint_length_bytes + msg_length_bytes);
#endif
+1
View File
@@ -14,6 +14,7 @@
#define ESPHOME_PROJECT_VERSION_30 "v2"
#define ESPHOME_VARIANT "ESP32"
#define ESPHOME_DEBUG_SCHEDULER
#define ESPHOME_DEBUG_API
// Default threading model for static analysis (ESP32 is multi-threaded with atomics)
#define ESPHOME_THREAD_MULTI_ATOMICS
+1
View File
@@ -197,6 +197,7 @@ async def yaml_config(request: pytest.FixtureRequest, unused_tcp_port: int) -> s
" platformio_options:\n"
" build_flags:\n"
' - "-DDEBUG" # Enable assert() statements\n'
' - "-DESPHOME_DEBUG_API" # Enable API protocol asserts\n'
' - "-g" # Add debug symbols',
)