Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions pyprusalink/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,29 @@ class VersionInfo(TypedDict):


class PrinterInfo(TypedDict):
"""Printer informations."""

mmu: bool | None
name: str | None
location: str | None
farm_mode: bool | None
nozzle_diameter: float | None
min_extrusion_temp: int | None
serial: str | None
sd_ready: bool | None
active_camera: bool | None
hostname: str | None
port: str | None
network_error_chime: bool | None
"""Printer information from /api/v1/info.

The set of fields returned varies by firmware version and printer
model — older firmware may omit fields like `min_extrusion_temp` or
`network_error_chime`, and a Buddy printer not in farm mode may omit
`farm_mode`. Treat any missing key as "not reported", not
"false/zero/empty".

Use `dict.get()` or `key in info` rather than indexing.
"""

mmu: NotRequired[bool]
name: NotRequired[str]
location: NotRequired[str]
farm_mode: NotRequired[bool]
nozzle_diameter: NotRequired[float]
min_extrusion_temp: NotRequired[int]
serial: NotRequired[str]
sd_ready: NotRequired[bool]
active_camera: NotRequired[bool]
hostname: NotRequired[str]
port: NotRequired[str]
network_error_chime: NotRequired[bool]


class StatusInfo(TypedDict):
Expand Down
19 changes: 19 additions & 0 deletions tests/test_prusalink.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,25 @@ async def test_get_info(pl, respx_mock):
assert result["nozzle_diameter"] == 0.4


async def test_get_info_minimal_firmware(pl, respx_mock):
"""Older firmware may omit several PrinterInfo fields."""
respx_mock.get(f"{HOST}/api/v1/info").mock(
return_value=httpx.Response(
200,
json={
"serial": "CZPX4720X004XC34242",
"nozzle_diameter": 0.4,
"hostname": "prusa-mk3",
},
)
)
result = await pl.get_info()
assert result["serial"] == "CZPX4720X004XC34242"
assert "min_extrusion_temp" not in result
assert "network_error_chime" not in result
assert "farm_mode" not in result


async def test_get_status(pl, respx_mock):
respx_mock.get(f"{HOST}/api/v1/status").mock(
return_value=httpx.Response(
Expand Down