Skip to content

Link devices by device id instead of deprecated identifiers - #2187

Closed
purcell-lab wants to merge 1 commit into
lbbrhzn:mainfrom
purcell-lab:fix/device-registry-deprecations-upstream
Closed

purcell-lab wants to merge 1 commit into
lbbrhzn:mainfrom
purcell-lab:fix/device-registry-deprecations-upstream

Conversation

@purcell-lab

@purcell-lab purcell-lab commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2140

Summary

Home Assistant 2026.9/2026.10 logs two deprecations from this integration:

  • device_registry.async_get_or_create called with the deprecated via_device parameter (__init__.py); this stops working in 2027.8.0. The same applies to DeviceInfo(via_device=…) on the connector entities (sensor, number, switch, button). HA reports only the first occurrence per integration, so these don't appear in the log.
  • device_registry.devices used as a mapping (chargepoint.py, dr.devices.values()); this stops working in 2027.9.0.

Changes

  • Charger devices link to the central system with via_device_id=<central device id>. When a charger shares the central system's identifier, HA merges the two into one device. That device is now left unlinked, because via_device_id rejects a self-reference; the old tuple form silently ignored it.
  • New devices.connector_device_info() builds the connector DeviceInfo with via_device_id, resolved from the charger device in the same config entry. If that device can't be found, the connector is left unlinked rather than failing.
  • ChargePoint.update() walks the entry's devices with device_registry.async_entries_for_config_entry instead of iterating dr.devices.values(). That helper is available on all supported HA versions.
  • Tests:
    • the traversal tests now patch async_entries_for_config_entry;
    • new test_charger_device_linked_to_central_system_without_deprecation asserts the link resolves and no via_device deprecation is logged.

Validation

  • Rebased on current main (e6a95c5). The only conflict was an import line in number.py next to the new TxDefaultProfile option.
  • pytest tests: 567 passed. ruff check and ruff format --check: clean.
  • Running in production since 5 Oct 2026 on HA 2026.10.0b0 with a Sigenergy EVDC 25 (OCPP 1.6J). After a restart the system log shows no ocpp device-registry deprecation warnings, and charger and connector devices keep their hierarchy.

Home Assistant deprecated the via_device identifier tuple on device_registry.async_get_or_create and in entity DeviceInfo (removed in 2027.8), and reading device_registry.devices as a mapping (removed in 2027.9). Live logs reported both from init.py and chargepoint.py.

  • Charger devices link to the central system by its device id; a charger that shares the central system's identifier (merged into one device) is not linked to itself, which via_device_id would reject.
  • Connector devices resolve their charger's device id in this config entry through a shared connector_device_info helper.
  • update() walks the entry's devices with async_entries_for_config_entry.

Claude-Session: https://claude.ai/code/session_01CGcSLnKvwwLo96gDatnNT5

Summary by CodeRabbit

  • Bug Fixes
    • Improved device relationships in Home Assistant: chargers are linked to the central system where applicable, and connector devices are linked to their charger when available.
    • Limited charger updates to devices associated with the current integration entry.

Home Assistant deprecated the via_device identifier tuple on
device_registry.async_get_or_create and in entity DeviceInfo (removed in
2027.8), and reading device_registry.devices as a mapping (removed in
2027.9). Live logs reported both from __init__.py and chargepoint.py.

- Charger devices link to the central system by its device id; a charger
  that shares the central system's identifier (merged into one device) is
  not linked to itself, which via_device_id would reject.
- Connector devices resolve their charger's device id in this config entry
  through a shared connector_device_info helper.
- update() walks the entry's devices with async_entries_for_config_entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CGcSLnKvwwLo96gDatnNT5
@purcell-lab
purcell-lab deployed to continuous-integration October 6, 2026 10:04 — with GitHub Actions Active
@coderabbitai

coderabbitai Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0a3316a2-da85-4149-86bd-dc52b35bcf7c
📥 Commits

Reviewing files that changed from the base of the PR and between e6a95c5 and 41071e6.

📒 Files selected for processing (9)
  • custom_components/ocpp/__init__.py
  • custom_components/ocpp/button.py
  • custom_components/ocpp/chargepoint.py
  • custom_components/ocpp/devices.py
  • custom_components/ocpp/number.py
  • custom_components/ocpp/sensor.py
  • custom_components/ocpp/switch.py
  • tests/test_init.py
  • tests/test_more_coverage_chargepoint.py
 ______________________________________________________________________________________________________________________
< Design with contracts. Use contracts to document and verify that code does no more and no less than it claims to do. >
 ----------------------------------------------------------------------------------------------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@purcell-lab purcell-lab closed this Oct 6, 2026
@codecov

codecov Bot commented Oct 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.85714% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.34%. Comparing base (8d07bd8) to head (41071e6).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
custom_components/ocpp/devices.py 93.75% 1 Missing ⚠️
custom_components/ocpp/number.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2187      +/-   ##
==========================================
+ Coverage   97.30%   97.34%   +0.04%     
==========================================
  Files          12       13       +1     
  Lines        4265     4375     +110     
==========================================
+ Hits         4150     4259     +109     
- Misses        115      116       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch was successfully deployed

1 active deployment
continuous-integration — 41071e65 Deployed Oct 6, 2026 by purcell-lab via Run tests #3732
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.

OCPP integration using soon to be deprecated device_registry.devices parameter.

2 participants