Bump pyprusalink to 3.0.0#170480
Conversation
There was a problem hiding this comment.
Pull request overview
This PR bumps the PrusaLink integration’s pyprusalink dependency to 3.0.0 and updates the integration/test code to accommodate the library’s breaking change where get_job() can now return None.
Changes:
- Bump
pyprusalinkto3.0.0across the integration manifest and generated requirements pins. - Update the PrusaLink coordinators/entities to correctly handle
JobInfo | Nonepayloads from the job endpoint. - Align sensors and tests with the new idle-job behavior and stricter typing introduced by
pyprusalink’spy.typed.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
homeassistant/components/prusalink/manifest.json |
Bumps integration requirement pin to pyprusalink==3.0.0. |
requirements_all.txt |
Updates generated dependency pin for pyprusalink. |
requirements_test_all.txt |
Updates generated test dependency pin for pyprusalink. |
homeassistant/components/prusalink/coordinator.py |
Makes the job coordinator nullable (`JobInfo |
homeassistant/components/prusalink/entity.py |
Prevents available_fn evaluation when coordinator data is None (avoids idle-job crashes). |
homeassistant/components/prusalink/sensor.py |
Updates sensor value/availability logic and adds typing workarounds for stricter upstream types. |
tests/components/prusalink/conftest.py |
Adjusts job API idle fixture to return None (matching pyprusalink>=3.0.0). |
Follow-up to home-assistant#170480, addressing the two `# type: ignore` comments that PR added to the `job.filename` and `job.finish` sensors. Both lambdas are guarded at runtime by `available_fn` (verifying `data["file"]` and `data["time_remaining"]` are not None respectively), but mypy doesn't follow the guarantee from `available_fn` into `value_fn`. Switch to the inner-cast pattern already used on the `printer.telemetry.material` sensor: - `job.filename`: `cast(JobFilePrint, data["file"])["display_name"]` narrows `JobFilePrint | None` so the index is type-safe. - `job.finish`: `cast(int, data["time_remaining"])` narrows `int | None` so it can be passed to `timedelta(seconds=...)`. Runtime behaviour is unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
Follow-up to home-assistant#170480, addressing the two `# type: ignore` comments that PR added to the `job.filename` and `job.finish` sensors. Both lambdas are guarded at runtime by `available_fn` (verifying `data["file"]` and `data["time_remaining"]` are not None respectively), but mypy doesn't follow the guarantee from `available_fn` into `value_fn`. Switch to the inner-cast pattern already used on the `printer.telemetry.material` sensor: - `job.filename`: `cast(JobFilePrint, data["file"])["display_name"]` narrows `JobFilePrint | None` so the index is type-safe. - `job.finish`: `cast(int, data["time_remaining"])` narrows `int | None` so it can be passed to `timedelta(seconds=...)`. Runtime behaviour is unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
fa62279 to
26f5a7e
Compare
|
I've cleaned this up to handle the version-bump in a minimal way. The following will be handled in followup-PRs. Builds on this, so they will be opened when this one is merged:
Ready for review. |
| def mock_job_api_idle() -> Generator[None]: | ||
| """Mock PrusaLink job API having no job. | ||
|
|
||
| pyprusalink >= 3.0.0 returns `None` from `get_job()` on HTTP 204 when | ||
| no job is running, rather than an empty dict as in 2.x. | ||
| """ | ||
| with patch("pyprusalink.PrusaLink.get_job", return_value=None): | ||
| yield None |
erwindouna
left a comment
There was a problem hiding this comment.
Thanks for the changes @heikkih. Please elaborate what's related to the dependency bump and what's not. All the work that's not related to the bump, then please split that off from this PR and create separate PRs. :)
|
Thanks for the review @erwindouna My local venv was pointing at the older pyprusalink 2.2.0 due to parallell work in a different branch, so sorry for the noise earlier. I've updated and gone through all changes manually. All changes are now relevant to the 3.0.0-bump, specifically the tighter typing in it, hence the need for the casts for now. I will handle these better (with some refactoring) in a follow-up PR, but now it is as minimal as I can get it, while still working correctly and passing all QA-jobs :) I'll set this as ready for review now. |
Proposed change
This PR is intentionally scoped to a minimal dependency bump for PrusaLink.
Included scope:
pyprusalinkto3.0.0.cast()adjustments required by the stricter typing surface inpyprusalink3.0.0.Out of scope:
unknownvsunavailable) are intentionally deferred and will be handled in a separate follow-up PR after this bump is merged.Dependency reference:
pyprusalink2.2.0->3.0.0pyprusalink3.0.0:Type of change
Checklist
ruff format homeassistant tests)requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.