diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index be87dac6f6..9666b7e9ff 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -105,7 +105,7 @@ class ProtoVarInt { /// Parse a varint from buffer. consumed must be a valid pointer (not null). static optional 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 diff --git a/esphome/core/defines.h b/esphome/core/defines.h index 0c888933bf..a2a967985e 100644 --- a/esphome/core/defines.h +++ b/esphome/core/defines.h @@ -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 diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 50e8d4122b..36df1bc83e 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -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', )