diff options
| author | Antoine Prieels <anp@odoo.com> | 2019-10-29 12:39:28 +0000 |
|---|---|---|
| committer | Antoine Prieels <anp@odoo.com> | 2020-05-13 13:26:05 +0000 |
| commit | e1c52c936d4777f53e9889832a65aaa443537ec7 (patch) | |
| tree | ec8853d0f00777c286fde9f8995a1a061c73e7e5 /addons/hw_drivers/iot_handlers/interfaces/PrinterInterface.py | |
| parent | bea1613f11e1def53bc3c558f82b8edc4633091a (diff) | |
[IMP] hw_drivers: Easier detection of new devices
Until now, to detect new types of devices on the IoT Box, we had to
modify driver.py. If partners wanted to connect a new type of device,
they had to modify directly the files on the Box, meaning that after
each new build they had to re-apply all their modifications.
We remove the loops that detected the connected devices and replace
them by `Interfaces`. All interfaces will be loaded from the connected
Odoo instance with the corresponding drivers.
TaskID: 2082282
Diffstat (limited to 'addons/hw_drivers/iot_handlers/interfaces/PrinterInterface.py')
| -rw-r--r-- | addons/hw_drivers/iot_handlers/interfaces/PrinterInterface.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/addons/hw_drivers/iot_handlers/interfaces/PrinterInterface.py b/addons/hw_drivers/iot_handlers/interfaces/PrinterInterface.py new file mode 100644 index 00000000000..ec596a60dce --- /dev/null +++ b/addons/hw_drivers/iot_handlers/interfaces/PrinterInterface.py @@ -0,0 +1,30 @@ +from cups import Connection as cups_connection +from re import sub +from threading import Lock + +from odoo.addons.hw_drivers.controllers.driver import Interface + +conn = cups_connection() +PPDs = conn.getPPDs() +printers = conn.getPrinters() +cups_lock = Lock() # We can only make one call to Cups at a time + +class PrinterInterface(Interface): + _loop_delay = 120 + connection_type = 'printer' + + def get_devices(self): + printer_devices = {} + with cups_lock: + devices = conn.getDevices() + for path in devices: + if 'uuid=' in path: + identifier = sub('[^a-zA-Z0-9 ]+', '', path.split('uuid=')[1]) + elif 'serial=' in path: + identifier = sub('[^a-zA-Z0-9 ]+', '', path.split('serial=')[1]) + else: + identifier = sub('[^a-zA-Z0-9 ]+', '', path) + devices[path]['identifier'] = identifier + devices[path]['url'] = path + printer_devices[identifier] = devices[path] + return printer_devices |
