Skip to content

Expose job and storage sub-objects from /api/v1/status#158

Merged
agners merged 2 commits into
home-assistant-libs:mainfrom
heikkih:feat/extended-status
May 7, 2026
Merged

Expose job and storage sub-objects from /api/v1/status#158
agners merged 2 commits into
home-assistant-libs:mainfrom
heikkih:feat/extended-status

Conversation

@heikkih
Copy link
Copy Markdown
Contributor

@heikkih heikkih commented Apr 27, 2026

Summary

PrinterStatus previously only typed the printer key. The /api/v1/status endpoint also returns:

  • job — present while printing, absent in IDLE (typed with NotRequired)
  • storage — the active storage device

Both are useful for consumers who want to poll a single endpoint instead of combining /api/v1/status and /api/v1/job.

New types added to types.py:

  • StatusJob — job summary as it appears in the status response
  • StatusStorage — storage device as it appears in the status response

Verification

Verified the actual response structure against a live Core One printer (firmware 6.5.3) in both IDLE and PRINTING states. The job key is genuinely absent (not null) when no job is running, hence NotRequired rather than | None.

Test plan

  • test_get_status — asserts job and storage fields during printing
  • test_get_status_idle — asserts job key is absent in IDLE response

🤖 Generated with Claude Code

PrinterStatus previously only typed the printer key. The status
endpoint also returns job (absent when idle) and storage, which
are useful for consumers polling a single endpoint.

Verified against a live Core One printer running firmware 6.5.3.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@heikkih heikkih force-pushed the feat/extended-status branch from 04b3529 to c777a1b Compare April 28, 2026 11:47
Comment thread pyprusalink/types.py
Comment thread pyprusalink/types.py Outdated
id: int
progress: float
time_printing: int
time_remaining: int | None
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do printers return null? From OpenAPI spec (https://github.com/prusa3d/Prusa-Link-Web/blob/master/spec/openapi.yaml) it doesn't seem this field is optional.

Comment thread pyprusalink/types.py
- Add `free_space: NotRequired[int]` to StatusStorage (per OpenAPI spec)
- Drop `| None` from time_remaining (spec doesn't mark it nullable;
  printer omits the field rather than returning null)
- Drop `| None` from job/storage in PrinterStatus (printer omits, doesn't
  return null — `NotRequired` alone is sufficient)

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

heikkih commented May 6, 2026

Pushed 98b444e addressing all three points:

  1. free_space added to StatusStorage — typed as NotRequired[int]. Verified against my Core One on 6.5.3 that it can be absent (printer omits the field on USB storage in my case), so NotRequired is the right choice rather than int | None.
  2. time_remaining: int — dropped | None. The OpenAPI spec doesn't mark it nullable; total=False on StatusJob already makes it not-required.
  3. job: NotRequired[StatusJob] / storage: NotRequired[StatusStorage] — dropped | None per your suggestion. The printer omits these keys, doesn't return null.

Test updated to include free_space to lock in the typing.

Comment thread pyprusalink/types.py
status_connect: StatusInfo | None


class StatusJob(TypedDict, total=False):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could argue using NotRequired on all the fields is a bit more consistent, but then again the API spec says all fields are optional for StatusJob, which this global flag captures nicely,

I am fine as is.

@agners agners merged commit 70cc21b into home-assistant-libs:main May 7, 2026
2 checks passed
@heikkih heikkih deleted the feat/extended-status 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