diff --git a/addons/hw_drivers/iot_handlers/interfaces/PrinterInterface.py b/addons/hw_drivers/iot_handlers/interfaces/PrinterInterface.py index ca601dbce04..371773b899e 100644 --- a/addons/hw_drivers/iot_handlers/interfaces/PrinterInterface.py +++ b/addons/hw_drivers/iot_handlers/interfaces/PrinterInterface.py @@ -20,18 +20,29 @@ class PrinterInterface(Interface): with cups_lock: printers = conn.getPrinters() devices = conn.getDevices() - for printer in printers: - path = printers.get(printer).get('device-uri', False) - if path and path in devices: - devices.get(path).update({'supported': True}) # these printers are automatically supported - 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] + for printer_name, printer in printers.items(): + path = printer.get('device-uri', False) + if printer_name != self.get_identifier(path): + printer.update({'supported': True}) # these printers are automatically supported + device_class = 'network' + if 'usb' in printer.get('device-uri'): + device_class = 'direct' + printer.update({'device-class': device_class}) + printer.update({'device-make-and-model': printer_name}) # give name setted in Cups + printer.update({'device-id': ''}) + devices.update({printer_name: printer}) + for path, device in devices.items(): + identifier = self.get_identifier(path) + device.update({'identifier': identifier}) + device.update({'url': path}) + printer_devices.update({identifier: device}) return printer_devices + + def get_identifier(self, path): + 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) + return identifier