From 28233180c967e84f1efb4188ed3010fe730732dd Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 7 Sep 2025 08:27:25 -0500 Subject: [PATCH 1/2] tidy --- esphome/components/api/api_frame_helper_plaintext.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/esphome/components/api/api_frame_helper_plaintext.cpp b/esphome/components/api/api_frame_helper_plaintext.cpp index 59daf49bfc..ceb573d562 100644 --- a/esphome/components/api/api_frame_helper_plaintext.cpp +++ b/esphome/components/api/api_frame_helper_plaintext.cpp @@ -202,15 +202,15 @@ APIError APIPlaintextFrameHelper::read_packet(ReadPacketBuffer *buffer) { // a message after the indicator byte to ensures its long // enough and can aid in debugging. #ifdef USE_ESP8266 - static const char msg_progmem[] PROGMEM = "\x00" + static const char MSG_PROGMEM[] PROGMEM = "\x00" "Bad indicator byte"; char msg[19]; - memcpy_P(msg, msg_progmem, 19); + memcpy_P(msg, MSG_PROGMEM, 19); iov[0].iov_base = (void *) msg; #else - static const char msg[] = "\x00" + static const char MSG[] = "\x00" "Bad indicator byte"; - iov[0].iov_base = (void *) msg; + iov[0].iov_base = (void *) MSG; #endif iov[0].iov_len = 19; this->write_raw_(iov, 1, 19); From 424e0a97b26c2f8194b3fb73d71cfa06bd6fd3bc Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 7 Sep 2025 18:23:03 -0500 Subject: [PATCH 2/2] const --- esphome/components/api/api_frame_helper_plaintext.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/esphome/components/api/api_frame_helper_plaintext.cpp b/esphome/components/api/api_frame_helper_plaintext.cpp index ceb573d562..859bb26630 100644 --- a/esphome/components/api/api_frame_helper_plaintext.cpp +++ b/esphome/components/api/api_frame_helper_plaintext.cpp @@ -201,19 +201,20 @@ APIError APIPlaintextFrameHelper::read_packet(ReadPacketBuffer *buffer) { // We must send at least 3 bytes to be read, so we add // a message after the indicator byte to ensures its long // enough and can aid in debugging. + static constexpr uint8_t INDICATOR_MSG_SIZE = 19; #ifdef USE_ESP8266 static const char MSG_PROGMEM[] PROGMEM = "\x00" "Bad indicator byte"; - char msg[19]; - memcpy_P(msg, MSG_PROGMEM, 19); + char msg[INDICATOR_MSG_SIZE]; + memcpy_P(msg, MSG_PROGMEM, INDICATOR_MSG_SIZE); iov[0].iov_base = (void *) msg; #else static const char MSG[] = "\x00" "Bad indicator byte"; iov[0].iov_base = (void *) MSG; #endif - iov[0].iov_len = 19; - this->write_raw_(iov, 1, 19); + iov[0].iov_len = INDICATOR_MSG_SIZE; + this->write_raw_(iov, 1, INDICATOR_MSG_SIZE); } return aerr; }