You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.1 KiB

4 years ago
  1. # -*- coding: utf-8 -*-
  2. """UPnP printer module."""
  3. import logging
  4. from typing import List, NamedTuple
  5. from async_upnp_client.profile import UpnpProfileDevice
  6. _LOGGER = logging.getLogger(__name__)
  7. PrinterAttributes = NamedTuple(
  8. 'PrinterAttributes', [
  9. ('printer_state', str),
  10. ('printer_state_reasons', str),
  11. ('job_id_list', List[int]),
  12. ('job_id', int)])
  13. class PrinterDevice(UpnpProfileDevice):
  14. """Representation of a printer device."""
  15. DEVICE_TYPES = [
  16. 'urn:schemas-upnp-org:device:printer:1',
  17. ]
  18. _SERVICE_TYPES = {
  19. 'BASIC': {
  20. 'urn:schemas-upnp-org:service:PrintBasic:1',
  21. },
  22. }
  23. async def async_get_printer_attributes(self) -> PrinterAttributes:
  24. """Get printer attributes."""
  25. action = self._action('BASIC', 'GetPrinterAttributes')
  26. result = await action.async_call()
  27. return PrinterAttributes(
  28. result['PrinterState'],
  29. result['PrinterStateReasons'],
  30. [int(x) for x in result['JobIdList'].split(',')],
  31. int(result['JobId']))