Match case for printer type discovery

This commit is contained in:
n07070
2026-11-13 03:01:21 +01:00
parent df070ebd72
commit ba7e854a6f

View File

@@ -90,47 +90,45 @@ class Printers:
hex(dev.idProduct), hex(dev.idProduct),
) )
if manufacturer == "EPSON": match (manufacturer):
try: case ("EPSON"):
# We create a new EscPosPrinter() try:
self.app.logger.debug("Trying to create a new EPSON printer") # We create a new EscPosPrinter()
prid = dev.idProduct self.app.logger.debug("Trying to create a new EPSON printer")
vendir = dev.idVendor prid = dev.idProduct
escpos_printer = EscPosPrinter( vendir = dev.idVendor
self.app, vendor_id=vendir, device_id=prid escpos_printer = EscPosPrinter(
) self.app, vendor_id=vendir, device_id=prid
except Exception as e: )
raise e except Exception as e:
raise e
# If the object creation is successfull, we add it to the list of Printers # If the object creation is successfull, we add it to the list of Printers
printers.add(escpos_printer) printers.add(escpos_printer)
self.app.logger.debug("Found a %s printer", manufacturer) self.app.logger.debug("Found a %s printer", manufacturer)
case ("Brother"):
try:
# We create a new BrotherPrinter()
self.app.logger.debug("Trying to create a new BROTHER printer")
# We already found the type of printer, brother_printer = BrotherPrinter(
# we don't need an extra comparaison. self.app, vendor_id=dev.idVendor, device_id=dev.idProduct
continue )
except Exception as e:
self.app.logger.error(
"Could not create a %s printer class with %s:%s",
product,
dev.idVendor,
dev.idProduct,
)
raise e
# or a Brother Printer # If the object creation is successfull, we add it to the list of Printers
if manufacturer == "Brother": printers.add(brother_printer)
try: self.app.logger.debug("Found a %s printer", manufacturer)
# We create a new BrotherPrinter() case (_):
self.app.logger.debug("Trying to create a new BROTHER printer") self.app.logger.debug("Found a printer of unknown manufacturer : %s", manufacturer)
# end match
brother_printer = BrotherPrinter(
self.app, vendor_id=dev.idVendor, device_id=dev.idProduct
)
except Exception as e:
self.app.logger.error(
"Could not create a %s printer class with %s:%s",
product,
dev.idVendor,
dev.idProduct,
)
raise e
# If the object creation is successfull, we add it to the list of Printers
printers.add(brother_printer)
self.app.logger.debug("Found a %s printer", manufacturer)
self.app.logger.debug("Found %s printers", len(printers)) self.app.logger.debug("Found %s printers", len(printers))