Skip to content

Add page count sensors to IPP integration#165570

Open
brianegge wants to merge 7 commits intohome-assistant:devfrom
brianegge:claude/zealous-shtern
Open

Add page count sensors to IPP integration#165570
brianegge wants to merge 7 commits intohome-assistant:devfrom
brianegge:claude/zealous-shtern

Conversation

@brianegge
Copy link
Copy Markdown
Contributor

Summary

  • Adds page count sensors to the IPP integration by fetching additional printer attributes via a separate Get-Printer-Attributes IPP request
  • Supports both simple integer attributes (printer-impressions-completed, printer-pages-completed, printer-media-sheets-completed) and collection-based attributes (printer-impressions-completed-col with monochrome/full-color sub-values used by HP printers)
  • Sensors are only created when the printer exposes the corresponding attributes, so existing setups are unaffected

Details

The pyipp library doesn't currently request or parse page count attributes. This PR works around that by using ipp.execute() directly to request these attributes in a separate call. An upstream PR to add native support in pyipp has been opened: ctalkington/python-ipp#715

Tested on an HP Color LaserJet Pro MFP 3301 which exposes printer-impressions-completed-col with monochrome and full-color sub-values.

Test plan

  • All 29 existing IPP tests pass
  • Snapshot tests updated to include new page count sensors
  • Tested on live HP Color LaserJet Pro MFP 3301 - monochrome and color impression sensors created and reporting correctly
  • Verified printers not exposing page counts create no new entities

🤖 Generated with Claude Code

@home-assistant
Copy link
Copy Markdown
Contributor

Hey there @ctalkington, mind taking a look at this pull request as it has been labeled with an integration (ipp) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of ipp can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign ipp Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

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 page-count diagnostic sensors to the IPP integration by issuing an additional Get-Printer-Attributes request and exposing relevant counters as Home Assistant sensor entities.

Changes:

  • Fetch page count attributes via a separate IPP GET_PRINTER_ATTRIBUTES request and parse both integer and collection-based counter attributes.
  • Add new diagnostic sensors for pages/impressions/media sheets completed (including monochrome/full-color impressions where available).
  • Update fixtures and snapshots to include the new entities, plus add translation strings and icons.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
homeassistant/components/ipp/coordinator.py Adds page count attribute fetch + parsing and stores results on the coordinator.
homeassistant/components/ipp/sensor.py Defines page count sensor descriptions and entities; conditionally adds them based on fetched attributes.
homeassistant/components/ipp/strings.json Adds names for new sensor translation keys.
homeassistant/components/ipp/icons.json Adds default icons for the new sensors.
tests/components/ipp/conftest.py Extends mocked IPP client to return page-count attributes for tests.
tests/components/ipp/snapshots/test_sensor.ambr Updates sensor snapshots to include the newly created page-count entities.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread homeassistant/components/ipp/coordinator.py
Comment thread homeassistant/components/ipp/sensor.py Outdated
@brianegge brianegge force-pushed the claude/zealous-shtern branch from 95dac1d to 49f923b Compare March 14, 2026 20:49
Copilot AI review requested due to automatic review settings March 14, 2026 20:50
@brianegge brianegge force-pushed the claude/zealous-shtern branch from 49f923b to 70fb173 Compare March 14, 2026 20:50
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 optional page count sensors to the IPP integration by issuing an additional Get-Printer-Attributes request and exposing any supported counter attributes as diagnostic sensors.

Changes:

  • Extend the IPP coordinator to fetch and parse page count attributes (including collection-based HP counters) into coordinator.page_counts.
  • Add new sensor entities that are only created when the corresponding IPP attributes are present.
  • Update/extend test fixtures, snapshots, and add a regression test ensuring no new sensors are created when unsupported.

Reviewed changes

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

Show a summary per file
File Description
homeassistant/components/ipp/coordinator.py Adds a second IPP request to fetch page-count-related attributes and parses them into page_counts.
homeassistant/components/ipp/sensor.py Introduces page count sensor descriptions/entities and conditionally sets them up based on available attributes.
homeassistant/components/ipp/strings.json Adds translation strings for new page count sensors.
homeassistant/components/ipp/icons.json Adds default icons for the new page count sensors.
tests/components/ipp/conftest.py Extends the mocked IPP client to return page count attributes for snapshot tests.
tests/components/ipp/test_sensor.py Adds a test ensuring no page count sensors/entities are created when attributes are absent.
tests/components/ipp/snapshots/test_sensor.ambr Updates snapshots to include the newly added page count sensors.

You can also share your feedback on Copilot code review. Take the survey.

brianegge and others added 3 commits March 15, 2026 15:19
Fetch page count attributes from IPP printers via a separate
Get-Printer-Attributes request. Supports both simple integer
attributes (printer-impressions-completed, printer-pages-completed,
printer-media-sheets-completed) and collection-based attributes
(printer-impressions-completed-col with monochrome/full-color
sub-values). Sensors are only created when the printer exposes
the corresponding attributes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Sort strings.json keys alphabetically to pass prek checks
- Preserve previous page_counts on transient fetch failure
- Add test for printers that don't support page count attributes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 15, 2026 19:19
@brianegge brianegge force-pushed the claude/zealous-shtern branch from ce5b074 to 3070239 Compare March 15, 2026 19: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

Adds page count sensors to the IPP integration by issuing an additional Get-Printer-Attributes request to retrieve page/impression counters (including HP-style collection attributes) and exposing them as diagnostic sensors.

Changes:

  • Extend the IPP coordinator to fetch and parse page count attributes via ipp.execute(...).
  • Add new diagnostic sensor entities for page/impression/media-sheet counters (including monochrome/full-color breakdown).
  • Update translations/icons and test snapshots; add a test ensuring no sensors are created when counters aren’t exposed.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
homeassistant/components/ipp/coordinator.py Adds a second IPP request to fetch page-count attributes and stores parsed results on the coordinator.
homeassistant/components/ipp/sensor.py Defines page-count sensor descriptions/entities and conditionally adds them based on fetched attributes.
homeassistant/components/ipp/strings.json Adds translation keys/names for the new sensors.
homeassistant/components/ipp/icons.json Adds default icons for the new sensors.
tests/components/ipp/conftest.py Extends the IPP mock to return page-count attributes for tests.
tests/components/ipp/test_sensor.py Adds coverage for the “unsupported page counts” case.
tests/components/ipp/snapshots/test_sensor.ambr Updates snapshots to include new entities and states.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +173 to +177
sensors.extend(
IPPPageCountSensor(coordinator, description)
for description in PAGE_COUNT_SENSORS
if description.ipp_attribute in coordinator.page_counts
)
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.

The current approach is intentional - page count sensors are only created when the printer supports them. For printers that don't report these attributes, creating unavailable entities would add noise. A transient failure on first refresh is unlikely since IPP printers are local network devices.

},
},
)
except IPPError:
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 suggestion - added debug logging with exc_info=True.

brianegge and others added 3 commits March 22, 2026 07:53
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Merge upstream dev to pick up entity registry changes, regenerate
test snapshots, and update tests to look up entities by unique_id
instead of hardcoded entity_ids that depend on translation resolution.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 26, 2026 12:05
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 page count (lifetime counter) sensors to the IPP integration by performing an additional IPP Get-Printer-Attributes request and exposing supported attributes as diagnostic sensors.

Changes:

  • Fetch and cache page-count-related IPP attributes via a separate GET_PRINTER_ATTRIBUTES call in the coordinator.
  • Add new diagnostic sensors for total page/impression/media-sheet counts, including HP “collection” counters (mono/color).
  • Extend tests/fixtures and snapshots, plus add a negative test to ensure no entities are created when counters are unsupported.

Reviewed changes

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

Show a summary per file
File Description
homeassistant/components/ipp/coordinator.py Adds periodic page-count attribute fetch via ipp.execute(...) and caches parsed counters.
homeassistant/components/ipp/sensor.py Introduces page-count sensor descriptions and conditionally creates entities based on discovered counters.
homeassistant/components/ipp/strings.json Adds translation names for the new page-count sensors.
homeassistant/components/ipp/icons.json Adds default icons for the new page-count sensors.
tests/components/ipp/conftest.py Extends the IPP client mock to return page-count attributes from execute().
tests/components/ipp/test_sensor.py Makes disabled-by-default test more robust and adds coverage for “unsupported counters” case.
tests/components/ipp/snapshots/test_sensor.ambr Updates snapshots to include the new page-count sensors.

Comment on lines +93 to +129
PAGE_COUNT_SENSORS: tuple[IPPPageCountSensorEntityDescription, ...] = (
IPPPageCountSensorEntityDescription(
key="pages_completed",
translation_key="pages_completed",
state_class=SensorStateClass.TOTAL_INCREASING,
entity_category=EntityCategory.DIAGNOSTIC,
ipp_attribute="printer-pages-completed",
),
IPPPageCountSensorEntityDescription(
key="impressions_completed",
translation_key="impressions_completed",
state_class=SensorStateClass.TOTAL_INCREASING,
entity_category=EntityCategory.DIAGNOSTIC,
ipp_attribute="printer-impressions-completed",
),
IPPPageCountSensorEntityDescription(
key="media_sheets_completed",
translation_key="media_sheets_completed",
state_class=SensorStateClass.TOTAL_INCREASING,
entity_category=EntityCategory.DIAGNOSTIC,
ipp_attribute="printer-media-sheets-completed",
),
IPPPageCountSensorEntityDescription(
key="impressions_completed_monochrome",
translation_key="impressions_completed_monochrome",
state_class=SensorStateClass.TOTAL_INCREASING,
entity_category=EntityCategory.DIAGNOSTIC,
ipp_attribute="printer-impressions-completed-col/monochrome",
),
IPPPageCountSensorEntityDescription(
key="impressions_completed_full_color",
translation_key="impressions_completed_full_color",
state_class=SensorStateClass.TOTAL_INCREASING,
entity_category=EntityCategory.DIAGNOSTIC,
ipp_attribute="printer-impressions-completed-col/full-color",
),
)
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

Ensure page-count sensors get stable, descriptive entity IDs by providing a deterministic suggested object id (e.g., derived from the description key) instead of relying on the default naming, which currently results in numbered IDs like ..._3/..._4 in the snapshots.

Copilot uses AI. Check for mistakes.
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.

The numbered entity IDs (_3/_4) in the previous snapshots were due to missing generated translation files during local testing. The snapshots have been regenerated with translations properly resolved, and entity IDs are now descriptive (e.g., sensor.test_ha_1000_series_pages_completed, sensor.test_ha_1000_series_impressions_completed). The translation_key on each description is the standard HA mechanism for deriving entity names/IDs.

Previous snapshot generation was missing translation files, causing
entity IDs to be generic numbered suffixes instead of proper names.
Generated translations first, then regenerated snapshots.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@brianegge
Copy link
Copy Markdown
Contributor Author

Triage request: this PR is blocked by the required-labels check. Could a maintainer apply the new-feature label? CI is green, code-owner approval is in, and the bot's add-label command doesn't accept new-feature. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants