| 1 | """async_upnp_client.profiles.printer module.""" |
| 2 | |
| 3 | import logging |
| 4 | from typing import NamedTuple |
| 5 | |
| 6 | from async_upnp_client.profiles.profile import UpnpProfileDevice |
| 7 | |
| 8 | _LOGGER = logging.getLogger(__name__) |
| 9 | |
| 10 | |
| 11 | PrinterAttributes = NamedTuple( |
| 12 | "PrinterAttributes", |
| 13 | [ |
| 14 | ("printer_state", str), |
| 15 | ("printer_state_reasons", str), |
| 16 | ("job_id_list", list[int]), |
| 17 | ("job_id", int), |
| 18 | ], |
| 19 | ) |
| 20 | |
| 21 | |
| 22 | class PrinterDevice(UpnpProfileDevice): |
| 23 | """Representation of a printer device.""" |
| 24 | |
| 25 | DEVICE_TYPES = [ |
| 26 | "urn:schemas-upnp-org:device:printer:1", |
| 27 | ] |
| 28 | |
| 29 | _SERVICE_TYPES = { |
| 30 | "BASIC": { |
| 31 | "urn:schemas-upnp-org:service:PrintBasic:1", |
| 32 | }, |
| 33 | } |
| 34 | |
| 35 | async def async_get_printer_attributes(self) -> PrinterAttributes | None: |
| 36 | """Get printer attributes.""" |
| 37 | action = self._action("BASIC", "GetPrinterAttributes") |
| 38 | if not action: |
| 39 | return None |
| 40 | |
| 41 | result = await action.async_call() |
| 42 | return PrinterAttributes( |
| 43 | result["PrinterState"], |
| 44 | result["PrinterStateReasons"], |
| 45 | [int(x) for x in result["JobIdList"].split(",")], |
| 46 | int(result["JobId"]), |
| 47 | ) |