From c432ab146fad2cab46b21c698d29d00cdb58a83b Mon Sep 17 00:00:00 2001 From: kbx81 Date: Thu, 3 Sep 2026 01:16:55 -0500 Subject: [PATCH] [serial_proxy] Compile out mode state in builds without a tap PROTOCOL is refused when no tap exists, so mode_ could never leave RAW there; gate the member and reset_mode_() behind USE_SERIAL_PROXY_TAP (no-op inline otherwise), saving the member and the four reset calls in every tapless build. --- esphome/components/serial_proxy/serial_proxy.cpp | 4 ++-- esphome/components/serial_proxy/serial_proxy.h | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/esphome/components/serial_proxy/serial_proxy.cpp b/esphome/components/serial_proxy/serial_proxy.cpp index 416deddc92..129745c1c9 100644 --- a/esphome/components/serial_proxy/serial_proxy.cpp +++ b/esphome/components/serial_proxy/serial_proxy.cpp @@ -43,6 +43,7 @@ void SerialProxy::setup() { this->disable_loop(); } +#ifdef USE_SERIAL_PROXY_TAP void SerialProxy::reset_mode_() { // The mode belongs to a session, not to the port. Carrying a departed client's choice // over to the next one would inject protocol bytes into a stream that never asked for @@ -55,6 +56,7 @@ void SerialProxy::reset_mode_() { ESP_LOGD(TAG, "Session ended, returning serial proxy [%" PRIu32 "] to RAW mode", this->instance_index_); this->mode_ = api::enums::SERIAL_PROXY_MODE_RAW; } +#endif void SerialProxy::loop() { #ifdef USE_API @@ -261,10 +263,8 @@ SerialProxyResult SerialProxy::set_mode_from_client(api::APIConnection *api_conn #ifdef USE_SERIAL_PROXY_TAP const bool leaving_protocol_mode = this->mode_ != api::enums::SERIAL_PROXY_MODE_RAW && mode == api::enums::SERIAL_PROXY_MODE_RAW; -#endif this->mode_ = mode; -#ifdef USE_SERIAL_PROXY_TAP // Only for an explicit client request, not for reset_mode_() at the end of a session: // an ordinary disconnect says nothing about the device, whereas a client deliberately // asking for raw bytes usually precedes changing what the device is. diff --git a/esphome/components/serial_proxy/serial_proxy.h b/esphome/components/serial_proxy/serial_proxy.h index e7b28c0221..e3f4264cfa 100644 --- a/esphome/components/serial_proxy/serial_proxy.h +++ b/esphome/components/serial_proxy/serial_proxy.h @@ -204,9 +204,14 @@ class SerialProxy final : public uart::UARTDevice, public Component { bool is_subscriber_(api::APIConnection *api_connection) const { return this->api_connection_ == api_connection; } #endif - /// Return the port to RAW when a subscriber goes away, so the mode never outlives it. - /// Not tap-gated: the mode is a client-visible property whether or not a tap acts on it. +#ifdef USE_SERIAL_PROXY_TAP + /// Return the port to RAW when a subscriber goes away, so the mode never outlives it void reset_mode_(); +#else + /// Without a tap, PROTOCOL is refused, so the mode is fixed at RAW and there is + /// nothing to reset + void reset_mode_() {} +#endif #ifdef USE_SERIAL_PROXY_TAP /// True when the tap should be shown the traffic passing through this port @@ -230,8 +235,10 @@ class SerialProxy final : public uart::UARTDevice, public Component { /// Port type api::enums::SerialProxyPortType port_type_{}; +#ifdef USE_SERIAL_PROXY_TAP /// How the bytes passing through are treated; zero is SERIAL_PROXY_MODE_RAW api::enums::SerialProxyMode mode_{}; +#endif /// Optional GPIO pins for modem control GPIOPin *rts_pin_{nullptr};