Skip to content
Draft
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
31 changes: 30 additions & 1 deletion api/plans.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package api

import "time"
import (
"encoding/json"
"time"
)

type RepeatingPlan struct {
Weekdays []int `json:"weekdays"` // 0-6 (Sunday-Saturday)
Expand All @@ -15,3 +18,29 @@ type PlanStrategy struct {
Continuous bool `json:"continuous"` // force continuous planning
Precondition time.Duration `json:"precondition"` // precondition duration in seconds
}

type planStrategy struct {
Continuous bool `json:"continuous"` // force continuous planning
Precondition int `json:"precondition"` // precondition duration in seconds
}

func (ps *PlanStrategy) MarshalJSON() ([]byte, error) {
return json.Marshal(planStrategy{
Continuous: ps.Continuous,
Precondition: int(ps.Precondition.Seconds()),
})
}

func (ps *PlanStrategy) UnmarshalJSON(data []byte) error {
var res planStrategy
if err := json.Unmarshal(data, &res); err != nil {
return err
}

*ps = PlanStrategy{
Continuous: res.Continuous,
Precondition: time.Duration(res.Precondition) * time.Second,
}

return nil
}
8 changes: 2 additions & 6 deletions core/keys/loadpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ const (
EffectiveMinCurrent = "effectiveMinCurrent" // effective min current
EffectiveMaxCurrent = "effectiveMaxCurrent" // effective max current

EffectiveLimitSoc = "effectiveLimitSoc" // effective limit soc
EffectivePlanStrategy = "effectivePlanStrategy" // effective plan strategy (deprecated, use individual fields)
EffectivePlanPrecondition = "effectivePlanPrecondition" // effective plan precondition duration
EffectivePlanContinuous = "effectivePlanContinuous" // effective plan continuous planning
EffectiveLimitSoc = "effectiveLimitSoc" // effective limit soc
EffectivePlanStrategy = "effectivePlanStrategy" // effective plan strategy (deprecated, use individual fields)

// measurements
ChargePower = "chargePower" // charge power
Expand All @@ -86,8 +84,6 @@ const (
PlanProjectedEnd = "planProjectedEnd" // charge plan ends (end of last slot)
PlanOverrun = "planOverrun" // charge plan goal not reachable in time
PlanStrategy = "planStrategy" // charge plan strategy (precondition, continuous)
PlanPrecondition = "planPrecondition" // charge plan precondition duration
PlanContinuous = "planContinuous" // charge plan continuous planning

// repeating plans
RepeatingPlans = "repeatingPlans" // key to access all repeating plans in db
Expand Down
3 changes: 1 addition & 2 deletions core/loadpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -691,8 +691,7 @@ func (lp *Loadpoint) Prepare(site site.API, uiChan chan<- util.Param, pushChan c
// restored settings
lp.publish(keys.PlanTime, lp.planTime)
lp.publish(keys.PlanEnergy, lp.planEnergy)
lp.publish(keys.PlanPrecondition, int64(lp.planStrategy.Precondition.Seconds()))
lp.publish(keys.PlanContinuous, lp.planStrategy.Continuous)
lp.publish(keys.PlanStrategy, lp.planStrategy)
lp.publish(keys.LimitSoc, lp.limitSoc)
lp.publish(keys.LimitEnergy, lp.limitEnergy)

Expand Down
3 changes: 1 addition & 2 deletions core/loadpoint_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,7 @@ func (lp *Loadpoint) setPlanStrategy(strategy api.PlanStrategy) error {
}

lp.planStrategy = strategy
lp.publish(keys.PlanPrecondition, int64(strategy.Precondition.Seconds()))
lp.publish(keys.PlanContinuous, strategy.Continuous)
lp.publish(keys.PlanStrategy, strategy)

lp.requestUpdate()

Expand Down
4 changes: 1 addition & 3 deletions core/loadpoint_effective.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ import (

// PublishEffectiveValues publishes all effective values
func (lp *Loadpoint) PublishEffectiveValues() {
strategy := lp.EffectivePlanStrategy()
lp.publish(keys.EffectivePriority, lp.EffectivePriority())
lp.publish(keys.EffectivePlanId, lp.EffectivePlanId())
lp.publish(keys.EffectivePlanTime, lp.EffectivePlanTime())
lp.publish(keys.EffectivePlanSoc, lp.EffectivePlanSoc())
lp.publish(keys.EffectivePlanStrategy, lp.EffectivePlanStrategy())
lp.publish(keys.EffectiveMinCurrent, lp.effectiveMinCurrent())
lp.publish(keys.EffectiveMaxCurrent, lp.effectiveMaxCurrent())
lp.publish(keys.EffectiveLimitSoc, lp.EffectiveLimitSoc())
lp.publish(keys.EffectivePlanPrecondition, int64(strategy.Precondition.Seconds()))
lp.publish(keys.EffectivePlanContinuous, strategy.Continuous)
}

// EffectivePriority returns the effective priority
Expand Down
66 changes: 32 additions & 34 deletions core/site_vehicles.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,24 @@ import (
)

type planStruct struct {
Soc int `json:"soc"`
Continuous bool `json:"continuous"`
Precondition int64 `json:"precondition"`
Time time.Time `json:"time"`
Soc int `json:"soc"`
Time time.Time `json:"time"`
PlanStrategy api.PlanStrategy `json:"planStrategy"`
}

type vehicleStruct struct {
Title string `json:"title"`
Icon string `json:"icon,omitempty"`
Capacity float64 `json:"capacity,omitempty"`
Phases int `json:"phases,omitempty"`
MinSoc int `json:"minSoc,omitempty"`
LimitSoc int `json:"limitSoc,omitempty"`
MinCurrent float64 `json:"minCurrent,omitempty"`
MaxCurrent float64 `json:"maxCurrent,omitempty"`
Priority int `json:"priority,omitempty"`
Features []string `json:"features,omitempty"`
Plan *planStruct `json:"plan,omitempty"`
RepeatingPlans []api.RepeatingPlan `json:"repeatingPlans"`
PlanPrecondition int64 `json:"planPrecondition"`
PlanContinuous bool `json:"planContinuous"`
Title string `json:"title"`
Icon string `json:"icon,omitempty"`
Capacity float64 `json:"capacity,omitempty"`
Phases int `json:"phases,omitempty"`
MinSoc int `json:"minSoc,omitempty"`
LimitSoc int `json:"limitSoc,omitempty"`
MinCurrent float64 `json:"minCurrent,omitempty"`
MaxCurrent float64 `json:"maxCurrent,omitempty"`
Priority int `json:"priority,omitempty"`
Features []string `json:"features,omitempty"`
Plan *planStruct `json:"plan,omitempty"`
RepeatingPlans []api.RepeatingPlan `json:"repeatingPlans"`
}

// publishVehicles returns a list of vehicle titles
Expand All @@ -48,28 +45,29 @@ func (site *Site) publishVehicles() {
}

ac := instance.OnIdentified()
strategy := v.GetPlanStrategy()

var plan *planStruct
if time, soc := v.GetPlanSoc(); !time.IsZero() {
plan = &planStruct{Soc: soc, Precondition: int64(strategy.Precondition.Seconds()), Time: time}
plan = &planStruct{
Soc: soc,
Time: time,
PlanStrategy: v.GetPlanStrategy(),
}
}

res[v.Name()] = vehicleStruct{
Title: instance.GetTitle(),
Icon: instance.Icon(),
Capacity: instance.Capacity(),
Phases: instance.Phases(),
MinSoc: v.GetMinSoc(),
LimitSoc: v.GetLimitSoc(),
MinCurrent: ac.MinCurrent,
MaxCurrent: ac.MaxCurrent,
Priority: ac.Priority,
Features: lo.Map(instance.Features(), func(f api.Feature, _ int) string { return f.String() }),
Plan: plan,
RepeatingPlans: v.GetRepeatingPlans(),
PlanPrecondition: int64(strategy.Precondition.Seconds()),
PlanContinuous: strategy.Continuous,
Title: instance.GetTitle(),
Icon: instance.Icon(),
Capacity: instance.Capacity(),
Phases: instance.Phases(),
MinSoc: v.GetMinSoc(),
LimitSoc: v.GetLimitSoc(),
MinCurrent: ac.MinCurrent,
MaxCurrent: ac.MaxCurrent,
Priority: ac.Priority,
Features: lo.Map(instance.Features(), func(f api.Feature, _ int) string { return f.String() }),
Plan: plan,
RepeatingPlans: v.GetRepeatingPlans(),
}

if lp := site.coordinator.Owner(instance); lp != nil {
Expand Down
1 change: 0 additions & 1 deletion core/vehicle/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ func (v *adapter) SetPlanStrategy(planStrategy api.PlanStrategy) error {
return err
}

v.log.DEBUG.Printf("update plan strategy for vehicle %s (precondition: %vs, continuous: %v)", v.name, planStrategy.Continuous, planStrategy.Precondition)
v.publish()

return nil
Expand Down
4 changes: 2 additions & 2 deletions tariff/solcast/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func (d *Duration) Duration() time.Duration {
return time.Duration(*d)
}

func (d *Duration) UnmarshalJSON(b []byte) error {
val, err := iso8601.ParseDuration(string(b))
func (d *Duration) UnmarshalJSON(data []byte) error {
val, err := iso8601.ParseDuration(string(data))
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions util/shortrfc3339/shortrfc3339.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ type Timestamp struct {
// Layout is the time.Parse compliant parsing string for use when parsing Shortened RFC-3339 compliant timestamps.
const Layout = "2006-01-02T15:04Z"

func (ct *Timestamp) UnmarshalJSON(b []byte) (err error) {
s := strings.Trim(string(b), "\"")
func (ct *Timestamp) UnmarshalJSON(data []byte) (err error) {
s := strings.Trim(string(data), "\"")
if s == "null" {
ct.Time = time.Time{}
return
Expand Down
4 changes: 2 additions & 2 deletions vehicle/psa/duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ type Duration struct {
}

// UnmarshalJSON implements json.Unmarshaler
func (d *Duration) UnmarshalJSON(b []byte) error {
func (d *Duration) UnmarshalJSON(data []byte) error {
var v any
if err := json.Unmarshal(b, &v); err != nil {
if err := json.Unmarshal(data, &v); err != nil {
return err
}

Expand Down
Loading