Skip to content

Hardware Catalog API Reference

purrint.catalog.PrinterModel dataclass

Static description of a printer model.

Source code in src/purrint/catalog.py
@dataclass(frozen=True)
class PrinterModel:
    """Static description of a printer model."""

    name: str
    """Normalised Bluetooth name (upper case, no spaces)."""

    family: Family
    """Protocol family used to talk to it."""

    vendor_model: str
    """Model code used by the vendor app (``V5G``, ``V5X`` or ``V5X_S``)."""

    kind: Kind = Kind.MINI_PRINTER
    simplified: bool = False
    """The vendor app shows a reduced feature set for this model."""

    display_name: Optional[str] = None
    dots_per_line: int = 384
    """Printable width in dots (384 dots = 48 mm at 203 dpi)."""

    dpi: int = 203
    density: Optional[DensityProfile] = None
    reports_overheat_d2: bool = False
    """Sends the dedicated ``51 78 D2`` overheat notification."""

    reports_low_battery: bool = False
    supports_gray: bool = False
    """Can print 16-level grayscale (V5X family)."""

    aliases: Tuple[str, ...] = field(default_factory=tuple)

    @property
    def label(self) -> str:
        return self.display_name or self.name

    @property
    def mxw01_board(self) -> bool:
        """True for every V5X/V5X_S device (they share the MXW01 board protocol)."""
        return self.family is Family.V5X

dots_per_line = 384 class-attribute instance-attribute

Printable width in dots (384 dots = 48 mm at 203 dpi).

family instance-attribute

Protocol family used to talk to it.

mxw01_board property

True for every V5X/V5X_S device (they share the MXW01 board protocol).

name instance-attribute

Normalised Bluetooth name (upper case, no spaces).

reports_overheat_d2 = False class-attribute instance-attribute

Sends the dedicated 51 78 D2 overheat notification.

simplified = False class-attribute instance-attribute

The vendor app shows a reduced feature set for this model.

supports_gray = False class-attribute instance-attribute

Can print 16-level grayscale (V5X family).

vendor_model instance-attribute

Model code used by the vendor app (V5G, V5X or V5X_S).


purrint.catalog.Family

Bases: str, Enum

Wire protocol spoken by a printer.

Source code in src/purrint/catalog.py
class Family(str, enum.Enum):
    """Wire protocol spoken by a printer."""

    V5G = "V5G"
    """``51 78`` frames, one command per raster line, flow control on the notify channel."""

    V5X = "V5X"
    """``22 21`` frames, whole bitmap streamed on a separate data channel (MXW01 board)."""

    def __str__(self) -> str:  # pragma: no cover - cosmetic
        return self.value

V5G = 'V5G' class-attribute instance-attribute

51 78 frames, one command per raster line, flow control on the notify channel.

V5X = 'V5X' class-attribute instance-attribute

22 21 frames, whole bitmap streamed on a separate data channel (MXW01 board).


purrint.catalog.all_models(family=None)

Every known model, optionally filtered by protocol family, in catalog order.

Source code in src/purrint/catalog.py
def all_models(family: Optional[Family] = None) -> List[PrinterModel]:
    """Every known model, optionally filtered by protocol family, in catalog order."""
    return [m for m in _MODELS.values() if family is None or m.family is family]

purrint.catalog.get_model(name)

Exact (normalised) catalog lookup.

Source code in src/purrint/catalog.py
def get_model(name: str) -> Optional[PrinterModel]:
    """Exact (normalised) catalog lookup."""
    return _MODELS.get(normalize_name(name))

purrint.catalog.identify(name, manufacturer_data=None)

Find the model for an advertised Bluetooth name.

Tries, in order: exact match, the name without hyphens/dots, and the longest catalog name that is a prefix of the advertised one ("MX10-1A2B" -> MX10). Returns None for unknown names.

Source code in src/purrint/catalog.py
def identify(
    name: Optional[str],
    manufacturer_data: Optional[Mapping[int, bytes]] = None,
) -> Optional[PrinterModel]:
    """Find the model for an advertised Bluetooth name.

    Tries, in order: exact match, the name without hyphens/dots, and the longest catalog name that is
    a prefix of the advertised one (``"MX10-1A2B"`` -> ``MX10``). Returns ``None`` for unknown names.
    """
    if not name:
        return None
    norm = normalize_name(name)
    model = _MODELS.get(norm)
    if model is None:
        loose = re.sub(r"[-_.]", "", norm)
        for key, candidate in _MODELS.items():
            if re.sub(r"[-_.]", "", key) == loose:
                model = candidate
                break
    if model is None:
        best: Optional[PrinterModel] = None
        for key, candidate in _MODELS.items():
            if len(key) >= 3 and norm.startswith(key) and (best is None or len(key) > len(best.name)):
                best = candidate
        model = best
    if model is not None and model.family is Family.V5G and _manufacturer_says_v5x(manufacturer_data):
        model = PrinterModel(
            name=model.name,
            family=Family.V5X,
            vendor_model="V5X_S",
            kind=model.kind,
            simplified=model.simplified,
            display_name=model.display_name,
            supports_gray=True,
        )
    return model