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

Fix persistence for devices with UNKWN00000000xxxx serial number #2220

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

vcelarde
Copy link

  • Replace randomly generated (UNKWN00000000xxxx) serial number for unknown devices (Default string, etc.) with a serial number generated by the unique device ID in the last element of the device path. This way the device will always get the same (unique) serial number and persistence will work correctly.
  • Original version worked fine, but since serial number was randomly generated on each startup, persistence did not work and the persistence.conf file fills up with settings from all the randomly generated serial numbers over time.

…own devices (Default string, etc.) with a serial number generated by the unique device ID in the last element of the device path. This way the device will always get the same (unique) serial number and persistence will work correctly.
@z3ntu
Copy link
Member

z3ntu commented Apr 4, 2024

Are you sure the serial numbers are consistent?

2024-04-04 21:20:53 | razer.device2                  | INFO     | Initialising device.2 RazerMambaElite
ERROR:root:random serial! 00031532006C0004

I unplugged and replugged the usb hub where my devices are connected and then the serial was different

2024-04-04 21:21:38 | razer.device2                  | INFO     | Initialising device.2 RazerMambaElite
ERROR:root:random serial! 00031532006C0010

("error" logging is added by me, diff attached)

diff --git a/daemon/openrazer_daemon/hardware/device_base.py b/daemon/openrazer_daemon/hardware/device_base.py
index 635f694b..fa332a01 100644
--- a/daemon/openrazer_daemon/hardware/device_base.py
+++ b/daemon/openrazer_daemon/hardware/device_base.py
@@ -974,8 +974,9 @@ class RazerDevice(DBusService):
                     time.sleep(0.1)
                     self.logger.debug('getting serial: {0} count:{1}'.format(serial, count))
 
-            if serial == '' or serial == 'Default string' or serial == 'empty (NULL)' or serial == 'As printed in the D cover':
-                serial = "".join([i for i in os.path.basename(self._device_path) if i.isalnum()])
+            #if serial == '' or serial == 'Default string' or serial == 'empty (NULL)' or serial == 'As printed in the D cover':
+            serial = "".join([i for i in os.path.basename(self._device_path) if i.isalnum()])
+            logging.error("random serial! " + str(serial))
 
             self._serial = serial.replace(' ', '_')
 

@vcelarde
Copy link
Author

vcelarde commented Jul 23, 2024

Thanks @z3ntu for taking a look. Yes, it is a weakness of this approach that if the serial number for a given device is randomly generated this will not work as far as maintaining persistence, however I will point out that it is no worse than the original version which ALWAYS generates a random device ID. For the devices I've tested (Razer Blade 16 RGB keyboard for example, which is not natively supported at the time of PR) I do see a consistent serial number per device and persistence does work in that case. I have not been able to find a device that generates a random serial number as you've demonstrated here. Perhaps it is specific to the brand/model of USB hub you are using?

  • Is there a better source of per-device unique identifier than the serial number that you can think of?
  • Also note that this fix is intended as a sort-of "stop gap" measure that at least allows persistence for non-natively supported devices until true support is rolled in and the UnknownID no longer applies. At least for devices with a consistent ID, this improves usability greatly in the interim.

@z3ntu
Copy link
Member

z3ntu commented Aug 31, 2024

One approach that could work well is generating the serial number from the USB VID/PID, so as a base e.g. UNKNOWN1532001A for 1532:001A. Since generally only one device of a given model is connected, this should be unproblematic for those cases but since I'm sure there will someone be connecting two (or more) of the same devices we probably need to have some logic of appending a number to it, so starting with 0 for the first device, and incrementing that if somebody connects two or more of the same. I'd say one digit is enough, so 10 or so of the same devices of the same model should be a decent limit.

For the general use case, I think we can assume the same device model connected over multiple starts will be the same device. For multiple it won't be possible to reliably identify them but that's okay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants