mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2026-10-31 22:02:17 +01:00
HTTP routes and MQTT commands now both build a shade request and submit it to the LoopQueue, which loop() drains into ShadeRequests. ShadeRequests finds the shade or group, turns client positions into stored ones, checks ranges and fills in default repeats, and reaches the shades through the ShadeOps seam: SomfyShadeOps on the device, a recording fake in the native tests. MqttCommands turns a .../set topic into a shade request. Behaviour that changes: - MQTT tiltTarget, mypos, myTiltPos and tiltPosition, and /setPositions, now honour flipPosition like the other routes. - MQTT mypos keeps the favorite tilt (was set to 0) and myTiltPos keeps the favorite lift. - repeat 0 on /shadeCommand means no repeats, as it did for groups; a JSON repeat over 127 is capped instead of wrapping to the default. - Position corrections go through the setters, so MQTT publishes them. - MQTT commands wait while the radio is full instead of being refused. - The queue is drained every loop() pass and no longer from inside a GitHub firmware download. WebCommand.h is replaced by LoopQueue.h and ShadeRequests.h. 45 new native tests, 271 in all. Flash: esp32devdbg +976 bytes, esp32dev +1,380 bytes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
78 lines
3.1 KiB
C++
78 lines
3.1 KiB
C++
#include <unity.h>
|
|
#include "LoopQueue.h"
|
|
|
|
static loop_item_t request(shade_request_type_t type) {
|
|
loop_item_t item;
|
|
item.request.type = type;
|
|
return item;
|
|
}
|
|
static loop_item_t item(loop_item_type_t type) {
|
|
loop_item_t item;
|
|
item.type = type;
|
|
return item;
|
|
}
|
|
|
|
static const shade_request_type_t RADIO_REQUESTS[] = {
|
|
shade_request_type_t::shade_command, shade_request_type_t::group_command, shade_request_type_t::tilt_command,
|
|
shade_request_type_t::shade_repeat, shade_request_type_t::group_repeat, shade_request_type_t::shade_sensor,
|
|
shade_request_type_t::group_sensor, shade_request_type_t::set_favorite, shade_request_type_t::unpair
|
|
};
|
|
static const shade_request_type_t OFF_RADIO_REQUESTS[] = {
|
|
shade_request_type_t::set_positions, shade_request_type_t::set_rolling_code
|
|
};
|
|
static const loop_item_type_t OTHER_ITEMS[] = { loop_item_type_t::restore_shades, loop_item_type_t::load_shades };
|
|
|
|
void setUp() {}
|
|
void tearDown() {}
|
|
|
|
static void test_only_position_and_rolling_code_requests_stay_off_the_radio() {
|
|
int offRadio = 0;
|
|
for(uint8_t t = 0; t <= static_cast<uint8_t>(shade_request_type_t::set_rolling_code); t++) {
|
|
if(!shadeRequestUsesRadio(static_cast<shade_request_type_t>(t))) offRadio++;
|
|
}
|
|
TEST_ASSERT_EQUAL_INT(2, offRadio);
|
|
for(shade_request_type_t t : OFF_RADIO_REQUESTS) TEST_ASSERT_FALSE(loopItemUsesRadio(request(t)));
|
|
for(loop_item_type_t t : OTHER_ITEMS) TEST_ASSERT_FALSE(loopItemUsesRadio(item(t)));
|
|
}
|
|
static void test_off_radio_items_are_never_held() {
|
|
// Nothing goes on air, so a full or suspended radio doesn't matter.
|
|
for(shade_request_type_t t : OFF_RADIO_REQUESTS) {
|
|
TEST_ASSERT_FALSE(holdLoopItem(request(t), false, false));
|
|
TEST_ASSERT_FALSE(holdLoopItem(request(t), true, false));
|
|
}
|
|
for(loop_item_type_t t : OTHER_ITEMS) {
|
|
TEST_ASSERT_FALSE(holdLoopItem(item(t), false, false));
|
|
TEST_ASSERT_FALSE(holdLoopItem(item(t), true, false));
|
|
}
|
|
}
|
|
static void test_radio_request_waits_for_room() {
|
|
for(shade_request_type_t t : RADIO_REQUESTS) {
|
|
TEST_ASSERT_TRUE(holdLoopItem(request(t), false, false));
|
|
TEST_ASSERT_FALSE(holdLoopItem(request(t), false, true));
|
|
}
|
|
}
|
|
static void test_requests_are_not_held_while_suspended() {
|
|
// Nothing goes on air during a frequency scan or OTA anyway.
|
|
for(shade_request_type_t t : RADIO_REQUESTS) {
|
|
if(t == shade_request_type_t::unpair) continue;
|
|
TEST_ASSERT_FALSE(holdLoopItem(request(t), true, false));
|
|
TEST_ASSERT_FALSE(holdLoopItem(request(t), true, true));
|
|
}
|
|
}
|
|
static void test_unpair_waits_out_a_suspend() {
|
|
// The client was already told the shade is unpaired.
|
|
TEST_ASSERT_TRUE(holdLoopItem(request(shade_request_type_t::unpair), true, false));
|
|
TEST_ASSERT_TRUE(holdLoopItem(request(shade_request_type_t::unpair), true, true));
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
(void)argc;
|
|
(void)argv;
|
|
UNITY_BEGIN();
|
|
RUN_TEST(test_only_position_and_rolling_code_requests_stay_off_the_radio);
|
|
RUN_TEST(test_off_radio_items_are_never_held);
|
|
RUN_TEST(test_radio_request_waits_for_room);
|
|
RUN_TEST(test_requests_are_not_held_while_suspended);
|
|
RUN_TEST(test_unpair_waits_out_a_suspend);
|
|
return UNITY_END();
|
|
}
|