Match case for printer type discovery
This commit is contained in:
@@ -90,47 +90,45 @@ class Printers:
|
||||
hex(dev.idProduct),
|
||||
)
|
||||
|
||||
if manufacturer == "EPSON":
|
||||
try:
|
||||
# We create a new EscPosPrinter()
|
||||
self.app.logger.debug("Trying to create a new EPSON printer")
|
||||
prid = dev.idProduct
|
||||
vendir = dev.idVendor
|
||||
escpos_printer = EscPosPrinter(
|
||||
self.app, vendor_id=vendir, device_id=prid
|
||||
)
|
||||
except Exception as e:
|
||||
raise e
|
||||
match (manufacturer):
|
||||
case ("EPSON"):
|
||||
try:
|
||||
# We create a new EscPosPrinter()
|
||||
self.app.logger.debug("Trying to create a new EPSON printer")
|
||||
prid = dev.idProduct
|
||||
vendir = dev.idVendor
|
||||
escpos_printer = EscPosPrinter(
|
||||
self.app, vendor_id=vendir, device_id=prid
|
||||
)
|
||||
except Exception as e:
|
||||
raise e
|
||||
|
||||
# If the object creation is successfull, we add it to the list of Printers
|
||||
printers.add(escpos_printer)
|
||||
self.app.logger.debug("Found a %s printer", manufacturer)
|
||||
# If the object creation is successfull, we add it to the list of Printers
|
||||
printers.add(escpos_printer)
|
||||
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,
|
||||
# we don't need an extra comparaison.
|
||||
continue
|
||||
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
|
||||
|
||||
# or a Brother Printer
|
||||
if manufacturer == "Brother":
|
||||
try:
|
||||
# We create a new BrotherPrinter()
|
||||
self.app.logger.debug("Trying to create a new BROTHER printer")
|
||||
|
||||
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)
|
||||
# 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)
|
||||
case (_):
|
||||
self.app.logger.debug("Found a printer of unknown manufacturer : %s", manufacturer)
|
||||
# end match
|
||||
|
||||
self.app.logger.debug("Found %s printers", len(printers))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user