Currently it is only possible to run the modules for the IoT Box on Raspios. The modifications brought by this commit brings the possibility that the various hw_* modules can be executed whatever the OS of the hardware (Linux or Windows). If the modules should be versioned according to the OS, the file will be renamed so that the end of the file includes *_L (for linux) or *_W (for windows) closes odoo/odoo#107350 X-original-commit: b7b8809ea8b7fe4ac8b24f43fe3f3a5e38a66696 Related: odoo/enterprise#34713 Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
30 lines
1.0 KiB
Python
30 lines
1.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from usb import core
|
|
|
|
from odoo.addons.hw_drivers.interface import Interface
|
|
|
|
|
|
class USBInterface(Interface):
|
|
connection_type = 'usb'
|
|
|
|
def get_devices(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.
|
|
"""
|
|
usb_devices = {}
|
|
devs = core.find(find_all=True)
|
|
cpt = 2
|
|
for dev in devs:
|
|
identifier = "usb_%04x:%04x" % (dev.idVendor, dev.idProduct)
|
|
if identifier in usb_devices:
|
|
identifier += '_%s' % cpt
|
|
cpt += 1
|
|
usb_devices[identifier] = dev
|
|
return usb_devices
|