Add page count sensors to IPP integration#165570
Add page count sensors to IPP integration#165570brianegge wants to merge 7 commits intohome-assistant:devfrom
Conversation
|
Hey there @ctalkington, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
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_ATTRIBUTESrequest 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.
95dac1d to
49f923b
Compare
49f923b to
70fb173
Compare
There was a problem hiding this comment.
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.
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>
ce5b074 to
3070239
Compare
There was a problem hiding this comment.
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.
| sensors.extend( | ||
| IPPPageCountSensor(coordinator, description) | ||
| for description in PAGE_COUNT_SENSORS | ||
| if description.ipp_attribute in coordinator.page_counts | ||
| ) |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
Good suggestion - added debug logging with exc_info=True.
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>
There was a problem hiding this comment.
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_ATTRIBUTEScall 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. |
| 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", | ||
| ), | ||
| ) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
|
Triage request: this PR is blocked by the |
Summary
Get-Printer-AttributesIPP requestprinter-impressions-completed,printer-pages-completed,printer-media-sheets-completed) and collection-based attributes (printer-impressions-completed-colwithmonochrome/full-colorsub-values used by HP printers)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#715Tested on an HP Color LaserJet Pro MFP 3301 which exposes
printer-impressions-completed-colwith monochrome and full-color sub-values.Test plan
🤖 Generated with Claude Code