Skip to content

prusalink: add sd_ready, farm_mode, and status_connect binary sensors#169310

Merged
joostlek merged 4 commits into
home-assistant:devfrom
heikkih:feat/prusalink-binary-sensors
May 18, 2026
Merged

prusalink: add sd_ready, farm_mode, and status_connect binary sensors#169310
joostlek merged 4 commits into
home-assistant:devfrom
heikkih:feat/prusalink-binary-sensors

Conversation

@heikkih
Copy link
Copy Markdown
Contributor

@heikkih heikkih commented Apr 27, 2026

Proposed change

Adds three binary sensors backed by data already fetched by existing coordinators. No pyprusalink changes needed — all fields are present in the currently-pinned version.

Entity Source Default Created when
SD card (info.sd_ready) /api/v1/info via InfoUpdateCoordinator Disabled Printer firmware exposes sd_ready
Farm mode (info.farm_mode) /api/v1/info via InfoUpdateCoordinator Disabled Printer firmware exposes farm_mode
Connectivity (printer.status_connect.ok) /api/v1/status via StatusCoordinator Enabled User has set up PrusaConnect (status_connect is in the response)

Patterns used

  • The Connectivity sensor uses BinarySensorDeviceClass.CONNECTIVITY, so HA provides the entity name and _connectivity entity_id suffix automatically — no translation_key / strings entry needed for it.
  • All three descriptions inherit the shared PrusaLinkEntityDescription introduced in prusalink: extract PrusaLinkEntityDescription base class #170092 (which carries available_fn and supported_fn). No local override of those fields or the available property.
  • supported_fn filters unsupported entities at setup time so they are not created at all (rather than created and marked unavailable). available_fn is reserved for transient unavailability (e.g. printer offline) per the existing pattern.
  • farm_mode is 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 dev after #170092 (entity description refactor) and #170099 (locationsuggested_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

  • 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 (36 passed)
  • Lint (ruff) and mypy 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

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_connect binary sensor sourced from /api/v1/status and enabled by default.
  • Add sd_ready and farm_mode binary 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.

Comment thread tests/components/prusalink/test_binary_sensor.py
Comment thread homeassistant/components/prusalink/binary_sensor.py
Comment thread homeassistant/components/prusalink/binary_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.

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

@home-assistant home-assistant Bot marked this pull request as draft April 29, 2026 15:46
@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.

heikkih added a commit to heikkih/homeassistant-core that referenced this pull request May 6, 2026
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>
@heikkih heikkih force-pushed the feat/prusalink-binary-sensors branch from 689cd3a to 77b9e83 Compare May 6, 2026 18:38
Copilot AI review requested due to automatic review settings May 6, 2026 18:38
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 6 out of 6 changed files in this pull request and generated 4 comments.

Comment thread homeassistant/components/prusalink/binary_sensor.py
Comment thread homeassistant/components/prusalink/binary_sensor.py Outdated
Comment thread tests/components/prusalink/test_binary_sensor.py Outdated
Comment thread tests/components/prusalink/test_binary_sensor.py Outdated
@heikkih heikkih marked this pull request as ready for review May 6, 2026 18:49
@home-assistant home-assistant Bot requested review from edenhaus and kclif9 May 6, 2026 18:49
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.

You also forgot to update the icons for the new entities

Comment thread homeassistant/components/prusalink/binary_sensor.py Outdated
Comment thread homeassistant/components/prusalink/entity.py Outdated
Comment thread homeassistant/components/prusalink/entity.py Outdated
Comment thread homeassistant/components/prusalink/binary_sensor.py
@home-assistant home-assistant Bot marked this pull request as draft May 7, 2026 09:29
Copilot AI review requested due to automatic review settings May 7, 2026 10:04
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 7 out of 7 changed files in this pull request and generated 2 comments.

Comment thread homeassistant/components/prusalink/binary_sensor.py
Comment thread tests/components/prusalink/test_binary_sensor.py
@heikkih heikkih marked this pull request as ready for review May 7, 2026 10:36
Copilot AI review requested due to automatic review settings May 7, 2026 10:36
@home-assistant home-assistant Bot requested a review from edenhaus May 7, 2026 10:36
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 7 out of 7 changed files in this pull request and generated 2 comments.

Comment thread homeassistant/components/prusalink/binary_sensor.py
Comment thread tests/components/prusalink/test_binary_sensor.py
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 merge request and implement the requested changes

@home-assistant home-assistant Bot marked this pull request as draft May 7, 2026 13:47
@heikkih
Copy link
Copy Markdown
Contributor Author

heikkih commented May 8, 2026

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>
@heikkih heikkih force-pushed the feat/prusalink-binary-sensors branch from b70661b to ea3a9d7 Compare May 8, 2026 10:54
@heikkih heikkih marked this pull request as ready for review May 8, 2026 11:00
Copilot AI review requested due to automatic review settings May 8, 2026 11:00
@home-assistant home-assistant Bot requested a review from edenhaus May 8, 2026 11:00
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
Copy link
Copy Markdown
Contributor Author

heikkih commented May 9, 2026

Updated and improved in the last commit as the refactoring #170092 has been merged.

Copilot AI review requested due to automatic review settings May 15, 2026 09:19
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 2 comments.

Comment thread homeassistant/components/prusalink/binary_sensor.py
Comment thread homeassistant/components/prusalink/binary_sensor.py
@joostlek joostlek dismissed edenhaus’s stale review May 18, 2026 19:56

Merge conflict solved

@joostlek joostlek merged commit ad71e31 into home-assistant:dev May 18, 2026
33 checks passed
jnimmo pushed a commit to jnimmo/core that referenced this pull request May 18, 2026
…home-assistant#169310)

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot locked and limited conversation to collaborators May 19, 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.

5 participants