Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usb: PyUsbDevice addresses need to be strings #743

Closed

Conversation

nmalaguti
Copy link
Contributor

@nmalaguti nmalaguti commented Nov 14, 2024

The cli treats addresses as strings, but the USB address is an integer. It needs to be converted to a string for the comparison to work.

This also changes the output from --json status.


Checklist:

New CLI flag?

  • Adjust the completion scripts in extra/completions/

New device?

  • Regenerate extra/linux/71-liquidctl.rules (instructions in the file header)
  • Add entry to the README's supported device list with applicable notes and git MRLV

New driver?

  • Document the protocol in docs/developer/protocol/

@jonasmalacofilho
Copy link
Member

Nice catch.

Maybe

diff --git a/liquidctl/driver/usb.py b/liquidctl/driver/usb.py
index 27ff346f0f0a..fecacc283eae 100644
--- a/liquidctl/driver/usb.py
+++ b/liquidctl/driver/usb.py
@@ -376,7 +376,7 @@ class PyUsbDevice:
 
     @property
     def address(self):
-        return self.usbdev.address
+        return str(self.usbdev.address)
 
     @property
     def port(self):

could be a better fix for it, though.

Is it still enough to fix the real world issue for you?

@nmalaguti
Copy link
Contributor Author

Is it still enough to fix the real world issue for you?

I'll test it out, but looking at the code almost certainly yes (and that's a better fix too).

@nmalaguti
Copy link
Contributor Author

Confirmed the fix worked. It might be a small breaking change because the --json output now outputs the address as a string instead of a number.

@nmalaguti nmalaguti force-pushed the feature/usb-address-string branch from 23fa956 to ffe24e3 Compare November 15, 2024 18:59
@nmalaguti nmalaguti changed the title usb: USB address comparisons need to be strings usb: PyUsbDevice addresses need to be strings Nov 15, 2024
The cli treats addresses as strings, but the USB address is an integer.
It needs to be converted to a string for the comparison to work.

This also changes the output from `--json status`.
@nmalaguti nmalaguti force-pushed the feature/usb-address-string branch from ffe24e3 to 1317a27 Compare November 15, 2024 19:01
@jonasmalacofilho
Copy link
Member

It might be a small breaking change because the --json output now outputs the address as a string instead of a number.

Forgot about that... and it also breaks the public API. And even though the change is small, it will likely require downstream changes anyway, because listing and filtering devices is a very basic feature.

I'll take your original fix to avoid the unnecessary breaking changes. Thanks!

(I'll manually merge your original commit).

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