prusalink: add X/Y axis, location, and min extrusion temp sensors#169312
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends the Home Assistant prusalink integration by exposing additional informational sensor entities derived from data that is already fetched by existing coordinators.
Changes:
- Add X/Y axis position sensors sourced from the status endpoint data.
- Add Location and Minimum extrusion temperature sensors sourced from the info endpoint data.
- Extend and update test fixtures and sensor tests to validate the newly added entities.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
homeassistant/components/prusalink/sensor.py |
Adds four new sensor entity descriptions (X, Y, location, min extrusion temp) with availability handling. |
homeassistant/components/prusalink/strings.json |
Adds translation strings for the four new sensors. |
tests/components/prusalink/conftest.py |
Extends the mocked /api/v1/info response with location. |
tests/components/prusalink/test_sensor.py |
Adds tests validating new sensors and axis sensor unavailability when fields are absent. |
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
Add four sensors from data already fetched by existing coordinators, requiring no library changes: - X position (printer.axis_x) — mm, disabled by default - Y position (printer.axis_y) — mm, disabled by default - Location (info.location) — text, disabled by default - Minimum extrusion temperature (info.min_extrusion_temp) — °C, disabled by default X and Y mirror the existing Z-Height sensor pattern. Location and minimum extrusion temperature expose the remaining useful scalar fields from the /api/v1/info endpoint already polled every 30 seconds. All sensors are marked unavailable when the respective field is absent from the API response. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…sensors - Add test for location and min_extrusion_temp sensors becoming unavailable when fields are absent from /api/v1/info response - Add assert state is not None before .state access in unavailability tests for clearer failure messages - Add type annotations to new test fixture parameters Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Per review feedback, available_fn is the wrong tool for "field absent on this firmware" — that's a permanent characteristic of the printer, not transient unavailability. Use a new supported_fn evaluated once in async_setup_entry so the sensor is not created when the field is absent. Job sensors keep available_fn since their unavailability is transient (state-based, not firmware-based). Also fix prettier CI failure: alphabetize new sensor strings. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ba8188e to
eb183b2
Compare
min_extrusion_temp is a static configuration value, not a continuously measured one — it changes only when the user reconfigures the printer. Treating it as a measurement generates long-term statistics for what is essentially a constant, which is recorder spam. This matches the existing nozzle_diameter sensor (also from /api/v1/info) which has no state_class. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Rename X and Y entity names from "X"/"Y" to "X-Position"/"Y-Position" to match the existing Z-Height pattern. Entity IDs change accordingly (sensor.<title>_x → sensor.<title>_x_position, same for y), and tests are updated to match. - Add icon for the location sensor. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
| PrusaLinkSensorEntityDescription[PrinterInfo]( | ||
| key="info.location", | ||
| translation_key="location", | ||
| value_fn=lambda data: cast(str, data["location"]), | ||
| supported_fn=lambda data: data.get("location") is not None, | ||
| entity_registry_enabled_default=False, | ||
| ), |
There was a problem hiding this comment.
So why is location a sensor? If it reflects the current location of the printer, it should probably be set to suggested_area in the device info instead
There was a problem hiding this comment.
Good catch — agreed that this is the right architectural choice. Opened #170099 which:
- Removes the
locationsensor - Sets
suggested_area=info_data.get("location")onDeviceInfo, so the printer's configured location is used as a hint when registering the device
The sensor was added in this PR (default-disabled, just merged) so the breaking impact is small — most users never enabled it. suggested_area is non-binding for already-registered devices, so existing setups keep their current area assignment unchanged. New users get the location string proposed as an area on registration (HA matches existing or creates).
Side note for posterity: DeviceEntry.suggested_area is being deprecated in HA 2026.9 (per this blog post), but setting suggested_area via DeviceInfo is still supported and still influences device area on registration. The deprecation only covers reading it back from DeviceEntry.
Proposed change
Adds four sensors from data already fetched by existing coordinators. No changes to
pyprusalinkrequired — all fields are present inpyprusalink==2.1.1.printer.axis_x)/api/v1/statusviaStatusCoordinatorprinter.axis_y)/api/v1/statusviaStatusCoordinatorinfo.location)/api/v1/infoviaInfoUpdateCoordinatorinfo.min_extrusion_temp)/api/v1/infoviaInfoUpdateCoordinatorX and Y mirror the existing Z-Height sensor (same device class, unit, state class). Location and minimum extrusion temperature expose the remaining useful scalar fields from
/api/v1/info. All four are disabled by default as they are informational rather than operational.Per review feedback, sensors are evaluated for support at setup via a new
supported_fnfield on the entity description. When the corresponding field is absent from the API response (older firmware, or printer model that doesn't have the feature), the sensor is not created — rather than being created and marked unavailable.available_fnis reserved for transient unavailability (e.g., printer offline, job-state-dependent fields) per the existing pattern.This is part of a series of incremental improvements to the prusalink integration; a parallel series of PRs to
home-assistant-libs/pyprusalinkadds additional endpoints.Type of change
Checklist