Skip to content

Fix TypeError in the multi-register write_sensor_register path - #74

Open
nikicat wants to merge 1 commit into
goodix-fp-linux-dev:masterfrom
nikicat:fix-write-sensor-register
Open

Fix TypeError in the multi-register write_sensor_register path#74
nikicat wants to merge 1 commit into
goodix-fp-linux-dev:masterfrom
nikicat:fix-write-sensor-register

Conversation

@nikicat

@nikicat nikicat commented Aug 6, 2026

Copy link
Copy Markdown

length is len(address), an int, so iterating it raises:

length = len(address)
...
for i in length:          # TypeError: 'int' object is not iterable

The single-register path (address passed as an int) is the only one any driver in this repo uses, which is why this has gone unnoticed. Passing a list — the documented alternative, per the int | list[int] annotation — fails immediately:

>>> device.write_sensor_register([0x0220, 0x0236], [b"\x78\x0b", b"\xb9\x00"])
TypeError: 'int' object is not iterable

With range(length) it builds the expected payload:

01 20 02 78 0b 36 02 b9 00

Not exercised against hardware — I have no driver that writes multiple registers in one call — but the previous code could not run at all, so this can only be an improvement.

Independent of #72 and #73; branches from master.

`length` is `len(address)`, an int, so iterating it raises:

    TypeError: 'int' object is not iterable

The single-register path (address passed as an int) is the only one any
driver in this repo uses, which is why this has gone unnoticed. Passing a
list of addresses -- the documented alternative, per the `int | list[int]`
annotation -- fails immediately.

    >>> device.write_sensor_register([0x0220, 0x0236], [b"\x78\x0b", b"\xb9\x00"])
    TypeError: 'int' object is not iterable

With `range(length)` it builds the expected payload:

    01 20 02 78 0b 36 02 b9 00

Not exercised against hardware -- I have no driver that writes multiple
registers in one call -- but the previous code could not run at all.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

1 participant