Skip to content

Fix VersionInfo to match real /api/version responses#165

Merged
agners merged 3 commits into
home-assistant-libs:mainfrom
heikkih:fix/version-info-types
May 7, 2026
Merged

Fix VersionInfo to match real /api/version responses#165
agners merged 3 commits into
home-assistant-libs:mainfrom
heikkih:fix/version-info-types

Conversation

@heikkih
Copy link
Copy Markdown
Contributor

@heikkih heikkih commented May 6, 2026

Summary

VersionInfo listed fields as required that the bundled PrusaLink in Prusa-Firmware-Buddy never returns (version, sdk) or only returns conditionally (firmware, printer). It also omitted three fields the bundled firmware always returns (server, hostname, nozzle_diameter).

Field availability matrix

firmware and printer were added to bundled PrusaLink in 64b7a21 (BFW-7864):

Firmware Has firmware/printer
≤ v6.5.0
v6.4.1 (XL track) ❌ (not backported)
v6.5.1 (Core One L)
v6.5.2 (Core One L)
v6.5.3 (Core One/MK4/MK3.9/MK3.5 family)

Models still without the fields on their latest firmware: XL (6.4.x), MINI (last release 6.4.0).

version and sdk are in the Prusa-Link-Web OpenAPI spec but never returned by bundled firmware — kept as optional in case standalone PrusaLink (RPi) returns them.

Changes

  • pyprusalink/types.py: every field on VersionInfo except api is now optional. Added docstring documenting which firmware versions return which fields.
  • tests/test_prusalink.py: updated test_get_version to use realistic Core One 6.5.3 data; added test_get_version_legacy_firmware covering the case where the printer doesn't return firmware/printer.

Test plan

  • Unit tests pass: pytest tests/
  • Lint clean: flake8 / black / isort
  • Verified against Core One firmware 6.5.3 — modern fields present
  • @agners reported MK3.9/6.4.0 lacks firmware field — confirmed via firmware source code analysis

🤖 Generated with Claude Code

The TypedDict listed `version` and `sdk` (per OpenAPI spec) as required
strings and `firmware`/`printer` as required, but the bundled PrusaLink
in Prusa-Firmware-Buddy never returns `version`/`sdk`, and only added
`firmware`/`printer` in v6.5.1 (Core One L) — the field is absent on:
- All firmware before v6.5.1
- XL track (currently on 6.4.x)
- MINI (last release was 6.4.0)

It also omitted `server`, `hostname`, and `nozzle_diameter` which the
bundled firmware always returns.

Update VersionInfo to mark every field except `api` as optional, and
add docstring documenting field availability per firmware. Update
test_get_version to use realistic modern firmware data and add
test_get_version_legacy_firmware covering the absence case.

Reference: prusa3d/Prusa-Firmware-Buddy@64b7a21

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment thread pyprusalink/types.py Outdated
Comment thread pyprusalink/types.py
Match the convention used by Storage and Transfer.

The OpenAPI spec for /api/version does not declare any field as
required, so we mark only `api` as required (it is the API version
itself, returned by every PrusaLink variant we know of). Every other
field is `NotRequired`, even fields that bundled firmware always
returns (server, hostname, nozzle_diameter, text, capabilities) — we
cannot assume the same for standalone PrusaLink installations on RPi.

Also include @agners' MK4 firmware 6.4.0 response as a concrete example
in the docstring of what older firmware returns (no firmware/printer
fields).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@heikkih
Copy link
Copy Markdown
Contributor Author

heikkih commented May 7, 2026

@agners Thanks for all the good feedback on doing this first pass on updates and getting this in a better state.

I suggest releasing a 2.2.0 when #165 is merged.

Further pipeline:

  • After 2.2 do the updates in HA that depends on the work up on til now.
  • Go on to a bit more complex tasks: file operations, and updates.

Comment thread tests/test_prusalink.py Outdated
Test absence of NotRequired keys via `not in` instead of `.get() is None`

`not in` is the precise assertion for NotRequired semantics — the key
is genuinely absent rather than present with a None value.

Co-authored-by: Stefan Agner <stefan@agner.ch>
@agners agners merged commit 80f5ed0 into home-assistant-libs:main May 7, 2026
2 checks passed
@heikkih heikkih deleted the fix/version-info-types branch May 13, 2026 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants