From e5f6e5f09fda2f75b76eaff56a3d4a2e79b6422a Mon Sep 17 00:00:00 2001 From: clydebarrow <2366188+clydebarrow@users.noreply.github.com> Date: Sun, 18 Oct 2026 20:41:36 +1100 Subject: [PATCH] [sx126x][sx127x] Take the packet size at construction The radio links have no buffer of their own, so code generation passes the configured max_packet_size to the constructor. Co-Authored-By: Claude Code --- esphome/components/sx126x/packet_interface/__init__.py | 2 +- .../sx126x/packet_interface/sx126x_packet_interface.h | 3 ++- esphome/components/sx127x/packet_interface/__init__.py | 2 +- .../sx127x/packet_interface/sx127x_packet_interface.h | 3 ++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/esphome/components/sx126x/packet_interface/__init__.py b/esphome/components/sx126x/packet_interface/__init__.py index e28cfb31f37..9fad6a60df6 100644 --- a/esphome/components/sx126x/packet_interface/__init__.py +++ b/esphome/components/sx126x/packet_interface/__init__.py @@ -52,7 +52,7 @@ FINAL_VALIDATE_SCHEMA = _final_validate async def to_code(config: ConfigType) -> None: radio = await cg.get_variable(config[CONF_SX126X_ID]) - var = await new_packet_interface(config, radio) + var = await new_packet_interface(config, radio, config[CONF_MAX_PACKET_SIZE]) radio_config = next( conf for conf in CORE.config[DOMAIN] if conf[CONF_ID] == config[CONF_SX126X_ID] ) diff --git a/esphome/components/sx126x/packet_interface/sx126x_packet_interface.h b/esphome/components/sx126x/packet_interface/sx126x_packet_interface.h index d5b5d99ae74..571fffb46d8 100644 --- a/esphome/components/sx126x/packet_interface/sx126x_packet_interface.h +++ b/esphome/components/sx126x/packet_interface/sx126x_packet_interface.h @@ -11,7 +11,8 @@ namespace esphome::sx126x { /// sends, so sending is refused while the radio is receiving a packet; the layers above send again shortly. class SX126xPacketInterface : public packet_interface::PacketInterface, public SX126xListener { public: - explicit SX126xPacketInterface(SX126x *radio) : radio_(radio) {} + SX126xPacketInterface(SX126x *radio, size_t max_packet_size) + : packet_interface::PacketInterface(max_packet_size), radio_(radio) {} void setup() override { this->radio_->register_listener(this); } void set_max_busy(uint32_t max_busy_ms) { this->listen_before_talk_.set_max_busy(max_busy_ms); } diff --git a/esphome/components/sx127x/packet_interface/__init__.py b/esphome/components/sx127x/packet_interface/__init__.py index 103b001b0ca..43c24bd216c 100644 --- a/esphome/components/sx127x/packet_interface/__init__.py +++ b/esphome/components/sx127x/packet_interface/__init__.py @@ -66,7 +66,7 @@ FINAL_VALIDATE_SCHEMA = _final_validate async def to_code(config: ConfigType) -> None: radio = await cg.get_variable(config[CONF_SX127X_ID]) - var = await new_packet_interface(config, radio) + var = await new_packet_interface(config, radio, config[CONF_MAX_PACKET_SIZE]) radio_config = next( conf for conf in CORE.config[DOMAIN] if conf[CONF_ID] == config[CONF_SX127X_ID] ) diff --git a/esphome/components/sx127x/packet_interface/sx127x_packet_interface.h b/esphome/components/sx127x/packet_interface/sx127x_packet_interface.h index 30196001382..827d41bffcb 100644 --- a/esphome/components/sx127x/packet_interface/sx127x_packet_interface.h +++ b/esphome/components/sx127x/packet_interface/sx127x_packet_interface.h @@ -11,7 +11,8 @@ namespace esphome::sx127x { /// sends, so sending is refused while the radio is receiving a packet; the layers above send again shortly. class SX127xPacketInterface : public packet_interface::PacketInterface, public SX127xListener { public: - explicit SX127xPacketInterface(SX127x *radio) : radio_(radio) {} + SX127xPacketInterface(SX127x *radio, size_t max_packet_size) + : packet_interface::PacketInterface(max_packet_size), radio_(radio) {} void setup() override { this->radio_->register_listener(this); } void set_max_busy(uint32_t max_busy_ms) { this->listen_before_talk_.set_max_busy(max_busy_ms); }