Skip to content

Add info why optimizer is not requestingan solution - #31919

Draft
achims311 wants to merge 8 commits into
evcc-io:masterfrom
achims311:master
Draft

Add info why optimizer is not requestingan solution#31919
achims311 wants to merge 8 commits into
evcc-io:masterfrom
achims311:master

Conversation

@achims311

Copy link
Copy Markdown

for now the optimizer quitely stops before isueing a request to OPTIMIZER_URL

Now we get a hint why

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The TRACE logs for the optimizer request and result (%+v on req and resp) may reveal sensitive data or produce extremely large log entries; consider reducing the detail or guarding these logs behind a more specific flag.
  • The format string "Optimizer: battery data not ready for now: %s" is passed site.batteryMeters, which is not a string; use %v (or a more appropriate formatter) to avoid incorrect output or runtime issues.
  • Log prefixes are now mixed between "Optimizer:" and "optimizer:"; consider standardizing the prefix casing to keep logs easy to filter and search.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The TRACE logs for the optimizer request and result (`%+v` on `req` and `resp`) may reveal sensitive data or produce extremely large log entries; consider reducing the detail or guarding these logs behind a more specific flag.
- The format string `"Optimizer: battery data not ready for now: %s"` is passed `site.batteryMeters`, which is not a string; use `%v` (or a more appropriate formatter) to avoid incorrect output or runtime issues.
- Log prefixes are now mixed between `"Optimizer:"` and `"optimizer:"`; consider standardizing the prefix casing to keep logs easy to filter and search.

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 core/site_optimizer.go Outdated

gt, err := site.homeProfile(minLen)
if err != nil {
site.log.ERROR.Printf("optimizer: failed to get home profile: %v", err)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Give a hint about he reason why there is no result from the optimizer.
It might help the user to solve the issue

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The error is already returned. You MUST NOT log and return. Instead, return enriched error if necessary.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

New version uploaded

Comment thread core/site_optimizer.go
Comment thread core/site_optimizer.go Outdated
// meters configured but measurements not in yet: retry instead of
// consuming the slot gate
if len(site.batteryMeters) > 0 {
site.log.DEBUG.Printf("optimizer: battery data not ready for now: %v", site.batteryMeters)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Similar reason as above, show the reason why you see the optimizer starting to work, but there is no result visible in the UI. this way you know there is some data missing.

Comment thread core/site_optimizer.go
if err != nil {
return err
}
site.log.TRACE.Printf("optimizer: result: %+v", resp)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For what purpose?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is already in the HTTP log, remove.

@andig
andig marked this pull request as draft July 18, 2026 23:31
@andig

andig commented Jul 18, 2026

Copy link
Copy Markdown
Member

Its unclear what this PR does and what value it adds.

@achims311

Copy link
Copy Markdown
Author

The main reason for me is to avoid questions like I had myself:
I did ask myself why does the optimizer start , but I have no result visible.
With this PR, we always see in the DEBUG output the reason why. So people which are able to see the optimizer starting in the DEBUG logs, they should see as well if there is a reason to have no results until now. There is a hint in the UI it might take some time, but at least for me the time was no reason.
So maybe it would be a good idea to show in the enablement dialog as well the reason why it does not work at the moment?
so run it, and get the information from the run if there will be results, why there are no results until now(which data is missing).

So in total give the user more information if the optimizer does not produce results.

Comment thread core/site_optimizer.go Outdated
Comment thread core/site_optimizer.go
site.log.DEBUG.Printf("optimizer: battery data not ready for now: %v", site.batteryMeters)
return errOptimizerNotReady
}
site.log.DEBUG.Printf("optimizer: no battery data skipping")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

you either have no batteries configured or any of the pervious warnings will have triggered. This one is redundant?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Agreed, it is somewhat redundant.
This happens only if there is at least one battery, but no battery was added in the for loop above.
So you got the warning for each configured battery concerning the mising capacity/soc.

I still think it is useful to have this additional and final message why the optimizer is not ready, at least to understand you need at least one (you could think "I don't care about the warningt here is no capacity, who cares")
On top I think it makes sense to have before each unsuccsesful return a message why. Let's you always better understand what happend.

For me, understandablilty of the behaviour is more important than 1 line of log output.

achims311 and others added 2 commits July 19, 2026 14:12
@github-actions github-actions Bot added the stale Outdated and ready to close label Jul 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Outdated and ready to close

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants