Fix TypeError in the multi-register write_sensor_register path - #74
Open
nikicat wants to merge 1 commit into
Open
Fix TypeError in the multi-register write_sensor_register path#74nikicat wants to merge 1 commit into
nikicat wants to merge 1 commit into
Conversation
`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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
lengthislen(address), anint, so iterating it raises:The single-register path (
addresspassed as anint) is the only one any driver in this repo uses, which is why this has gone unnoticed. Passing a list — the documented alternative, per theint | list[int]annotation — fails immediately:With
range(length)it builds the expected payload: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.