Skip to content

Conversation

@danudey
Copy link
Contributor

@danudey danudey commented Oct 17, 2025

This fix gracefully handles i2c devices which we do not have permissions to open; this means that we no longer have to have every i2c device on the system accessible by the current user in order to use the tool.

@danudey
Copy link
Contributor Author

danudey commented Oct 17, 2025

Coveralls tests seems to be due to adding more lines to a chunk of code which was already untested. That code probably should be tested, but I'm not yet sure the most optimal way to do so.

Copy link
Owner

@newAM newAM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes! Sorry for the slow review, this got buried at the bottom of my inbox.

Coveralls tests seems to be due to adding more lines to a chunk of code which was already untested. That code probably should be tested, but I'm not yet sure the most optimal way to do so.

That's fine, small decreases are ok by me. I should probably change the threshold.

except (OSError, VCPIOError):
pass
except VCPPermissionError as exc:
logging.error("Unable to check i2c device: %s", exc)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logging.error("Unable to check i2c device: %s", exc)
logging.exception("Unable to check i2c device")

This adds native exception info into the logging record.

Comment on lines +396 to +400
else:
logging.error(
"Unable to check i2c device %s: no device number found", device
)
continue
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am curious, have you seen this occur? pyudev should only return None if the device number is not a unicode string: https://github.com/pyudev/pyudev/blob/7588bc8c84bf1e994b31020452124bc6618625ce/src/pyudev/device/_device.py#L626-L651

for device in pyudev.Context().list_devices(subsystem="i2c"):
vcp = LinuxVCP(device.sys_number)
try:
if sys_no := device.sys_number:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if sys_no := device.sys_number:
if (sys_no := device.sys_number) is None:

I think 0 is a valid device.sys_number.

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.

2 participants