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)