Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jthun
Copy link
Contributor

@jthun jthun commented Oct 12, 2025

Resolves #1762.

Summary by CodeRabbit

  • New Features
    • Ensures charge point buttons immediately appear available after reload.
  • Bug Fixes
    • Sensors and numbers now refresh only when relevant, improving update accuracy.
    • Reliable cleanup of update listeners when entities are removed.
  • Performance Improvements
    • Reduces unnecessary updates by filtering out disabled or unloaded entities.
    • Uses targeted dispatcher notifications with active entities to minimize overhead.
  • Refactor
    • Streamlined internal update flow across buttons, sensors, and numbers for more efficient, event-driven state updates.

@jthun jthun temporarily deployed to continuous-integration October 12, 2025 12:19 — with GitHub Actions Inactive
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 12, 2025

Walkthrough

Introduces filtered update dispatching from ChargePoint.update that sends a set of active entity_ids via DATA_UPDATED. Entities (sensor/number/button) switch to a local _maybe_update callback that schedules updates only when applicable. Button adds async_added_to_hass to register the dispatcher listener and ensure availability after reload.

Changes

Cohort / File(s) Summary
Filtered dispatch and traversal
custom_components/ocpp/chargepoint.py
Removes unused import, adds local type annotations, filters out disabled/unloaded entities, collects active entity_ids, and dispatches DATA_UPDATED with active_entities payload; maintains child traversal.
Dispatcher handler refactor (selective updates)
custom_components/ocpp/number.py, custom_components/ocpp/sensor.py
Replaces direct dispatcher callback with inline _maybe_update that interprets first arg as active set and schedules updates conditionally; registers via hass dispatcher and cleans up with async_on_remove; removes prior immediate-update methods.
Button lifecycle listener
custom_components/ocpp/button.py
Adds async_added_to_hass to register DATA_UPDATED listener via async_dispatcher_connect, wraps handler in callback, and schedules state updates based on incoming args; ensures availability on reload; updates imports.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant CP as ChargePoint.update
  participant HA as HA Dispatcher
  participant ENT as Entities (Sensor/Number/Button)

  CP->>CP: Traverse devices
  CP->>CP: Filter disabled/unloaded entities
  CP->>HA: dispatch(DATA_UPDATED, active_entities)
  note over HA: active_entities: Set[str] or None

  par For each subscribed entity
    HA-->>ENT: DATA_UPDATED(active_entities)
    ENT->>ENT: _maybe_update(active_lookup)
    alt included or lookup is None
      ENT->>ENT: schedule_update_ha_state(immediate=True)
    else not included
      ENT-->>ENT: ignore
    end
  end

  note over ENT: Button registers listener in async_added_to_hass
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

Thump-thump goes my coder heart, hop-hop through the queue,
I trim the noisy updates, only wake the chosen few.
Signals sift like carrot seeds, each sprout gets its turn,
Disabled buds stay sleeping still—no needless churn.
In the warren of events, I twitch, dispatch, and view—
A tidy burrow of entities, all doing what they’re due.

Pre-merge checks and finishing touches

✅ 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 succinctly indicates the primary change by specifying that the integration will now handle disabled entities differently, directly reflecting the PR goal. It clearly relates to the PR’s objective of preventing update triggers for disabled entities. It is concise and specific enough to inform reviewers of the core change.
Linked Issues Check ✅ Passed The changes implement filtering of disabled entities in ChargePoint.update by skipping disabled and unloaded entities and dispatching DATA_UPDATED only with active_entities. The entity classes now register dispatcher listeners that schedule updates only when the entity ID appears in the active set or when no specific set is provided. This ensures disabled entities will not receive update triggers. Therefore, the PR fulfills the requirement of preventing update triggers for disabled entities described in issue #1762.
Out of Scope Changes Check ✅ Passed All modifications focus exclusively on filtering update triggers for disabled entities by adjusting the update logic and dispatcher handling in the ChargePoint, sensor, number, and button components. No unrelated features or functionality were introduced. Thus, the PR contains no out-of-scope changes.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3ce65ab and 4b49e21.

📒 Files selected for processing (4)
  • custom_components/ocpp/button.py (2 hunks)
  • custom_components/ocpp/chargepoint.py (2 hunks)
  • custom_components/ocpp/number.py (1 hunks)
  • custom_components/ocpp/sensor.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
custom_components/ocpp/button.py (2)
custom_components/ocpp/number.py (2)
  • async_added_to_hass (196-216)
  • _maybe_update (203-212)
custom_components/ocpp/sensor.py (2)
  • async_added_to_hass (341-365)
  • _maybe_update (350-359)
custom_components/ocpp/number.py (2)
custom_components/ocpp/button.py (1)
  • _maybe_update (187-197)
custom_components/ocpp/sensor.py (1)
  • _maybe_update (350-359)
custom_components/ocpp/sensor.py (2)
custom_components/ocpp/button.py (1)
  • _maybe_update (187-197)
custom_components/ocpp/number.py (1)
  • _maybe_update (203-212)
custom_components/ocpp/chargepoint.py (1)
tests/test_more_coverage_chargepoint.py (5)
  • async_get_device (210-211)
  • async_get_device (313-314)
  • devices (217-219)
  • devices (317-323)
  • values (320-321)
🔇 Additional comments (4)
custom_components/ocpp/number.py (1)

202-216: Filtered dispatcher listener looks solid

Gating the scheduled update on the active entity-id set cleanly prevents disabled numbers from being poked while still handling legacy no-arg dispatches. Nicely defensive.

custom_components/ocpp/button.py (1)

14-205: Button now participates in filtered updates

Registering the listener during async_added_to_hass and rechecking availability after reload keeps buttons aligned with the new active-entity dispatch without over-updating. Good call.

custom_components/ocpp/sensor.py (1)

345-363: Sensor update listener matches the filtered payload

The inner callback gracefully copes with both legacy and new dispatch shapes and avoids hammering disabled sensors. Looks great.

custom_components/ocpp/chargepoint.py (1)

19-637: DATA_UPDATED listeners accept varargs All registered _maybe_update callbacks in sensor.py, number.py, and button.py are defined with *args, so the new dispatch signature poses no risk.


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.

@codecov
Copy link

codecov bot commented Oct 12, 2025

Codecov Report

❌ Patch coverage is 83.33333% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.19%. Comparing base (3ce65ab) to head (4b49e21).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
custom_components/ocpp/button.py 87.50% 2 Missing ⚠️
custom_components/ocpp/chargepoint.py 80.00% 2 Missing ⚠️
custom_components/ocpp/number.py 81.81% 2 Missing ⚠️
custom_components/ocpp/sensor.py 81.81% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1763      +/-   ##
==========================================
- Coverage   95.42%   95.19%   -0.23%     
==========================================
  Files          12       12              
  Lines        2883     2914      +31     
==========================================
+ Hits         2751     2774      +23     
- Misses        132      140       +8     

☔ View full report in Codecov by Sentry.
📢 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.

@jthun jthun marked this pull request as ready for review October 12, 2025 12:24
@drc38 drc38 merged commit 97cd770 into lbbrhzn:main Oct 12, 2025
7 of 9 checks passed
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.

Entity is incorrectly being triggered for updates while it is disabled

2 participants