Skip to content

Planner: simple planning on incomplete rates#26324

Merged
andig merged 9 commits into
evcc-io:masterfrom
iseeberg79:fix/planner_latest
Jan 4, 2026
Merged

Planner: simple planning on incomplete rates#26324
andig merged 9 commits into
evcc-io:masterfrom
iseeberg79:fix/planner_latest

Conversation

@iseeberg79
Copy link
Copy Markdown
Contributor

follow-up on discusson #24423

@evcc-bot evcc-bot added enhancement New feature or request tariffs Specific tariff support labels Jan 1, 2026
@iseeberg79 iseeberg79 changed the title Planner: latest on missing rates Planner: latest continuous on missing rates Jan 1, 2026
@iseeberg79
Copy link
Copy Markdown
Contributor Author

test fails, but not related but interessting...

@iseeberg79 iseeberg79 marked this pull request as ready for review January 1, 2026 12:50
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 left some high level feedback:

  • Consider renaming TestContinuous_StartBeforeRatesInsufficientTime (and possibly its description) to reflect that the behavior is now to start at the latest possible time before the rates window rather than immediately, so the test name matches the updated semantics.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider renaming `TestContinuous_StartBeforeRatesInsufficientTime` (and possibly its description) to reflect that the behavior is now to start at the latest possible time before the rates window rather than immediately, so the test name matches the updated semantics.

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/planner/planner.go Outdated
}

// available window too small for sliding window - charge continuously from now to target
// available window too small for sliding window - charge continuously to target
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.

Wenn der Fall eintreten kann dann aber analog auch für "nicht continuous". Wieso behandeln wir den dann nicht vorher oben?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ja, du hast recht! das erspart hier die Prüfung und sorgt für konsistentes Verhalten für beide Strategien.
Wenn nicht genug Raten verfügbar sind, wird aktuell für non-continuous nicht geprüft, ich dachte - da greift simplePlan bereits.

Es sollte bei nicht ausreichend verfügbaren Tarifdaten und ungenügender Zeit einen simplePlan als Antwort geben?

Es gibt einen Testfall, der das "falsche" Verhalten erwartet:
require.NotEmpty(t, plan, "plan should not be empty - starts when rates become available")

Das würde dann aber tatsächlich dazu führen, das der non-continous eine Stunde zu spät mit der Ladung beginnt?

Verhalten und Test anpassen, ja?

Copy link
Copy Markdown
Contributor Author

@iseeberg79 iseeberg79 Jan 1, 2026

Choose a reason for hiding this comment

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

Test war vor dem continuous Fall offen, ich hab das aktuelle Verhalten ausgedrückt.
Lass uns das anpassen und für beide Fälle bei nicht ausreichend verfügbaren Tarifdaten den simplePlan nutzen

@iseeberg79 iseeberg79 marked this pull request as draft January 1, 2026 13:27
@iseeberg79 iseeberg79 changed the title Planner: latest continuous on missing rates Planner: simple planning on missing rates Jan 1, 2026
@iseeberg79 iseeberg79 marked this pull request as ready for review January 1, 2026 14:21
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 left some high level feedback:

  • The new rate coverage check uses rates[len(rates)-1].End.Sub(rates[0].Start) which ignores both now/targetTime clamping and any gaps inside the window; if the intention is to check the actual usable coverage, consider reusing the clamped start/end logic or explicitly accounting for gaps rather than just span.
  • Previously, insufficient coverage in continuous mode fell back to continuousPlan, but now the early check returns simplePlan for both continuous and dispersed; if this behavioral change is intentional it might be worth making that explicit in code/comments, otherwise consider preserving the earlier continuous-specific fallback.
  • The comment // check if rate coverage is sufficient for planning is quite generic; consider tightening it to describe the exact condition (e.g., that the total span of rate data must cover at least requiredDuration or the planner ignores rates) to avoid misinterpretation during future refactors.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new rate coverage check uses `rates[len(rates)-1].End.Sub(rates[0].Start)` which ignores both `now`/`targetTime` clamping and any gaps inside the window; if the intention is to check the actual usable coverage, consider reusing the clamped start/end logic or explicitly accounting for gaps rather than just span.
- Previously, insufficient coverage in continuous mode fell back to `continuousPlan`, but now the early check returns `simplePlan` for both continuous and dispersed; if this behavioral change is intentional it might be worth making that explicit in code/comments, otherwise consider preserving the earlier continuous-specific fallback.
- The comment `// check if rate coverage is sufficient for planning` is quite generic; consider tightening it to describe the exact condition (e.g., that the total span of rate data must cover at least `requiredDuration` or the planner ignores rates) to avoid misinterpretation during future refactors.

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/planner/planner.go Outdated
rates = clampRates(rates, now, targetTime)

// check if rate coverage is sufficient for planning
if len(rates) > 0 && rates[len(rates)-1].End.Sub(rates[0].Start) < requiredDuration {
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.

Len(rates) muss hier immer größer 0 sein, oder?

This comment was marked as outdated.

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.

Dennoch: len>0 ist hier schon sicher gestellt: https://github.com/evcc-io/evcc/pull/26324/changes#diff-aaad52d4c2a2116a876ad00b56b5959c94db6cbed386b2942f956d044b0ff7c2R125. Lass uns nichts doppeln, das verdeckt nur die echten Probleme.

Copy link
Copy Markdown
Contributor Author

@iseeberg79 iseeberg79 Jan 1, 2026

Choose a reason for hiding this comment

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

ja, siehe oben; aber ich glaube die Prüfung ist notwendig, falls clampRates doch die Rates leert. Es würde was merkwürdiges in der Prüfung beim Array-Zugriff passieren..., lass uns das zur Absicherung der Bedingung drin lassen

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.

Ungern. Wenns die braucht hätte ich gerne einen Test dafür. Ich sehe aber nicht, wie man in den Fall kommen kann.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Der Fall wären wohl verfügbare Raten, vor dem aktuellen Zeitpunkt. Das wird anders nicht abgeprüft. Die Anpassung sollte im Verhalten konsistent und sicher sein und einen panic verhindern:

Suggested change
if len(rates) > 0 && rates[len(rates)-1].End.Sub(rates[0].Start) < requiredDuration {
if len(rates) == 0 || rates[len(rates)-1].End.Sub(rates[0].Start) < requiredDuration {

Einen Test würde ich ergänzen?

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.

ok- aber das sollten wir dann ganz oben abfangen, nicht hier unten wieder neu mit dem Thema anfangen:

	// treat like normal target charging if we don't have rates
	if len(rates) == 0 || err != nil {
		return simplePlan
	}

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.

diese verteilte Logik ist die Hölle. Einmal konsistente Bedingungen herstellen, dann drauf verlassen.

Comment thread core/planner/planner.go
@iseeberg79 iseeberg79 changed the title Planner: simple planning on missing rates Planner: simple planning on incomplete rates Jan 3, 2026
@andig andig merged commit ed9709e into evcc-io:master Jan 4, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request tariffs Specific tariff support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants