prusalink: add sd_ready, farm_mode, and status_connect binary sensors#169310
Conversation
There was a problem hiding this comment.
Pull request overview
Adds three new PrusaLink binary sensors (SD ready, Farm mode, and Connect status) backed by existing coordinator data to improve observability without requiring pyprusalink changes.
Changes:
- Add
status_connectbinary sensor sourced from/api/v1/statusand enabled by default. - Add
sd_readyandfarm_modebinary sensors sourced from/api/v1/info, disabled by default. - Extend fixtures and tests to cover the new entities and their availability behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
homeassistant/components/prusalink/binary_sensor.py |
Adds entity descriptions for the three new binary sensors. |
homeassistant/components/prusalink/strings.json |
Adds translations (names) for the new binary sensor entities. |
tests/components/prusalink/conftest.py |
Extends mocked API payloads to include sd_ready, farm_mode, and status_connect. |
tests/components/prusalink/test_binary_sensor.py |
Adds tests validating default enablement and unavailable behavior for new sensors. |
edenhaus
left a comment
There was a problem hiding this comment.
All three sensors are marked unavailable when the respective field is absent from the API response (older firmware may omit some fields).
As in the other PR, we should not mark something unavailable if not supported. Instead we should only create the sensor if supported by the printer.
For example the farm mode (if I understand it correctly) should only be created if the printer is setup in farm_mode makes no sense for all standalone printers users have.
Same for cloud connection.
I personally don't have setup the cloud connection on my printer and so I don't expect any cloud related sensor to be created. The printer can operate without cloud just fine
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
Per review feedback (home-assistant#169310): - Drop available_fn for sd_ready, farm_mode, and status_connect — these fields are absent for permanent reasons (printer model lacks SD slot, user hasn't configured Connect, printer not in a farm setup), not transient ones. Use supported_fn evaluated once in async_setup_entry so the entity is not created at all when unsupported. - farm_mode is created only when farm_mode is True. Rationale: farm mode is a static configuration, not a runtime state. For the ~99% of users running standalone printers, a constant-False sensor is noise. For farm operators, the sensor's existence is itself the signal "this is a farm printer" — useful for filtering and automations. Trade-off: if a farm operator disables farm mode, the entity goes away on next reload, which matches the new reality. - Move duplicated `available` property to PrusaLinkEntity base class per @kclif9 — both PrusaLinkSensorEntity and PrusaLinkBinarySensorEntity had identical overrides. Made defensive so subclasses without entity_description (camera) don't break. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
689cd3a to
77b9e83
Compare
edenhaus
left a comment
There was a problem hiding this comment.
You also forgot to update the icons for the new entities
edenhaus
left a comment
There was a problem hiding this comment.
Please fix the merge request and implement the requested changes
Will get back to this when #170092 is ok 👍 |
Three binary sensors backed by data already fetched by existing coordinators — no pyprusalink changes needed. All inherit the shared `PrusaLinkEntityDescription` (which provides `available_fn` and `supported_fn`) introduced in home-assistant#170092. | Entity | Source | Default | Created when | |---|---|---|---| | SD card (`info.sd_ready`) | /api/v1/info | Disabled | Printer firmware exposes `sd_ready` | | Farm mode (`info.farm_mode`) | /api/v1/info | Disabled | Printer firmware exposes `farm_mode` | | Connectivity (`printer.status_connect.ok`) | /api/v1/status | Enabled | User has set up PrusaConnect (`status_connect` is in the response) | The Connectivity sensor uses `BinarySensorDeviceClass.CONNECTIVITY`, so HA provides the entity name and `_connectivity` entity_id suffix automatically — no `translation_key` or strings entry needed for it. `supported_fn` filters out unsupported entities at setup time so they are not created (rather than created and marked unavailable). This matches the pattern used by sensor.py and the contract documented in home-assistant#170092. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
b70661b to
ea3a9d7
Compare
|
Updated and improved in the last commit as the refactoring #170092 has been merged. |
…home-assistant#169310) Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Proposed change
Adds three binary sensors backed by data already fetched by existing coordinators. No
pyprusalinkchanges needed — all fields are present in the currently-pinned version.info.sd_ready)/api/v1/infoviaInfoUpdateCoordinatorsd_readyinfo.farm_mode)/api/v1/infoviaInfoUpdateCoordinatorfarm_modeprinter.status_connect.ok)/api/v1/statusviaStatusCoordinatorstatus_connectis in the response)Patterns used
BinarySensorDeviceClass.CONNECTIVITY, so HA provides the entity name and_connectivityentity_id suffix automatically — notranslation_key/ strings entry needed for it.PrusaLinkEntityDescriptionintroduced in prusalink: extract PrusaLinkEntityDescription base class #170092 (which carriesavailable_fnandsupported_fn). No local override of those fields or theavailableproperty.supported_fnfilters unsupported entities at setup time so they are not created at all (rather than created and marked unavailable).available_fnis reserved for transient unavailability (e.g. printer offline) per the existing pattern.farm_modeis created whenever the printer firmware exposes the field, regardless of value — supports the standard binary-sensor contract of representing both ON and OFF states.History
This branch was rebased on top of current
devafter #170092 (entity description refactor) and #170099 (location→suggested_area) merged, then the binary-sensor-specific changes were re-applied to fit the new description pattern. The previous commit history is replaced by a single coherent commit.This is part of a series of incremental improvements to the prusalink integration; #169309, #169312, #170092, and #170099 are already merged.
Type of change
Checklist