Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loadpoint: cleanup phase configuration and drop deprecations #18638

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
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
6 changes: 4 additions & 2 deletions core/keys/loadpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ const (
DisableDelay = "disableDelay"
BatteryBoost = "batteryBoost"

// TODO FIX WORDING
Phases = "phases" // configured phases (1/3, 0 for auto on 1p3p chargers, nil for plain chargers)
PhasesConfigured = "phasesConfigured" // TODO mirrors "phases" for UI purposes
PhasesEnabled = "phasesEnabled" // enabled phases (1/3)
PhasesActive = "phasesActive" // active phases as used by vehicle (1/2/3)
// TODO REMOVE
PhasesEnabled = "phasesEnabled" // enabled phases (1/3)
PhasesActive = "phasesActive" // active phases as used by vehicle (1/2/3)

ChargerIcon = "chargerIcon" // charger icon for ui
ChargerFeature = "chargerFeature" // charger feature
Expand Down
58 changes: 6 additions & 52 deletions core/loadpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,6 @@ func NewLoadpointFromConfig(log *util.Logger, settings settings.Settings, other
lp.phases = 3
}

// TODO deprecated
lp.migrateSettings()

// validate thresholds
if lp.Enable.Threshold > lp.Disable.Threshold {
lp.log.WARN.Printf("PV mode enable threshold (%.0fW) is larger than disable threshold (%.0fW)", lp.Enable.Threshold, lp.Disable.Threshold)
Expand Down Expand Up @@ -275,53 +272,6 @@ func NewLoadpoint(log *util.Logger, settings settings.Settings) *Loadpoint {
return lp
}

// migrateSettings migrates loadpoint settings
func (lp *Loadpoint) migrateSettings() {
// One-time migrations MUST be mirrored in restoreSettings
if lp.DefaultMode != "" {
lp.log.WARN.Println("deprecated: mode setting is ignored, please remove")
if _, err := lp.settings.String(keys.Mode); err != nil {
lp.settings.SetString(keys.Mode, string(lp.DefaultMode))
}
}
if lp.Title_ != "" {
lp.log.WARN.Println("deprecated: title setting is ignored, please remove")
if _, err := lp.settings.String(keys.Title); err != nil {
lp.settings.SetString(keys.Title, lp.Title_)
}
}
if lp.Priority_ > 0 {
lp.log.WARN.Println("deprecated: priority setting is ignored, please remove")
if _, err := lp.settings.String(keys.Priority); err != nil {
lp.settings.SetInt(keys.Priority, int64(lp.Priority_))
}
}
if lp.MinCurrent_ > 0 {
lp.log.WARN.Println("deprecated: mincurrent setting is ignored, please remove")
if _, err := lp.settings.Float(keys.MinCurrent); err != nil {
lp.settings.SetFloat(keys.MinCurrent, lp.MinCurrent_)
}
}
if lp.MaxCurrent_ > 0 {
lp.log.WARN.Println("deprecated: maxcurrent setting is ignored, please remove")
if _, err := lp.settings.Float(keys.MaxCurrent); err != nil {
lp.settings.SetFloat(keys.MaxCurrent, lp.MaxCurrent_)
}
}
if lp.Phases_ > 0 {
lp.log.WARN.Println("deprecated: phases setting is ignored, please remove")
if _, err := lp.settings.Int(keys.Phases); err != nil {
lp.settings.SetInt(keys.Phases, int64(lp.Phases_))
}
}
if lp.Soc.Estimate != nil || lp.Soc.Poll.Mode != loadpoint.PollCharging || lp.Soc.Poll.Interval != 0 {
lp.log.WARN.Println("deprecated: soc setting is ignored, please remove")
if _, err := lp.settings.String(keys.Soc); err != nil {
lp.settings.SetJson(keys.Soc, lp.Soc)
}
}
}

// restoreSettings restores loadpoint settings
func (lp *Loadpoint) restoreSettings() {
if testing.Testing() {
Expand All @@ -336,9 +286,12 @@ func (lp *Loadpoint) restoreSettings() {
if v, err := lp.settings.Int(keys.Priority); err == nil && v > 0 {
lp.setPriority(int(v))
}
if v, err := lp.settings.Int(keys.Phases); err == nil && (v > 0 || lp.hasPhaseSwitching()) {
if v, err := lp.settings.Int(keys.PhasesConfigured); err == nil && (v > 0 || lp.hasPhaseSwitching()) {
lp.setConfiguredPhases(int(v))
lp.phases = lp.configuredPhases
if !lp.hasPhaseSwitching() {
// TODO FIX PUBLISHING/ use setter?
lp.phases = lp.configuredPhases
}
}
if v, err := lp.settings.Float(keys.MinCurrent); err == nil && v > 0 {
lp.setMinCurrent(v)
Expand Down Expand Up @@ -657,6 +610,7 @@ func (lp *Loadpoint) Prepare(uiChan chan<- util.Param, pushChan chan<- push.Even
lp.publish(keys.PhasesConfigured, lp.configuredPhases)
lp.publish(keys.ChargerPhases1p3p, lp.hasPhaseSwitching())
lp.publish(keys.ChargerSinglePhase, lp.getChargerPhysicalPhases() == 1)
// TODO REMOVE PhasesEnabled
lp.publish(keys.PhasesEnabled, lp.phases)
lp.publish(keys.PhasesActive, lp.ActivePhases())
lp.publish(keys.SmartCostLimit, lp.smartCostLimit)
Expand Down
8 changes: 5 additions & 3 deletions core/loadpoint/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@ type API interface {
GetDefaultMode() api.ChargeMode
// SetDefaultMode sets the default charge mode (for reset)
SetDefaultMode(api.ChargeMode)
// GetPhases returns the enabled phases
// GetPhases returns the currently enabled phases
GetPhases() int
// SetPhases sets the enabled phases
SetPhases(int) error
// GetConfiguredPhases returns statically configured phases
GetConfiguredPhases() int
// SetConfiguredPhases sets the statically configured phases
SetConfiguredPhases(int) error
// ActivePhases returns the active phases for the current vehicle
ActivePhases() int

Expand Down
24 changes: 12 additions & 12 deletions core/loadpoint/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ type StaticConfig struct {

type DynamicConfig struct {
// dynamic config
Title string `json:"title"`
DefaultMode string `json:"defaultMode"`
Priority int `json:"priority"`
Phases int `json:"phases"`
MinCurrent float64 `json:"minCurrent"`
MaxCurrent float64 `json:"maxCurrent"`
SmartCostLimit *float64 `json:"smartCostLimit"`
PlanEnergy float64 `json:"planEnergy"`
PlanTime time.Time `json:"planTime"`
LimitEnergy float64 `json:"limitEnergy"`
LimitSoc int `json:"limitSoc"`
Title string `json:"title"`
DefaultMode string `json:"defaultMode"`
Priority int `json:"priority"`
ConfiguredPhases int `json:"configuredPhases"`
MinCurrent float64 `json:"minCurrent"`
MaxCurrent float64 `json:"maxCurrent"`
SmartCostLimit *float64 `json:"smartCostLimit"`
PlanEnergy float64 `json:"planEnergy"`
PlanTime time.Time `json:"planTime"`
LimitEnergy float64 `json:"limitEnergy"`
LimitSoc int `json:"limitSoc"`

Thresholds ThresholdsConfig `json:"thresholds"`
Soc SocConfig `json:"soc"`
Expand Down Expand Up @@ -69,7 +69,7 @@ func (payload DynamicConfig) Apply(lp API) error {
}

if err == nil {
err = lp.SetPhases(payload.Phases)
err = lp.SetConfiguredPhases(payload.ConfiguredPhases)
}

if err == nil && payload.MinCurrent != 0 {
Expand Down
42 changes: 28 additions & 14 deletions core/loadpoint/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions core/loadpoint_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,22 @@ func (lp *Loadpoint) SetPriority(prio int) {
}
}

// GetPhases returns loadpoint enabled phases
// GetPhases returns the currently enabled phases
func (lp *Loadpoint) GetPhases() int {
lp.RLock()
defer lp.RUnlock()
return lp.phases
}

// SetPhases sets loadpoint enabled phases
func (lp *Loadpoint) SetPhases(phases int) error {
// GetConfiguredPhases returns statically configured phases
func (lp *Loadpoint) GetConfiguredPhases() int {
lp.RLock()
defer lp.RUnlock()
return lp.configuredPhases
}

// SetConfiguredPhases sets the statically configured phases
func (lp *Loadpoint) SetConfiguredPhases(phases int) error {
// limit auto mode (phases=0) to scalable charger
if !lp.hasPhaseSwitching() && phases == 0 {
return fmt.Errorf("charger does not support phase switching")
Expand Down
7 changes: 5 additions & 2 deletions core/loadpoint_phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import (
// setConfiguredPhases sets the default phase configuration
func (lp *Loadpoint) setConfiguredPhases(phases int) {
lp.configuredPhases = phases

// TODO CLARIFY
lp.publish(keys.Phases, lp.configuredPhases)
lp.publish(keys.PhasesConfigured, lp.configuredPhases) // TODO remove
lp.settings.SetInt(keys.Phases, int64(lp.configuredPhases))

lp.publish(keys.PhasesConfigured, lp.configuredPhases)
lp.settings.SetInt(keys.PhasesConfigured, int64(lp.configuredPhases))
}

// setPhases sets the number of enabled phases without modifying the charger
Expand Down
26 changes: 13 additions & 13 deletions server/http_config_loadpoint_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ func getLoadpointStaticConfig(lp loadpoint.API) loadpoint.StaticConfig {
func getLoadpointDynamicConfig(lp loadpoint.API) loadpoint.DynamicConfig {
planTime, planEnergy := lp.GetPlanEnergy()
return loadpoint.DynamicConfig{
Title: lp.GetTitle(),
DefaultMode: string(lp.GetDefaultMode()),
Priority: lp.GetPriority(),
Phases: lp.GetPhases(),
MinCurrent: lp.GetMinCurrent(),
MaxCurrent: lp.GetMaxCurrent(),
SmartCostLimit: lp.GetSmartCostLimit(),
Thresholds: lp.GetThresholds(),
Soc: lp.GetSocConfig(),
PlanEnergy: planEnergy,
PlanTime: planTime,
LimitEnergy: lp.GetLimitEnergy(),
LimitSoc: lp.GetLimitSoc(),
Title: lp.GetTitle(),
DefaultMode: string(lp.GetDefaultMode()),
Priority: lp.GetPriority(),
ConfiguredPhases: lp.GetConfiguredPhases(),
MinCurrent: lp.GetMinCurrent(),
MaxCurrent: lp.GetMaxCurrent(),
SmartCostLimit: lp.GetSmartCostLimit(),
Thresholds: lp.GetThresholds(),
Soc: lp.GetSocConfig(),
PlanEnergy: planEnergy,
PlanTime: planTime,
LimitEnergy: lp.GetLimitEnergy(),
LimitSoc: lp.GetLimitSoc(),
}
}

Expand Down
Loading