File: printer.py

package info (click to toggle)
async-upnp-client 0.45.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,076 kB
  • sloc: python: 11,946; xml: 2,826; sh: 32; makefile: 6
file content (48 lines) | stat: -rw-r--r-- 1,222 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# -*- coding: utf-8 -*-
"""async_upnp_client.profiles.printer module."""

import logging
from typing import List, NamedTuple, Optional

from async_upnp_client.profiles.profile import UpnpProfileDevice

_LOGGER = logging.getLogger(__name__)


PrinterAttributes = NamedTuple(
    "PrinterAttributes",
    [
        ("printer_state", str),
        ("printer_state_reasons", str),
        ("job_id_list", List[int]),
        ("job_id", int),
    ],
)


class PrinterDevice(UpnpProfileDevice):
    """Representation of a printer device."""

    DEVICE_TYPES = [
        "urn:schemas-upnp-org:device:printer:1",
    ]

    _SERVICE_TYPES = {
        "BASIC": {
            "urn:schemas-upnp-org:service:PrintBasic:1",
        },
    }

    async def async_get_printer_attributes(self) -> Optional[PrinterAttributes]:
        """Get printer attributes."""
        action = self._action("BASIC", "GetPrinterAttributes")
        if not action:
            return None

        result = await action.async_call()
        return PrinterAttributes(
            result["PrinterState"],
            result["PrinterStateReasons"],
            [int(x) for x in result["JobIdList"].split(",")],
            int(result["JobId"]),
        )