summaryrefslogtreecommitdiff
path: root/addons/hw_drivers/driver.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/hw_drivers/driver.py
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/hw_drivers/driver.py')
-rw-r--r--addons/hw_drivers/driver.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/addons/hw_drivers/driver.py b/addons/hw_drivers/driver.py
new file mode 100644
index 00000000..459c3c9b
--- /dev/null
+++ b/addons/hw_drivers/driver.py
@@ -0,0 +1,53 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from threading import Thread, Event
+
+from odoo.addons.hw_drivers.main import drivers, iot_devices
+
+
+class DriverMetaClass(type):
+ def __new__(cls, clsname, bases, attrs):
+ newclass = super(DriverMetaClass, cls).__new__(cls, clsname, bases, attrs)
+ if hasattr(newclass, 'priority'):
+ newclass.priority += 1
+ else:
+ newclass.priority = 0
+ drivers.append(newclass)
+ return newclass
+
+
+class Driver(Thread, metaclass=DriverMetaClass):
+ """
+ Hook to register the driver into the drivers list
+ """
+ connection_type = ''
+
+ def __init__(self, identifier, device):
+ super(Driver, self).__init__()
+ self.dev = device
+ self.device_identifier = identifier
+ self.device_name = ''
+ self.device_connection = ''
+ self.device_type = ''
+ self.device_manufacturer = ''
+ self.data = {'value': ''}
+ self._stopped = Event()
+
+ @classmethod
+ def supported(cls, device):
+ """
+ On specific driver override this method to check if device is supported or not
+ return True or False
+ """
+ return False
+
+ def action(self, data):
+ """
+ On specific driver override this method to make a action with device (take picture, printing,...)
+ """
+ raise NotImplementedError()
+
+ def disconnect(self):
+ self._stopped.set()
+ del iot_devices[self.device_identifier]