Skip to content
Permalink
Browse files

[FIX] hw_drivers: Avoid duplicates identifiers in devices

Before this commit the identifier integrate the BUS and port to identifiate USB devices
Now we check if there are duplicates devices before increment the identifier

For other loop we add identifier in the iot_device object
  • Loading branch information...
qle-odoo committed Apr 4, 2019
1 parent 0b9d752 commit 45527dd2481544bbee753eaca71ee6cac6014b64
Showing with 22 additions and 4 deletions.
  1. +22 −4 addons/hw_drivers/controllers/driver.py
@@ -143,7 +143,7 @@ def device_name(self):

@property
def device_identifier(self):
return self._device_identifier
return self.dev.identifier

@property
def device_connection(self):
@@ -300,12 +300,28 @@ def send_alldevices(self):
_logger.warning('Odoo server not set')

def usb_loop(self):
"""
USB devices are identified by a combination of their `idVendor` and
`idProduct`. We can't be sure this combination in unique per equipment.
To still allow connecting multiple similar equipments, we complete the
identifier by a counter. The drawbacks are we can't be sure the equipments
will get the same identifiers after a reboot or a disconnect/reconnect.
Loops over the connected usb devices, assign them an identifier, instantiate
an `IoTDevice` for them.
:return: a dict of the `IoTDevices` instances indexed by their identifier.
"""
usb_devices = {}
devs = core.find(find_all=True)
cpt = 2
for dev in devs:
path = "usb_%04x:%04x_%03d_%03d_" % (dev.idVendor, dev.idProduct, dev.bus, dev.address)
dev.identifier = "usb_%04x:%04x" % (dev.idVendor, dev.idProduct)
if dev.identifier in usb_devices:
dev.identifier += '_%s' % cpt
cpt += 1
iot_device = IoTDevice(dev, 'usb')
usb_devices[path] = iot_device
usb_devices[dev.identifier] = iot_device
return usb_devices

def video_loop(self):
@@ -316,8 +332,9 @@ def video_loop(self):
dev = v4l2.v4l2_capability()
ioctl(path, v4l2.VIDIOC_QUERYCAP, dev)
dev.interface = video
dev.identifier = dev.bus_info.decode('utf-8')
iot_device = IoTDevice(dev, 'video')
camera_devices[dev.bus_info.decode('utf-8')] = iot_device
camera_devices[dev.identifier] = iot_device
return camera_devices

def printer_loop(self):
@@ -376,6 +393,7 @@ def device_discovered(self, device):
path = "bt_%s" % (device.mac_address,)
if path not in bt_devices:
device.manager = self
device.identifier = path
iot_device = IoTDevice(device, 'bluetooth')
bt_devices[path] = iot_device

0 comments on commit 45527dd

Please sign in to comment.
You can’t perform that action at this time.