Revert "Planner: add continuous strategy (BC) (#24423)"

This reverts commit 291898fea9.
This commit is contained in:
andig 2025-12-31 11:30:23 +01:00
parent 6f28537531
commit 7acc133f3c
68 changed files with 950 additions and 2245 deletions

View file

@ -5,31 +5,31 @@ import (
"fmt"
"net/http"
"strconv"
"strings"
"time"
"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/core/loadpoint"
"github.com/evcc-io/evcc/core/site"
"github.com/evcc-io/evcc/util"
"github.com/gorilla/mux"
)
type PlanResponse struct {
PlanId int `json:"planId"`
PlanTime time.Time `json:"planTime"`
Duration int64 `json:"duration"`
Plan api.Rates `json:"plan"`
Power float64 `json:"power"`
PlanId int `json:"planId"`
PlanTime time.Time `json:"planTime"`
Duration int64 `json:"duration"`
Precondition int64 `json:"precondition"`
Plan api.Rates `json:"plan"`
Power float64 `json:"power"`
}
type PlanPreviewResponse struct {
PlanTime time.Time `json:"planTime"`
Duration int64 `json:"duration"`
Plan api.Rates `json:"plan"`
Power float64 `json:"power"`
// TODO remove
Continuous bool `json:"continuous"`
Precondition int64 `json:"precondition"`
PlanTime time.Time `json:"planTime"`
Duration int64 `json:"duration"`
Precondition int64 `json:"precondition"`
Plan api.Rates `json:"plan"`
Power float64 `json:"power"`
}
// planHandler returns the current plan
@ -40,16 +40,17 @@ func planHandler(lp loadpoint.API) http.HandlerFunc {
id := lp.EffectivePlanId()
goal, _ := lp.GetPlanGoal()
precondition := lp.GetPlanPreCondDuration()
requiredDuration := lp.GetPlanRequiredDuration(goal, maxPower)
strategy := lp.EffectivePlanStrategy()
plan := lp.GetPlan(planTime, requiredDuration, strategy.Precondition, strategy.Continuous)
plan := lp.GetPlan(planTime, requiredDuration, precondition)
res := PlanResponse{
PlanId: id,
PlanTime: planTime,
Duration: int64(requiredDuration.Seconds()),
Plan: plan,
Power: maxPower,
PlanId: id,
PlanTime: planTime,
Duration: int64(requiredDuration.Seconds()),
Precondition: int64(precondition.Seconds()),
Plan: plan,
Power: maxPower,
}
jsonWrite(w, res)
@ -60,6 +61,7 @@ func planHandler(lp loadpoint.API) http.HandlerFunc {
func staticPlanPreviewHandler(lp loadpoint.API) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
query := r.URL.Query()
planTime, err := time.ParseInLocation(time.RFC3339, vars["time"], nil)
if err != nil {
@ -73,6 +75,12 @@ func staticPlanPreviewHandler(lp loadpoint.API) http.HandlerFunc {
return
}
precondition, err := parseDuration(query.Get("precondition"))
if err != nil {
jsonError(w, http.StatusBadRequest, err)
return
}
switch typ := vars["type"]; typ {
case "soc":
if !lp.SocBasedPlanning() {
@ -91,19 +99,66 @@ func staticPlanPreviewHandler(lp loadpoint.API) http.HandlerFunc {
maxPower := lp.EffectiveMaxPower()
requiredDuration := lp.GetPlanRequiredDuration(goal, maxPower)
strategy := lp.EffectivePlanStrategy()
plan := lp.GetPlan(planTime, requiredDuration, strategy.Precondition, strategy.Continuous)
plan := lp.GetPlan(planTime, requiredDuration, precondition)
res := PlanPreviewResponse{
PlanTime: planTime,
Duration: int64(requiredDuration.Seconds()),
Plan: plan,
Power: maxPower,
PlanTime: planTime,
Duration: int64(requiredDuration.Seconds()),
Precondition: int64(precondition.Seconds()),
Plan: plan,
Power: maxPower,
}
// TODO remove
Continuous: strategy.Continuous,
Precondition: int64(strategy.Precondition.Seconds()),
jsonWrite(w, res)
}
}
func repeatingPlanPreviewHandler(lp loadpoint.API) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
query := r.URL.Query()
hourMinute := vars["time"]
tz := vars["tz"]
var weekdays []int
for weekdayStr := range strings.SplitSeq(vars["weekdays"], ",") {
weekday, err := strconv.Atoi(weekdayStr)
if err != nil {
jsonError(w, http.StatusBadRequest, fmt.Errorf("invalid weekdays format"))
return
}
weekdays = append(weekdays, weekday)
}
soc, err := strconv.ParseFloat(vars["soc"], 64)
if err != nil {
jsonError(w, http.StatusBadRequest, err)
return
}
planTime, err := util.GetNextOccurrence(weekdays, hourMinute, tz)
if err != nil {
jsonError(w, http.StatusBadRequest, err)
return
}
precondition, err := parseDuration(query.Get("precondition"))
if err != nil {
jsonError(w, http.StatusBadRequest, err)
return
}
maxPower := lp.EffectiveMaxPower()
requiredDuration := lp.GetPlanRequiredDuration(soc, maxPower)
plan := lp.GetPlan(planTime, requiredDuration, precondition)
res := PlanPreviewResponse{
PlanTime: planTime,
Duration: int64(requiredDuration.Seconds()),
Precondition: int64(precondition.Seconds()),
Plan: plan,
Power: maxPower,
}
jsonWrite(w, res)
@ -114,6 +169,7 @@ func staticPlanPreviewHandler(lp loadpoint.API) http.HandlerFunc {
func planEnergyHandler(lp loadpoint.API) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
query := r.URL.Query()
ts, err := time.ParseInLocation(time.RFC3339, vars["time"], nil)
if err != nil {
@ -127,19 +183,27 @@ func planEnergyHandler(lp loadpoint.API) http.HandlerFunc {
return
}
if err := lp.SetPlanEnergy(ts, val); err != nil {
precondition, err := parseDuration(query.Get("precondition"))
if err != nil {
jsonError(w, http.StatusBadRequest, err)
return
}
ts, energy := lp.GetPlanEnergy()
if err := lp.SetPlanEnergy(ts, precondition, val); err != nil {
jsonError(w, http.StatusBadRequest, err)
return
}
ts, precondition, energy := lp.GetPlanEnergy()
res := struct {
Energy float64 `json:"energy"`
Time time.Time `json:"time"`
Energy float64 `json:"energy"`
Precondition int64 `json:"precondition"`
Time time.Time `json:"time"`
}{
Energy: energy,
Time: ts,
Energy: energy,
Precondition: int64(precondition.Seconds()),
Time: ts,
}
jsonWrite(w, res)
@ -149,12 +213,13 @@ func planEnergyHandler(lp loadpoint.API) http.HandlerFunc {
// planRemoveHandler removes plan time
func planRemoveHandler(lp loadpoint.API) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if err := lp.SetPlanEnergy(time.Time{}, 0); err != nil {
if err := lp.SetPlanEnergy(time.Time{}, 0, 0); err != nil {
jsonError(w, http.StatusBadRequest, err)
return
}
jsonWrite(w, struct{}{})
res := struct{}{}
jsonWrite(w, res)
}
}
@ -186,7 +251,8 @@ func vehicleSelectHandler(site site.API, lp loadpoint.API) http.HandlerFunc {
func vehicleRemoveHandler(lp loadpoint.API) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
lp.SetVehicle(nil)
jsonWrite(w, struct{}{})
res := struct{}{}
jsonWrite(w, res)
}
}
@ -194,20 +260,7 @@ func vehicleRemoveHandler(lp loadpoint.API) http.HandlerFunc {
func vehicleDetectHandler(lp loadpoint.API) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
lp.StartVehicleDetection()
jsonWrite(w, struct{}{})
}
}
// planStrategyHandler updates plan strategy for loadpoint
func planStrategyHandler(lp loadpoint.API) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if err := planStrategyHandlerSetter(r, lp.SetPlanStrategy); err != nil {
jsonError(w, http.StatusBadRequest, err)
return
}
res := planStrategyPayloadFromApi(lp.GetPlanStrategy())
res := struct{}{}
jsonWrite(w, res)
}
}