fix: give out ids up to the maximum

New ids stopped two short of the limits, at 30 shades, 14 groups and 14
rooms instead of 32, 16 and 16, while the web UI showed the full limits.
The original loop ran i < MAX - 1, an off-by-one: nothing indexes by id
or treats the last two ids as special. ModelSnapshot's next-id answers
and SomfyShadeController's allocation now run from 1 to the maximum.
Found during LOOP_QUEUE_PLAN.md's review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
cjkas 2026-10-17 23:03:16 +02:00
parent bee6a6d60b
commit e4ac7a29c6
3 changed files with 17 additions and 8 deletions

View file

@ -242,9 +242,17 @@ static void test_next_group() {
TEST_ASSERT_EQUAL_STRING("{\"groupId\":1,\"remoteAddress\":78,\"bitLength\":0,\"proto\":0}",
document(snapshot_doc_t::nextGroup).c_str());
}
static void test_no_room_for_another_shade() {
static void test_the_last_ids_are_given_out() {
// Ids used to stop two short: 30 shades where the limit says 32.
snap.shadeCount = 0;
for(uint8_t id = 1; id <= SOMFY_MAX_SHADES - 2; id++) snap.shades[snap.shadeCount++] = shade(id, "S");
TEST_ASSERT_EQUAL_UINT8(SOMFY_MAX_SHADES - 1, nextShadeId(snap));
snap.shades[snap.shadeCount++] = shade(SOMFY_MAX_SHADES - 1, "S");
TEST_ASSERT_EQUAL_UINT8(SOMFY_MAX_SHADES, nextShadeId(snap));
}
static void test_no_room_for_another_shade() {
snap.shadeCount = 0;
for(uint8_t id = 1; id <= SOMFY_MAX_SHADES; id++) snap.shades[snap.shadeCount++] = shade(id, "S");
TEST_ASSERT_EQUAL_UINT8(255, nextShadeId(snap));
}
static void test_group_options_lists_the_shades_not_in_it() {
@ -334,6 +342,7 @@ int main(int argc, char **argv) {
RUN_TEST(test_next_shade);
RUN_TEST(test_next_address_skips_one_already_used);
RUN_TEST(test_next_group);
RUN_TEST(test_the_last_ids_are_given_out);
RUN_TEST(test_no_room_for_another_shade);
RUN_TEST(test_group_options_lists_the_shades_not_in_it);
RUN_TEST(test_group_options_of_a_group_gone_by_the_snapshot);