Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion assets/js/components/Optimize/OptimizeHeader.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ const base = {
updated: new Date(Date.now() - 2 * 60 * 1000).toISOString(),
horizonHours: 47,
currency: CURRENCY.EUR,
chargingStrategies: ["charge_before_export", "attenuate_grid_peaks", "none"],
chargingStrategies: [
"charge_before_export",
"attenuate_demand_peaks",
"attenuate_feedin_peaks",
"attenuate_grid_peaks",
"none",
],
selectedStrategy: "charge_before_export",
pending: false,
};
Expand Down
2 changes: 2 additions & 0 deletions assets/js/components/Optimize/OptimizeHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ import "@h2d2/shopicons/es/regular/info";
// themselves come from backend state to avoid drift if the enum changes
const STRATEGY_LABELS: Record<string, string> = {
charge_before_export: "fill battery first",
attenuate_demand_peaks: "reduce grid import peaks",
attenuate_feedin_peaks: "reduce grid feed-in peaks",
Comment on lines +126 to +127

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.

suggestion: Tighten the type of STRATEGY_LABELS to the known strategy key union instead of Record<string, string>.

Because these keys correspond to a finite backend enum, typing this as Record<OptimizerChargingStrategy, string> or a union of the literal keys will catch typos and missing strategies at compile time instead of only at runtime, and will scale better as the list grows.

Suggested implementation:

type OptimizerChargingStrategy =
	| "charge_before_export"
	| "attenuate_demand_peaks"
	| "attenuate_feedin_peaks"
	| "attenuate_grid_peaks"
	| "none";

// themselves come from backend state to avoid drift if the enum changes
const STRATEGY_LABELS: Record<OptimizerChargingStrategy, string> = {
	charge_before_export: "fill battery first",
	attenuate_demand_peaks: "reduce grid import peaks",
	attenuate_feedin_peaks: "reduce grid feed-in peaks",
	attenuate_grid_peaks: "reduce grid peaks",
	none: "no preference",
};

If a shared OptimizerChargingStrategy type already exists in your backend-typed models (e.g. in a types or api module), prefer importing that instead of defining the local union:

  1. Remove the local type OptimizerChargingStrategy = ... definition.
  2. Add import type { OptimizerChargingStrategy } from "<appropriate-path>"; at the top of the <script> block.
  3. Keep const STRATEGY_LABELS: Record<OptimizerChargingStrategy, string> = { ... } as-is.

This ensures the labels stay in sync with the backend enum and that missing/extra strategies are caught at compile time.

attenuate_grid_peaks: "reduce grid peaks",
none: "no preference",
};
Expand Down
2 changes: 1 addition & 1 deletion core/optimizer.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Optimizer uses mixed integer linear programming (MILP) to minize a cost function
- solar forecast
- base load (aka home) energy demand
- end of forecast commercial value
- strategy- either "charge before export" (charge loads as soon as possible) or "attenuate grid peaks"
- strategy- either "charge before export" (charge loads as soon as possible) or attenuating grid peaks on the demand side, the feed-in side or both
- home battery or loadpoint/vehicle...
- capacity, soc and charge goals
- charge/discharge power limits and efficiency
Expand Down
2 changes: 2 additions & 0 deletions core/site_optimizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ var (
// entry is the default and preserves the previous hard-coded behavior.
var optimizerChargingStrategies = []string{
string(optimizer.OptimizerStrategyChargingStrategyChargeBeforeExport),
string(optimizer.OptimizerStrategyChargingStrategyAttenuateDemandPeaks),
string(optimizer.OptimizerStrategyChargingStrategyAttenuateFeedinPeaks),
string(optimizer.OptimizerStrategyChargingStrategyAttenuateGridPeaks),
string(optimizer.OptimizerStrategyChargingStrategyNone),
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ require (
github.com/enbility/ship-go v0.6.1-0.20260720110450-0aa90f64ac76
github.com/enbility/spine-go v0.7.1-0.20260629113257-b3bcc643f323
github.com/evcc-io/openapi-mcp v0.6.1-0.20260701153510-26c442199ef4
github.com/evcc-io/optimizer v0.0.0-20260719151136-b6c835a178a3
github.com/evcc-io/optimizer v0.0.0-20260724075549-cce0c41d9489
github.com/evcc-io/rct v0.2.0
github.com/evcc-io/tesla-proxy-client v0.0.0-20260722070723-f3604323d820
github.com/fatih/structs v1.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ github.com/evcc-io/ocpp-go v0.0.0-20251212212612-b7f92ee0443b h1:5vFr7wOwoi5ylyb
github.com/evcc-io/ocpp-go v0.0.0-20251212212612-b7f92ee0443b/go.mod h1:2kcukDdhui4u730VfnYVWuwzDLgw+mBRGDir/QAyBhg=
github.com/evcc-io/openapi-mcp v0.6.1-0.20260701153510-26c442199ef4 h1:aGM3NwDsKbnmiaO10ptbvEolRAUThWJEsObiAWFDU/c=
github.com/evcc-io/openapi-mcp v0.6.1-0.20260701153510-26c442199ef4/go.mod h1:YyOx4zwr6xVUcchAETHERZ+75cZMIrdcjVIZFwBlE1Q=
github.com/evcc-io/optimizer v0.0.0-20260719151136-b6c835a178a3 h1:QXk6AKYrYWQ+PxXhJS/LcHnegKFCCClUQ/BlCuqbs9Y=
github.com/evcc-io/optimizer v0.0.0-20260719151136-b6c835a178a3/go.mod h1:cHMeq6GfoXQ8LxqY4LH1wn/hrgYEn+ka5RPI1CF37SY=
github.com/evcc-io/optimizer v0.0.0-20260724075549-cce0c41d9489 h1:iM7XzdAI07Ff9uJtu7MS8wg2q0hH/84JtrQNbgGn1oo=
github.com/evcc-io/optimizer v0.0.0-20260724075549-cce0c41d9489/go.mod h1:cHMeq6GfoXQ8LxqY4LH1wn/hrgYEn+ka5RPI1CF37SY=
github.com/evcc-io/rct v0.2.0 h1:qjXKI7NKwW5YpEKEb27MwLMBaR4ne2Kd2cPV2PYTKn4=
github.com/evcc-io/rct v0.2.0/go.mod h1:n6MTBU36QOadGlxxiADu86VaT5l0eYdbmFBHF14AD/s=
github.com/evcc-io/tesla-proxy-client v0.0.0-20260722070723-f3604323d820 h1:qpLoOYEJ6dgD+UBEgwzsIiQ3WLPmi3Xb7EN4wFIypQY=
Expand Down
Loading