-
-
Notifications
You must be signed in to change notification settings - Fork 100
Fixed #1452 #1476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed #1452 #1476
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1476 +/- ##
==========================================
+ Coverage 92.74% 92.75% +0.01%
==========================================
Files 12 12
Lines 2025 2028 +3
==========================================
+ Hits 1878 1881 +3
Misses 147 147 ☔ View full report in Codecov by Sentry. |
WalkthroughThe changes involve modifications to the Changes
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
custom_components/ocpp/ocppv16.py (1)
274-278
: Consider adding debug logging before warning.The warning logs are helpful, but consider adding debug logs before the warning to help with troubleshooting. This would provide more context about what led to the failure.
+ _LOGGER.debug( + "Connector %d status notification failed with response: %s", + id, + resp.status, + ) _LOGGER.warning( "Forcing number of connectors to %d, charger returned %d", id - 1, nof_connectors, )
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
custom_components/ocpp/ocppv16.py
(1 hunks)
🔇 Additional comments (2)
custom_components/ocpp/ocppv16.py (2)
274-281
: Enhance error handling for connector status notification failures.The changes improve the robustness of connector state management by:
- Logging detailed information about connector count mismatches
- Ensuring a minimum of one connector remains active
- Breaking the loop on first failure to prevent cascading errors
This aligns with the PR objective to handle connector state notification trigger failures more gracefully.
Let's verify the connector state handling in the codebase:
✅ Verification successful
Connector count handling is correctly implemented
The changes properly handle connector count mismatches by:
- Maintaining system stability with a minimum of one connector
- Breaking on first failure to prevent cascading errors
- Providing detailed logging for debugging
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for other connector state handling implementations and potential edge cases # Search for connector state handling patterns rg -A 5 "connector_id.*status_notification" # Search for connector metrics updates rg -A 5 "connectors.*value.*=.*"Length of output: 1035
Script:
#!/bin/bash # Search for status notification and connector-related patterns rg -A 10 "status_notification|StatusNotification" # Search for connector-related error handling rg -A 5 "connector.*error|error.*connector" # Find metric usage rg -A 3 "cdet\.connectors"Length of output: 25582
279-279
: Verify the minimum connector count assumption.The code assumes that having at least one connector is valid:
self._metrics[cdet.connectors.value].value = max(1, id - 1) return_value = id > 1Please verify this assumption with the OCPP specification. Some charge points might be valid with zero connectors in specific states.
Let's check the codebase for zero-connector handling:
Also applies to: 280-280
✅ Verification successful
The minimum connector count assumption is correct
The code's assumption is valid. In OCPP 1.6:
- Connector ID 0 represents the charge point's main controller (not a physical connector)
- Physical connectors are numbered from 1 onwards
- The code correctly handles both cases:
- Special handling for connector_id=0 for main controller status
- max(1, id - 1) for counting physical connectors
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for zero-connector handling patterns # Search for connector count validations rg "connector.*=.*0" # Search for connector-related error handling ast-grep --pattern 'if $_connector.* [=<>]+ 0 { $$$ }'Length of output: 766
Script:
#!/bin/bash # Search for OCPP 1.6 connector documentation rg -i "connector.*0|connector.*id" custom_components/ocpp/const.py custom_components/ocpp/ocppv16.py -A 2 # Search for any documentation files fd "README|OCPP|\.md$" --exec cat {}Length of output: 44826
custom_components/ocpp/ocppv16.py
Outdated
@@ -271,7 +271,10 @@ async def trigger_status_notification(self): | |||
resp = await self.call(req) | |||
if resp.status != TriggerMessageStatus.accepted: | |||
_LOGGER.warning("Failed with response: %s", resp.status) | |||
return_value = False | |||
_LOGGER.warning("Forcing number of connectors to %d, charger returned %d", id - 1, nof_connectors) | |||
self._metrics[cdet.connectors.value].value = max( 1, id - 1 ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're overriding the cached value for the number of connectors in case of an error. I don't really like this approach, since it can lead to inconsistencies: Any new configuration request for the number of connectors will revert to the old value again. It would be better to introduce a new variable, such as number _of_working_connectors, that is updated instead., It should be initialized to the number returned by the charger, or 1 of the value it outside of the sensible range.
In case connector state notification trigger fails, stop and force the number of connectors equal to last succeeded connector, with a minimum of 1
Summary by CodeRabbit