From 8a07d4204b5ba484c6ffe8a749db4486fb75b867 Mon Sep 17 00:00:00 2001 From: clydebarrow <2366188+clydebarrow@users.noreply.github.com> Date: Tue, 20 Oct 2026 09:35:38 +1100 Subject: [PATCH] [sx126x][sx127x] Stop reading a radio that fails while sends are held back Also drop a leftover preamble_detect key from a test case. Co-Authored-By: Claude Opus 5.5 --- esphome/components/packet_interface/radio_link.h | 5 +++-- tests/components/packet_interface/radio_link.cpp | 10 ++++++++++ tests/unit_tests/test_lora_packet_interface.py | 1 - 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/esphome/components/packet_interface/radio_link.h b/esphome/components/packet_interface/radio_link.h index 823a9819016..5a7d3bf87e1 100644 --- a/esphome/components/packet_interface/radio_link.h +++ b/esphome/components/packet_interface/radio_link.h @@ -49,9 +49,10 @@ class RadioLink : public RadioLinkBase, public Listener { this->radio_->register_listener(this); this->disable_loop(); } - // Runs only during a busy period; a busy flag that never clears keeps it running + // Runs only during a busy period; a busy flag that never clears keeps it running. A radio that failed meanwhile + // is not read again, as reading it may wait on the radio every time void loop() override { - if (!this->radio_->is_receiving()) + if (!this->radio_->is_ready() || !this->radio_->is_receiving()) this->radio_free_(); } diff --git a/tests/components/packet_interface/radio_link.cpp b/tests/components/packet_interface/radio_link.cpp index a2a3275784a..4867d134bc1 100644 --- a/tests/components/packet_interface/radio_link.cpp +++ b/tests/components/packet_interface/radio_link.cpp @@ -105,6 +105,16 @@ TEST_F(RadioLinkTest, FailedRadioRefusesSends) { EXPECT_TRUE(this->radio_.sent.empty()); } +TEST_F(RadioLinkTest, RadioFailingWhileBusyEndsBusyPeriod) { + set_time(START); + this->radio_.receiving = true; + EXPECT_FALSE(this->send_()); + EXPECT_TRUE(this->link_.is_in_loop_state()); + this->radio_.fail(); + this->link_.loop(); + EXPECT_TRUE(this->link_.is_idle()); +} + TEST_F(RadioLinkTest, ReceivedPacketCarriesSignal) { Packet received; PacketMetaData meta; diff --git a/tests/unit_tests/test_lora_packet_interface.py b/tests/unit_tests/test_lora_packet_interface.py index c0c90799d56..442384cc3b6 100644 --- a/tests/unit_tests/test_lora_packet_interface.py +++ b/tests/unit_tests/test_lora_packet_interface.py @@ -137,7 +137,6 @@ class _FullConfig(dict): "packet_mode": True, "payload_length": 0, "sync_value": [], - "preamble_detect": 0, }, {}, "sync_value",