Skip to content

Commit

Permalink
chore: fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Jul 6, 2024
1 parent 5485765 commit 5f21545
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion charger/charger.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func NewConfigurableFromConfig(other map[string]interface{}) (api.Charger, error
}

// decorate measurements
powerG, energyG, _, _, _, err := meter.BuildMeasurements(cc.Power, cc.Energy, nil, nil, nil)
powerG, energyG, err := meter.BuildMeasurements(cc.Power, cc.Energy)
if err != nil {
return nil, err
}
Expand Down
37 changes: 17 additions & 20 deletions meter/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,13 @@ import (
)

// BuildMeasurements returns typical meter measurement getters from config
func BuildMeasurements(
power *provider.Config,
energy *provider.Config,
currents []provider.Config,
voltages []provider.Config,
powers []provider.Config,
) (
func() (float64, error),
func() (float64, error),
func() (float64, float64, float64, error),
func() (float64, float64, float64, error),
func() (float64, float64, float64, error),
error,
) {
func BuildMeasurements(power, energy *provider.Config) (func() (float64, error), func() (float64, error), error) {
var powerG func() (float64, error)
if power != nil {
var err error
powerG, err = provider.NewFloatGetterFromConfig(*power)
if err != nil {
return nil, nil, nil, nil, nil, fmt.Errorf("power: %w", err)
return nil, nil, fmt.Errorf("power: %w", err)
}
}

Expand All @@ -36,26 +23,36 @@ func BuildMeasurements(
var err error
energyG, err = provider.NewFloatGetterFromConfig(*energy)
if err != nil {
return nil, nil, nil, nil, nil, fmt.Errorf("energy: %w", err)
return nil, nil, fmt.Errorf("energy: %w", err)
}
}

return powerG, energyG, nil
}

// BuildPhaseMeasurements returns typical meter measurement getters from config
func BuildPhaseMeasurements(currents, voltages, powers []provider.Config) (
func() (float64, float64, float64, error),
func() (float64, float64, float64, error),
func() (float64, float64, float64, error),
error,
) {
currentsG, err := buildPhaseProviders(currents)
if err != nil {
return nil, nil, nil, nil, nil, fmt.Errorf("currents: %w", err)
return nil, nil, nil, fmt.Errorf("currents: %w", err)
}

voltagesG, err := buildPhaseProviders(voltages)
if err != nil {
return nil, nil, nil, nil, nil, fmt.Errorf("voltages: %w", err)
return nil, nil, nil, fmt.Errorf("voltages: %w", err)
}

powersG, err := buildPhaseProviders(powers)
if err != nil {
return nil, nil, nil, nil, nil, fmt.Errorf("powers: %w", err)
return nil, nil, nil, fmt.Errorf("powers: %w", err)
}

return powerG, energyG, currentsG, voltagesG, powersG, nil
return currentsG, voltagesG, powersG, nil
}

// buildPhaseProviders returns phases getter for given config
Expand Down
7 changes: 6 additions & 1 deletion meter/meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ func NewConfigurableFromConfig(other map[string]interface{}) (api.Meter, error)
return nil, err
}

powerG, energyG, currentsG, voltagesG, powersG, err := BuildMeasurements(&cc.Power, cc.Energy, cc.Currents, cc.Voltages, cc.Powers)
powerG, energyG, err := BuildMeasurements(&cc.Power, cc.Energy)
if err != nil {
return nil, err
}

currentsG, voltagesG, powersG, err := BuildPhaseMeasurements(cc.Currents, cc.Voltages, cc.Powers)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 5f21545

Please sign in to comment.