Skip to content

Fix sensor data not updating for single-connector chargers (#1835)#1902

Open
rishabhvaish wants to merge 2 commits intolbbrhzn:mainfrom
rishabhvaish:fix/sensor-update-connector-remap-1835
Open

Fix sensor data not updating for single-connector chargers (#1835)#1902
rishabhvaish wants to merge 2 commits intolbbrhzn:mainfrom
rishabhvaish:fix/sensor-update-connector-remap-1835

Conversation

@rishabhvaish
Copy link

@rishabhvaish rishabhvaish commented Mar 1, 2026

Summary

  • For single-connector chargers, non-phased measurands (like Current.Offered) sent with connectorId=0 were stored at connector slot 0
  • Meanwhile, process_phases correctly remaps phased values to connector 1
  • This mismatch caused some sensors to intermittently fail to update, especially clock-aligned vs periodic data
  • Fix: remap connectorId=0 to 1 for non-EAIR measurands on single-connector chargers, matching the existing process_phases behavior

Files changed

  • custom_components/ocpp/chargepoint.py — added connector ID remapping for non-phased measurands

Test plan

  • Test with a single-connector Wallbox charger
  • Verify Current.Import and Current.Offered both update on Sample.Periodic
  • Verify Sample.Clock data also updates correctly
  • Verify no regression for multi-connector chargers

Fixes #1835

Summary by CodeRabbit

  • Bug Fixes
    • Fixed measurement allocation when connector identifiers are missing or zero: single-connector chargers now map readings to connector 1, and multi-connector chargers no longer use invalid connector keys. Metrics are now assigned to the correct connector.

For single-connector chargers, non-phased measurands (like Current.Offered)
sent with connectorId=0 were stored at connector slot 0, while process_phases
correctly remaps phased values to connector 1. This mismatch caused some
sensors to never update with periodic data.

Remap connector 0 to 1 for non-EAIR measurands on single-connector chargers,
matching the existing behavior in process_phases.

Fixes lbbrhzn#1835
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 1, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 65f88bf and 9c48de5.

📒 Files selected for processing (1)
  • custom_components/ocpp/chargepoint.py

📝 Walkthrough

Walkthrough

Tightened mapping of non-EAIR measurands to per-connector metrics: when connector_id is None or 0, the code now selects target_cid = 1 for single-connector chargers and 0 for multi-connector chargers, avoiding use of None/0 as dict keys for multi-connector devices.

Changes

Cohort / File(s) Summary
Connector ID mapping
custom_components/ocpp/chargepoint.py
Adjusted logic in process_measurands so target_cid is derived from charger connector count: if connector_id is None or 0, choose 1 for single-connector chargers else 0 for multi-connector chargers; aligns behavior with process_phases and prevents None/0 dict keys.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰
I hopped through code where connectors play,
Turned a zero into one so readings find their way.
No more lost measurands under night or sun,
Single chargers cheer — the mapping’s done! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: remapping connector IDs for single-connector chargers to ensure sensor data updates properly regardless of context.
Linked Issues check ✅ Passed The changes address issue #1835 by remapping connectorId=0 to connector 1 for non-phased measurands on single-connector chargers, ensuring consistent storage behavior with phased measurands and enabling sensor updates on Sample.Periodic context.
Out of Scope Changes check ✅ Passed All changes are within scope, modifying only process_measurands in chargepoint.py to fix connector ID remapping for non-phased measurands on single-connector chargers as specified in issue #1835.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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 and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@custom_components/ocpp/chargepoint.py`:
- Around line 927-934: The current remapping block can leave target_cid as None
for multi-connector chargers; change the logic so connector_id values of None or
0 are always remapped to 1 (matching process_phases behavior) and other values
are used as-is—i.e., compute target_cid from connector_id by treating None and 0
the same way—so look for the block that sets target_cid (uses variables
connector_id and single) and update it to map None -> 1 to avoid inserting
(None, measurand) keys that break _ConnectorAwareMetrics.__getitem__.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bd4a8ee and 65f88bf.

📒 Files selected for processing (1)
  • custom_components/ocpp/chargepoint.py

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Update of sensor on receiving data regardless of the context

1 participant