Skip to content

Add CDM (JSON) API support for newer HP+ printers - #213

Open
HummelsTech wants to merge 2 commits into
elad-bar:masterfrom
HumAssist:master
Open

Add CDM (JSON) API support for newer HP+ printers#213
HummelsTech wants to merge 2 commits into
elad-bar:masterfrom
HumAssist:master

Conversation

@HummelsTech

Copy link
Copy Markdown

Summary

Newer HP+ models (e.g. Envy 6020e/6420e/6520e — reported as "HP Envy 6500e series") no longer expose the legacy LEDM XML endpoints: every /DevMgmt/*.xml request returns 404, so the config flow fails with "Unsupported API". These printers instead serve a JSON-based CDM API under /cdm/ (HTTPS; port 80 redirects to 443).

This PR adds CDM support while keeping LEDM fully intact:

  • Auto-detection of the API variant (LEDM vs CDM) during the config flow and at setup, by probing the main endpoint of each variant. The detected variant is stored in the config entry (api_variant); existing LEDM entries have no such key and keep working unchanged (variant is re-detected at setup when missing).
  • New parameters/data_points_cdm.json mapping CDM resources onto the same property keys as the LEDM data points, so all existing translations, entity descriptions and device naming are reused as-is:
    • /cdm/system/v1/identity → Main (model, SKU, serial, product number)
    • /cdm/system/v1/statusdevice_status (10s interval, same enum sensor; new states idle, initializing, starting, shuttingdown, error, down added with EN/NL translations)
    • /cdm/supply/v1/suppliesPublic → Consumables (level %, level state, brand, slot, install/manufacture dates, selectability number, serial, unique id), identified by supplyColorCode (K/CMY) matching the LEDM label codes
    • /cdm/deviceUsage/v1/lifetimeCounters → Printer / Copy / Scanner page counters
  • REST client: accept application/json responses next to application/javascript/XML, support root-level ("") data paths, and use variant-aware status/main endpoints and offline payload (via new HAConfigManager properties instead of the hardcoded constants).
  • Device ordering: in the CDM data points the Printer sub-unit is defined before the Consumables so via_device exists when cartridge devices are created (avoids the HA "non existing via_device" warning that becomes an error in HA 2025.12).
  • utils/api_test.py: variant-aware main endpoint, prints extracted data, and a Windows selector-event-loop fix.

Probably helps with #176 and similar "Unsupported API" reports for devices that expose the CDM API.

Testing

Tested end-to-end against a live HP Envy 6520e (firmware 6.22.5.27):

  • utils/api_test.py with no api_variant set → detects cdm, extracts Main/Status/Consumables/Printer/Copy/Scanner data correctly
  • Fresh config flow on HA 2026.x → entry created and loaded, title "HP Envy 6500e series (10.2.107.134)"
  • Entities verified: status (inPowerSave → translated), both cartridges incl. levels/dates, print/copy/scan counters
  • LEDM path: no behavioural change (constants kept, same endpoints/payloads; _get_data_section only short-circuits on empty paths, which LEDM never uses)

The manifest version bump to 2.1.0 and the CHANGELOG entry are included for completeness — happy to drop or adjust those if you prefer to manage versioning yourself.

🤖 Generated with Claude Code

HummelsTech and others added 2 commits July 15, 2026 23:53
Newer HP+ models (e.g. Envy 6020e/6420e/6520e "6500e series") no longer
expose the legacy LEDM XML endpoints (/DevMgmt/*.xml return 404) and
instead serve a JSON-based CDM API under /cdm/.

- Auto-detect API variant (LEDM vs CDM) during config flow and setup;
  detected variant is stored in the config entry, existing LEDM
  entries keep working unchanged
- New parameters/data_points_cdm.json mapping CDM resources onto the
  existing property keys (identity, system status, suppliesPublic,
  deviceUsage lifetimeCounters) so translations and entity naming are
  reused as-is
- REST client: parse application/json responses, support root-level
  ("") data paths, variant-aware status/main endpoints and offline
  payload
- New device_status states (idle, initializing, starting,
  shuttingdown, error, down) with EN/NL translations
- utils/api_test.py: variant-aware main endpoint, print extracted
  data, Windows selector event loop fix

Tested end-to-end against an HP Envy 6520e (auto-detect cdm, status,
both cartridges incl. levels, print/copy/scan counters).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Reorder CDM data points so the Printer device exists before consumable
devices reference it as via_device (fixes HA warning about a
non-existing via_device, which becomes an error in HA 2025.12).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vemboy200

Copy link
Copy Markdown

Good news!
It works against my HP OfficeJet Pro 8130e

@HummelsTech

Copy link
Copy Markdown
Author

Good news! It works against my HP OfficeJet Pro 8130e

Glad to know thanks for your feedback

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants