Skip to content

Fix: repeating group length inference must include nested subgroup points - #120

Open
LinusCrugnola wants to merge 2 commits into
sunspec:masterfrom
LinusCrugnola:master
Open

LinusCrugnola wants to merge 2 commits into
sunspec:masterfrom
LinusCrugnola:master

Conversation

@LinusCrugnola

Copy link
Copy Markdown

Fixes #119

Group._init_repeating_group's legacy count-inference path (used when a repeating group's count can't be read directly from its count point, so the count is derived from total model length instead) divided by g.points_len, which only counts a group's own direct points and ignores any nested repeating subgroup.

This breaks models where a repeating group nests another repeating group, e.g. model 705's Crv group nesting a Pt group for curve points. With 2 curves of 2 points each, each Crv instance is actually 14 registers (10 own + 2×2 from Pt), but points_len reports only 10, so device.scan() raised ModelError: Repeating group count not consistent with model length for model 705, model repeating len = 28, model repeating group len = 10.

g.len is the fully-resolved length of one group instance including nested subgroups, and is the correct divisor. For groups with no nested subgroups g.len == g.points_len, so this is a no-op for the common case.

Added a regression test (test__init_repeating_group_legacy_count_nested_group) that reproduces the exact reported error against the old logic and passes against the fix.

hilman2 added a commit to hilman2/ha-sunspec2 that referenced this pull request Sep 1, 2026
…s included (#72)

When a repeating group's count point reads 0, pysunspec2 infers the
count from the model length: repeating registers divided by the length
of one group instance. It divided by points_len, which counts only the
group's own points and ignores any repeating subgroup nested inside.
Model 705, the volt-var curves, is exactly that shape: each Crv holds
its own ten registers plus NPt curve points of two registers each. With
two points per curve the real instance is 14 registers, points_len said
10, and the scan raised "Repeating group count not consistent with
model length". A device that exposes 705 lost every model behind it in
the chain.

g.len is the resolved length of one instance, subgroups included, and
equals points_len for a group without them, so the change is a no-op
for every other model. This is sunspec/pysunspec2#120, unmerged
upstream since August; the regression test is theirs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Repeating group model length mismatch for 705 model

1 participant