Skip to content
Open
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
13 changes: 12 additions & 1 deletion src/pyipp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def from_dict(data: dict[str, Any]) -> Info:
serial=serial,
uptime=data.get("printer-up-time", 0),
uuid=uuid[9:] if uuid else None, # strip urn:uuid: from uuid
version=data.get("printer-firmware-string-version"),
version=_join_if_list(data.get("printer-firmware-string-version")),
more_info=data.get("printer-more-info"),
)

Expand Down Expand Up @@ -317,6 +317,17 @@ def _utcnow() -> datetime:
"""Return the current date and time in UTC."""
return datetime.now(tz=timezone.utc)

def _join_if_list(value: Any) -> str | None:
"""Return value joined into a single string if it is a list."""
if value is None:
return None

if isinstance(value, list):
return ", ".join(str(item) for item in value)

return str(value)


def _str_or_none(value: str) -> str | None:
"""Return string while handling string representations of None."""
if value == "none":
Expand Down
12 changes: 12 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ async def test_info() -> None: # noqa: PLR0915
assert info.model == "Unknown"


@pytest.mark.asyncio
async def test_info_version_list() -> None:
"""Test Info model with firmware version reported as multiple values."""
parsed = parser.parse(load_fixture_binary("get-printer-attributes-epsonxp6000.bin"))
data = parsed["printers"][0]
data["printer-firmware-string-version"] = ["2.0", "1.02", "CXNZJ.250.038"]
info = models.Info.from_dict(data)

assert info
assert info.version == "2.0, 1.02, CXNZJ.250.038"


@pytest.mark.asyncio
async def test_state() -> None:
"""Test State model."""
Expand Down