Skip to content

Commit

Permalink
chore: rename ChargePhases api to PhaseSwitcher (evcc-io#4105)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Aug 13, 2022
1 parent f9e3027 commit 8ad84d4
Show file tree
Hide file tree
Showing 20 changed files with 91 additions and 91 deletions.
6 changes: 3 additions & 3 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/fatih/structs"
)

//go:generate mockgen -package mock -destination ../mock/mock_api.go github.com/evcc-io/evcc/api Charger,ChargeState,ChargePhases,Identifier,Meter,MeterEnergy,Vehicle,ChargeRater,Battery
//go:generate mockgen -package mock -destination ../mock/mock_api.go github.com/evcc-io/evcc/api Charger,ChargeState,PhaseSwitcher,Identifier,Meter,MeterEnergy,Vehicle,ChargeRater,Battery

// ChargeMode are charge modes modeled after OpenWB
type ChargeMode string
Expand Down Expand Up @@ -107,8 +107,8 @@ type ChargerEx interface {
MaxCurrentMillis(current float64) error
}

// ChargePhases provides 1p3p switching
type ChargePhases interface {
// PhaseSwitcher provides 1p3p switching
type PhaseSwitcher interface {
Phases1p3p(phases int) error
}

Expand Down
4 changes: 2 additions & 2 deletions charger/_blueprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ func (wb *Blueprint) Identify() (string, error) {
return "", api.ErrNotAvailable
}

var _ api.ChargePhases = (*Blueprint)(nil)
var _ api.PhaseSwitcher = (*Blueprint)(nil)

// Phases1p3p implements the api.ChargePhases interface
// Phases1p3p implements the api.PhaseSwitcher interface
func (wb *Blueprint) Phases1p3p(phases int) error {
return api.ErrNotAvailable
}
4 changes: 2 additions & 2 deletions charger/abb.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ func (wb *ABB) Currents() (float64, float64, float64, error) {
return curr[0], curr[1], curr[2], nil
}

// var _ api.ChargePhases = (*ABB)(nil)
// var _ api.PhaseSwitcher = (*ABB)(nil)

// // Phases1p3p implements the api.ChargePhases interface
// // Phases1p3p implements the api.PhaseSwitcher interface
// func (wb *ABB) Phases1p3p(phases int) error {
// var b uint16 = 1
// if phases != 1 {
Expand Down
4 changes: 2 additions & 2 deletions charger/alfen.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ func (wb *Alfen) Currents() (float64, float64, float64, error) {
return currents[0], currents[1], currents[2], nil
}

var _ api.ChargePhases = (*Alfen)(nil)
var _ api.PhaseSwitcher = (*Alfen)(nil)

// Phases1p3p implements the api.ChargePhases interface
// Phases1p3p implements the api.PhaseSwitcher interface
func (c *Alfen) Phases1p3p(phases int) error {
_, err := c.conn.WriteSingleRegister(alfenRegPhases, uint16(phases))
return err
Expand Down
4 changes: 2 additions & 2 deletions charger/dadapower.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ func (wb *Dadapower) Currents() (float64, float64, float64, error) {
return currents[0], currents[1], currents[2], nil
}

var _ api.ChargePhases = (*Dadapower)(nil)
var _ api.PhaseSwitcher = (*Dadapower)(nil)

// Phases1p3p implements the api.ChargePhases interface
// Phases1p3p implements the api.PhaseSwitcher interface
func (wb *Dadapower) Phases1p3p(phases int) error {
_, err := wb.conn.WriteSingleRegister(dadapowerRegActivePhases+wb.regOffset, uint16(phases))
return err
Expand Down
4 changes: 2 additions & 2 deletions charger/easee.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,9 @@ func (c *Easee) MaxCurrent(current int64) error {
return err
}

var _ api.ChargePhases = (*Easee)(nil)
var _ api.PhaseSwitcher = (*Easee)(nil)

// Phases1p3p implements the api.ChargePhases interface
// Phases1p3p implements the api.PhaseSwitcher interface
func (c *Easee) Phases1p3p(phases int) error {
var err error
if c.circuit != 0 {
Expand Down
4 changes: 2 additions & 2 deletions charger/go-e.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func init() {
registry.Add("go-e", NewGoEFromConfig)
}

// go:generate go run ../cmd/tools/decorate.go -f decorateGoE -b *GoE -r api.Charger -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.ChargePhases,Phases1p3p,func(int) (error)"
// go:generate go run ../cmd/tools/decorate.go -f decorateGoE -b *GoE -r api.Charger -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.PhaseSwitcher,Phases1p3p,func(int) (error)"

// NewGoEFromConfig creates a go-e charger from generic config
func NewGoEFromConfig(other map[string]interface{}) (api.Charger, error) {
Expand Down Expand Up @@ -205,7 +205,7 @@ func (c *GoE) totalEnergy() (float64, error) {
return val, err
}

// phases1p3p implements the api.ChargePhases interface - v2 only
// phases1p3p implements the api.PhaseSwitcher interface - v2 only
func (c *GoE) phases1p3p(phases int) error {
if phases == 3 {
phases = 2
Expand Down
30 changes: 15 additions & 15 deletions charger/go-e_decorators.go

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

4 changes: 2 additions & 2 deletions charger/go-e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestGoEV2(t *testing.T) {
t.Error("missing MeterEnergy api")
}

if _, ok := wb.(api.ChargePhases); !ok {
t.Error("missing ChargePhases api")
if _, ok := wb.(api.PhaseSwitcher); !ok {
t.Error("missing PhaseSwitcher api")
}
}
4 changes: 2 additions & 2 deletions charger/kse.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ func (wb *KSE) Currents() (float64, float64, float64, error) {
return curr[0], curr[1], curr[2], nil
}

// var _ api.ChargePhases = (*KSE)(nil)
// var _ api.PhaseSwitcher = (*KSE)(nil)

// // Phases1p3p implements the api.ChargePhases interface
// // Phases1p3p implements the api.PhaseSwitcher interface
// func (wb *KSE) Phases1p3p(phases int) error {
// var b uint16 = 0
// if phases == 1 {
Expand Down
2 changes: 1 addition & 1 deletion charger/ocpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func (c *OCPP) Status() (api.ChargeStatus, error) {
return c.cp.Status()
}

// TODO: Phases1p3p implements the api.ChargePhases interface
// TODO: Phases1p3p implements the api.PhaseSwitcher interface
// func (c *OCPP) Phases1p3p(phases int) error {
// if !c.phaseSwitchingSupported {
// return fmt.Errorf("phase switching is not supported by the charger")
Expand Down
4 changes: 2 additions & 2 deletions charger/openwb-pro.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ func (wb *OpenWBPro) Currents() (float64, float64, float64, error) {
return res.Currents[0], res.Currents[1], res.Currents[2], err
}

var _ api.ChargePhases = (*OpenWBPro)(nil)
var _ api.PhaseSwitcher = (*OpenWBPro)(nil)

// Phases1p3p implements the api.ChargePhases interface
// Phases1p3p implements the api.PhaseSwitcher interface
func (wb *OpenWBPro) Phases1p3p(phases int) error {
return wb.set(fmt.Sprintf("phasetarget=%d", phases))
}
Expand Down
2 changes: 1 addition & 1 deletion charger/openwb.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type OpenWB struct {
authS func(string) error
}

// go:generate go run ../cmd/tools/decorate.go -f decorateOpenWB -b *OpenWB -r api.Charger -t "api.ChargePhases,Phases1p3p,func(int) (error)" -t "api.Battery,SoC,func() (float64, error)"
// go:generate go run ../cmd/tools/decorate.go -f decorateOpenWB -b *OpenWB -r api.Charger -t "api.PhaseSwitcher,Phases1p3p,func(int) (error)" -t "api.Battery,SoC,func() (float64, error)"

// NewOpenWBFromConfig creates a new configurable charger
func NewOpenWBFromConfig(other map[string]interface{}) (api.Charger, error) {
Expand Down
30 changes: 15 additions & 15 deletions charger/openwb_decorators.go

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

16 changes: 8 additions & 8 deletions core/loadpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func NewLoadPointFromConfig(log *util.Logger, cp configProvider, other map[strin
// setup fixed phases:
// - simple charger starts with phases config if specified or 3p
// - switchable charger starts at 0p since we don't know the current setting
if _, ok := lp.charger.(api.ChargePhases); !ok {
if _, ok := lp.charger.(api.PhaseSwitcher); !ok {
if lp.DefaultPhases == 0 {
lp.DefaultPhases = 3
lp.log.WARN.Println("phases not configured, assuming 3p")
Expand Down Expand Up @@ -1014,13 +1014,13 @@ func (lp *LoadPoint) resetPVTimerIfRunning(typ ...string) {
lp.publishTimer(pvTimer, 0, timerInactive)
}

// scalePhasesIfAvailable scales if api.ChargePhases is available
// scalePhasesIfAvailable scales if api.PhaseSwitcher is available
func (lp *LoadPoint) scalePhasesIfAvailable(phases int) error {
if lp.DefaultPhases != 0 {
phases = lp.DefaultPhases
}

if _, ok := lp.charger.(api.ChargePhases); ok {
if _, ok := lp.charger.(api.PhaseSwitcher); ok {
return lp.scalePhases(phases)
}

Expand All @@ -1036,7 +1036,7 @@ func (lp *LoadPoint) setDefaultPhases(phases int) {
lp.phaseTimer = time.Time{}

// publish 1p3p capability and phase configuration
if _, ok := lp.charger.(api.ChargePhases); ok {
if _, ok := lp.charger.(api.PhaseSwitcher); ok {
lp.publish("phases1p3p", lp.DefaultPhases)
} else {
lp.publish("phases1p3p", nil)
Expand All @@ -1059,11 +1059,11 @@ func (lp *LoadPoint) setPhases(phases int) {
}

// scalePhases adjusts the number of active phases and returns the appropriate charging current.
// Returns api.ErrNotAvailable if api.ChargePhases is not available.
// Returns api.ErrNotAvailable if api.PhaseSwitcher is not available.
func (lp *LoadPoint) scalePhases(phases int) error {
cp, ok := lp.charger.(api.ChargePhases)
cp, ok := lp.charger.(api.PhaseSwitcher)
if !ok {
panic("charger does not implement api.ChargePhases")
panic("charger does not implement api.PhaseSwitcher")
}

if lp.GetPhases() != phases {
Expand Down Expand Up @@ -1210,7 +1210,7 @@ func (lp *LoadPoint) pvMaxCurrent(mode api.ChargeMode, sitePower float64, batter
maxCurrent := lp.GetMaxCurrent()

// switch phases up/down
if _, ok := lp.charger.(api.ChargePhases); ok {
if _, ok := lp.charger.(api.PhaseSwitcher); ok {
availablePower := -sitePower + lp.chargePower

// in case of scaling, keep charger disabled for this cycle
Expand Down
4 changes: 2 additions & 2 deletions core/loadpoint_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (lp *LoadPoint) GetPhases() int {
// SetPhases sets loadpoint enabled phases
func (lp *LoadPoint) SetPhases(phases int) error {
// limit auto mode (phases=0) to scalable charger
if _, ok := lp.charger.(api.ChargePhases); !ok && phases == 0 {
if _, ok := lp.charger.(api.PhaseSwitcher); !ok && phases == 0 {
return fmt.Errorf("invalid number of phases: %d", phases)
}

Expand All @@ -120,7 +120,7 @@ func (lp *LoadPoint) SetPhases(phases int) error {
lp.setDefaultPhases(phases)

// apply immediately if not 1p3p
if _, ok := lp.charger.(api.ChargePhases); !ok {
if _, ok := lp.charger.(api.PhaseSwitcher); !ok {
lp.setPhases(phases)
}

Expand Down
2 changes: 1 addition & 1 deletion core/loadpoint_phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (lp *LoadPoint) maxActivePhases() int {
}

// if 1p3p supported then assume configured limit or 3p
if _, ok := lp.charger.(api.ChargePhases); ok {
if _, ok := lp.charger.(api.PhaseSwitcher); ok {
physical = lp.DefaultPhases
if physical == 0 {
physical = 3
Expand Down
Loading

0 comments on commit 8ad84d4

Please sign in to comment.