summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorAntoine Prieels <anp@odoo.com>2019-10-31 14:53:16 +0000
committerAntoine Prieels <anp@odoo.com>2020-05-13 13:26:05 +0000
commite5d25e98b4f6ca06c61eeb64d3b4852a0de387e8 (patch)
treeba5a60817591c6042057949075a3f7f524c56747 /addons
parente1c52c936d4777f53e9889832a65aaa443537ec7 (diff)
[IMP] hw_drivers: Give a priority order to drivers
Previously, we tested the `supported` methods of all drivers sequentially in alphabetical order of file names. If you wanted to extend a driver, the `supported` method of your driver could never be tested if the one of its parent was tested first. We've now added a priority order to drivers so that by default the extending driver will always be tested before the extended driver. You can still do something similar to what `is_tested_last` did by manually setting the priority of a driver to 0. Ex: The way barcode scanners is really similar to keyboards, but still requires a few modifications in the driver. We couldn't extend the keyboard driver easily because the supported method of barcode scanners had to be more strict than the one of keyboards. If the KeyboardUSBDriver was tested first, scanners were recognized as keyboard and didn't have all the specific features of scanners. TaskID: 2082282
Diffstat (limited to 'addons')
-rwxr-xr-xaddons/hw_drivers/controllers/driver.py11
-rw-r--r--addons/hw_drivers/iot_handlers/drivers/SerialScaleDriver.py2
2 files changed, 6 insertions, 7 deletions
diff --git a/addons/hw_drivers/controllers/driver.py b/addons/hw_drivers/controllers/driver.py
index 7be5df911cd..30d6be7344a 100755
--- a/addons/hw_drivers/controllers/driver.py
+++ b/addons/hw_drivers/controllers/driver.py
@@ -144,7 +144,7 @@ class Interface(Thread, metaclass=InterfaceMetaClass):
def __init__(self):
super(Interface, self).__init__()
- self.drivers = [d for d in drivers if d.connection_type == self.connection_type]
+ self.drivers = sorted([d for d in drivers if d.connection_type == self.connection_type], key=lambda d: d.priority, reverse=True)
def run(self):
while self.connection_type and self.drivers:
@@ -179,11 +179,11 @@ class Interface(Thread, metaclass=InterfaceMetaClass):
class DriverMetaClass(type):
def __new__(cls, clsname, bases, attrs):
newclass = super(DriverMetaClass, cls).__new__(cls, clsname, bases, attrs)
- # Some drivers must be tried only when all the others have been ruled out. These are kept at the bottom of the list.
- if newclass.is_tested_last:
- drivers.append(newclass)
+ if hasattr(newclass, 'priority'):
+ newclass.priority += 1
else:
- drivers.insert(0, newclass)
+ newclass.priority = 0
+ drivers.append(newclass)
return newclass
class Driver(Thread, metaclass=DriverMetaClass):
@@ -191,7 +191,6 @@ class Driver(Thread, metaclass=DriverMetaClass):
Hook to register the driver into the drivers list
"""
connection_type = ""
- is_tested_last = False
def __init__(self, device):
super(Driver, self).__init__()
diff --git a/addons/hw_drivers/iot_handlers/drivers/SerialScaleDriver.py b/addons/hw_drivers/iot_handlers/drivers/SerialScaleDriver.py
index e81bf4af383..116beac799f 100644
--- a/addons/hw_drivers/iot_handlers/drivers/SerialScaleDriver.py
+++ b/addons/hw_drivers/iot_handlers/drivers/SerialScaleDriver.py
@@ -247,7 +247,7 @@ class AdamEquipmentDriver(ScaleDriver):
"""Driver for the Adam Equipment serial scale."""
_protocol = ADAMEquipmentProtocol
- is_tested_last = True
+ priority = 0 # Test the supported method of this driver last, after all other serial drivers
def __init__(self, device):
super().__init__(device)