Skip to content

prusalink: add X/Y axis, location, and min extrusion temp sensors#169312

Merged
edenhaus merged 5 commits into
home-assistant:devfrom
heikkih:feat/prusalink-more-sensors
May 7, 2026
Merged

prusalink: add X/Y axis, location, and min extrusion temp sensors#169312
edenhaus merged 5 commits into
home-assistant:devfrom
heikkih:feat/prusalink-more-sensors

Conversation

@heikkih
Copy link
Copy Markdown
Contributor

@heikkih heikkih commented Apr 27, 2026

Proposed change

Adds four sensors from data already fetched by existing coordinators. No changes to pyprusalink required — all fields are present in pyprusalink==2.1.1.

Entity Source Unit Default
X (printer.axis_x) /api/v1/status via StatusCoordinator mm Disabled
Y (printer.axis_y) /api/v1/status via StatusCoordinator mm Disabled
Location (info.location) /api/v1/info via InfoUpdateCoordinator Disabled
Minimum extrusion temperature (info.min_extrusion_temp) /api/v1/info via InfoUpdateCoordinator °C Disabled

X 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_fn field 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_fn is 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/pyprusalink adds additional endpoints.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (non-breaking change which fixes an issue)
  • Code quality improvements to existing code or addition of tests

Checklist

  • The code change is tested and works locally
  • Local tests pass
  • There is no commented out code in this PR

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment thread tests/components/prusalink/test_sensor.py Outdated
Comment thread tests/components/prusalink/test_sensor.py Outdated
Copy link
Copy Markdown
Member

@edenhaus edenhaus left a comment

Choose a reason for hiding this comment

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

Please fix the CI

Comment thread homeassistant/components/prusalink/sensor.py Outdated
@home-assistant home-assistant Bot marked this pull request as draft April 29, 2026 15:42
@home-assistant
Copy link
Copy Markdown
Contributor

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

Copilot AI review requested due to automatic review settings May 6, 2026 18:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment thread homeassistant/components/prusalink/sensor.py
Comment thread tests/components/prusalink/test_sensor.py Outdated
Comment thread tests/components/prusalink/test_sensor.py
@heikkih heikkih marked this pull request as ready for review May 6, 2026 18:37
Copilot AI review requested due to automatic review settings May 6, 2026 18:37
@home-assistant home-assistant Bot requested a review from edenhaus May 6, 2026 18:37
heikkih and others added 3 commits May 6, 2026 20:38
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>
@heikkih heikkih force-pushed the feat/prusalink-more-sensors branch from ba8188e to eb183b2 Compare May 6, 2026 18:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread homeassistant/components/prusalink/sensor.py Outdated
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>
Comment thread homeassistant/components/prusalink/strings.json Outdated
Comment thread homeassistant/components/prusalink/sensor.py
@home-assistant home-assistant Bot marked this pull request as draft May 7, 2026 09:31
- 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>
Copilot AI review requested due to automatic review settings May 7, 2026 10:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@heikkih heikkih marked this pull request as ready for review May 7, 2026 10:37
@home-assistant home-assistant Bot requested a review from edenhaus May 7, 2026 10:37
Copy link
Copy Markdown
Member

@edenhaus edenhaus left a comment

Choose a reason for hiding this comment

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

Thanks @heikkih 👍

@edenhaus edenhaus merged commit c26eb23 into home-assistant:dev May 7, 2026
36 of 37 checks passed
Comment on lines +218 to +224
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,
),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch — agreed that this is the right architectural choice. Opened #170099 which:

  • Removes the location sensor
  • Sets suggested_area=info_data.get("location") on DeviceInfo, 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.

@heikkih heikkih deleted the feat/prusalink-more-sensors branch May 8, 2026 07:37
@github-actions github-actions Bot locked and limited conversation to collaborators May 9, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants