From 50ff87849857b04ebe90fa810fdc366a287d85f8 Mon Sep 17 00:00:00 2001 From: cjkas Date: Tue, 13 Oct 2026 15:33:49 +0200 Subject: [PATCH] fix: hold an unpair while radio TX is suspended /unpairShade answers paired:false as soon as the unpair is queued. If TX was suspended before loop() reached it, the Prog was dropped and the shade stayed paired, with nothing to tell the client. The unpair now waits in the queue until TX resumes. Co-Authored-By: Claude Opus 5.5 --- src/Web.cpp | 3 ++- src/WebCommand.h | 6 ++++-- test/test_webcmd/test_webcmd.cpp | 11 +++++++++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Web.cpp b/src/Web.cpp index d9a2bdd..07cf46a 100644 --- a/src/Web.cpp +++ b/src/Web.cpp @@ -311,7 +311,8 @@ static void serializeShadeRef(SomfyShade *shade, JsonFormatter &json) { json.addElem("repeats", shade->repeats); } // paired is passed in for a response that reports the change the main loop -// is about to make. +// is about to make. The unpair is held until it goes on air (holdWebCommand), +// so the answer comes true. static void serializeShade(SomfyShade *shade, JsonFormatter &json, bool paired) { json.addElem("shadeId", shade->getShadeId()); json.addElem("roomId", shade->roomId); diff --git a/src/WebCommand.h b/src/WebCommand.h index e1c473c..982a4c8 100644 --- a/src/WebCommand.h +++ b/src/WebCommand.h @@ -43,8 +43,10 @@ inline bool webCommandUsesRadio(web_cmd_t type) { return type != web_cmd_t::set_ // Whether the command at the head of the queue waits for the radio. The // client was already told it was accepted so it stays queued until the radio // has room rather than have the radio drop it. While TX is suspended nothing -// gets through anyway so nothing is held back then. +// gets through anyway so nothing is held back then, except an unpair: the +// client was told the shade is unpaired, so it waits until TX resumes. inline bool holdWebCommand(web_cmd_t type, bool txSuspended, bool txHasRoom) { - return webCommandUsesRadio(type) && !txSuspended && !txHasRoom; + if(txSuspended) return type == web_cmd_t::unpair_shade; + return webCommandUsesRadio(type) && !txHasRoom; } #endif diff --git a/test/test_webcmd/test_webcmd.cpp b/test/test_webcmd/test_webcmd.cpp index c6a7514..7073ad2 100644 --- a/test/test_webcmd/test_webcmd.cpp +++ b/test/test_webcmd/test_webcmd.cpp @@ -28,13 +28,19 @@ static void test_radio_command_waits_for_room() { TEST_ASSERT_FALSE(holdWebCommand(t, false, true)); } } -static void test_nothing_is_held_while_suspended() { +static void test_commands_are_not_held_while_suspended() { // Nothing goes on air during a frequency scan or OTA anyway. for(web_cmd_t t : RADIO_COMMANDS) { + if(t == web_cmd_t::unpair_shade) continue; TEST_ASSERT_FALSE(holdWebCommand(t, true, false)); TEST_ASSERT_FALSE(holdWebCommand(t, true, true)); } } +static void test_unpair_waits_out_a_suspend() { + // The client was already told the shade is unpaired. + TEST_ASSERT_TRUE(holdWebCommand(web_cmd_t::unpair_shade, true, false)); + TEST_ASSERT_TRUE(holdWebCommand(web_cmd_t::unpair_shade, true, true)); +} int main(int argc, char **argv) { (void)argc; @@ -43,6 +49,7 @@ int main(int argc, char **argv) { RUN_TEST(test_only_set_positions_stays_off_the_radio); RUN_TEST(test_set_positions_is_never_held); RUN_TEST(test_radio_command_waits_for_room); - RUN_TEST(test_nothing_is_held_while_suspended); + RUN_TEST(test_commands_are_not_held_while_suspended); + RUN_TEST(test_unpair_waits_out_a_suspend); return UNITY_END(); }