Skip to content

Add MeterReturnEnergy (BC)#29805

Draft
andig wants to merge 6 commits into
masterfrom
feat/importexport
Draft

Add MeterReturnEnergy (BC)#29805
andig wants to merge 6 commits into
masterfrom
feat/importexport

Conversation

@andig
Copy link
Copy Markdown
Member

@andig andig commented May 10, 2026

Replace #29788

See #29784 (comment)

TODO

@andig andig added the infrastructure Basic functionality label May 10, 2026
@andig andig requested review from naltatis and premultiply May 10, 2026 08:55
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread meter/measurement/energy.go Outdated
Comment thread charger/measurement/energy.go Outdated
@andig andig added the needs documentation Triggers issue creation in evcc-io/docs label May 10, 2026
@naltatis naltatis removed the needs documentation Triggers issue creation in evcc-io/docs label May 12, 2026
@naltatis naltatis mentioned this pull request May 12, 2026
6 tasks
@andig andig added the backlog Things to do later label May 12, 2026
@andig
Copy link
Copy Markdown
Member Author

andig commented May 15, 2026

@copilot resolve the merge conflicts in this pull request

Co-authored-by: andig <184815+andig@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented May 15, 2026

@copilot resolve the merge conflicts in this pull request

Resolved and pushed in 5280bab. I merged master into this branch, resolved all merge conflicts, regenerated api/implement/implementations.go, and validated with targeted Go tests plus parallel validation.

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:

  • 224.0.0.251
    • Triggering command: REDACTED, pid is -1 (packet block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of andig May 15, 2026 08:59
@andig andig changed the title Split MeterEnergy into MeterImport and MeterExport (BC) Add MeterReturnEnergy (BC) May 15, 2026
@andig andig marked this pull request as draft May 15, 2026 10:04
- 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backlog Things to do later infrastructure Basic functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants