Add MeterReturnEnergy (BC)#29805
Draft
andig wants to merge 6 commits into
Draft
Conversation
)" This reverts commit d5e6253.
Contributor
There was a problem hiding this comment.
Hey - I've found 2 issues, and left some high level feedback:
- In charger/measurement/energy.go, Export is documented as optional but Configure unconditionally dereferences cc.Export; when no export measurement is configured this will panic, so consider only creating exportG (and returning a non-nil third function) when an Export config is present.
- Similarly in meter/measurement/energy.go, Import/Export are described as optional with Energy as a legacy alias, but Configure currently assumes both importCfg and exportCfg are non-nil; making these getters conditional on the corresponding config being set (and returning nil functions otherwise) will better match the API and avoid nil dereferences for meters that only provide one direction.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In charger/measurement/energy.go, Export is documented as optional but Configure unconditionally dereferences cc.Export; when no export measurement is configured this will panic, so consider only creating exportG (and returning a non-nil third function) when an Export config is present.
- Similarly in meter/measurement/energy.go, Import/Export are described as optional with Energy as a legacy alias, but Configure currently assumes both importCfg and exportCfg are non-nil; making these getters conditional on the corresponding config being set (and returning nil functions otherwise) will better match the API and avoid nil dereferences for meters that only provide one direction.
## Individual Comments
### Comment 1
<location path="meter/measurement/energy.go" line_range="44-49" />
<code_context>
+ importCfg = cc.Energy
+ }
+
+ importG, err := importCfg.FloatGetter(ctx)
+ if err != nil {
+ return nil, nil, nil, fmt.Errorf("import: %w", err)
</code_context>
<issue_to_address>
**issue:** Nil checks are missing for optional Import/Export configs and can panic at runtime.
`Import`, `Export`, and `Energy` are documented as optional, but `Configure` always calls `FloatGetter` on `importCfg`/`exportCfg`. When both the main field and legacy alias are nil, this will panic. Please add nil checks (e.g. `if importCfg != nil { ... }`, `if exportCfg != nil { ... }`) and leave the getter nil when no config is provided, consistent with the previous `Energy` handling.
</issue_to_address>
### Comment 2
<location path="charger/measurement/energy.go" line_range="36-41" />
<code_context>
+ importCfg = cc.Energy
+ }
+
+ importG, err := importCfg.FloatGetter(ctx)
+ if err != nil {
+ return nil, nil, nil, fmt.Errorf("import: %w", err)
}
- energyG, err := cc.Energy.FloatGetter(ctx)
+ exportG, err := cc.Export.FloatGetter(ctx)
if err != nil {
- return nil, nil, fmt.Errorf("energy: %w", err)
</code_context>
<issue_to_address>
**issue (bug_risk):** Optional Import/Export configs are dereferenced unconditionally, which can cause nil-pointer panics.
`Import`, `Export`, and `Energy` are optional, but `Configure` unconditionally calls `FloatGetter` on `importCfg` and `cc.Export`. If a charger is configured only with `Power` or only with legacy `Energy` (no `Export`), these calls will panic on nil. Please follow the existing pattern of returning nil getters when a config is absent: guard `FloatGetter` calls with nil checks and only set up `MeterImport`/`MeterExport` when the corresponding configs are present.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
6 tasks
Member
Author
|
@copilot resolve the merge conflicts in this pull request |
Co-authored-by: andig <184815+andig@users.noreply.github.com>
Contributor
Resolved and pushed in 5280bab. I merged Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
- Restore MeterEnergy/TotalEnergy() interface (revert MeterImport/ImportEnergy()). - Add MeterReturnEnergy/ReturnEnergy() in place of MeterExport/ExportEnergy(). - Rename measurement.Energy fields Import/Export -> Energy/ReturnEnergy (YAML config keys: energy, returnEnergy). - Drop AliasImport / LegacyEnergy deprecation shims now that the legacy `energy:` YAML key remains the primary one. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace #29788
See #29784 (comment)
TODO